-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API specification generation #178
API specification generation #178
Conversation
@romalytvynenko this is so good, thank you! We'll keep this in draft until Scramble has the new features merged, so we're not pinned to a specific branch. |
Just as a small update, working on that |
@jbrooksuk just wanted to let you know that I've released alpha versions of Scramble and unpinned this implementation from branches! While I will continue working on improving Scramble so it covers Cachet's API better, this branch can now be reviewed and merged 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, quick pass at a review.
.github/workflows/build-api-docs.yml
Outdated
DOCS_REPOSITORY: romalytvynenko/cachet-docs | ||
DOCS_BRANCH: feat/api-docs-generation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to update these to the real docs and main
branch.
.github/workflows/build-api-docs.yml
Outdated
git config --global user.name "GitHub Actions" | ||
git config --global user.email "<>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can replace this with the setup-git-user
workflow, https://github.com/marketplace/actions/setup-git-user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, could not make it work, but found this gem used in other Cachet's workflows! I'll use it
.github/workflows/build-api-docs.yml
Outdated
composer require dedoc/scramble-pro:0.7.0-alpha.1 --dev | ||
|
||
- name: Checkout documentation repository | ||
uses: actions/checkout@v2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uses: actions/checkout@v2 | |
uses: actions/checkout@v4 |
.github/workflows/build-api-docs.yml
Outdated
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uses: actions/checkout@v2 | |
uses: actions/checkout@v4 |
src/CachetCoreServiceProvider.php
Outdated
} | ||
|
||
Scramble::afterOpenApiGenerated(function (OpenApi $openApi) { | ||
$openApi->info->description = 'API documentation for Cachet, the open source status page system.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$openApi->info->description = 'API documentation for Cachet, the open source status page system.'; | |
$openApi->info->description = 'API documentation for Cachet, the open-source, self-hosted status page system.'; |
Applied the requested changes! |
Let's go! |
Hey 🙌
This PR introduces automatic API specification generation using Scramble.
How it works
dedoc/scramble
is required as development dependency. For spec generationtestbench
is used:./vendor/bin/testbench scramble:export
creates the specification file.How CI part works
Using GitHub Actions,
dedoc/scramble-pro
is installed (provides support for packages the API is built with) and after that the specification can be generated (scramble:export
).Next, a very opinionated step happens. GHA clones docs repository into a subfolder. Then, the API specification file is being generated in that newly created
docs
repository folder (docs-repository/api-reference/openapi.json
). After that, GHA commits and pushes changes (if any) to thedocs
repository. This can be improved though! I imagined something like pushing to some dedicated branch ofdocs
repo and creating a PR from that branch (if not existing), so the maintainers can manually accept the updated specification.This step is very opinionated and I was curious if I can make it work. If keeping the spec file within this repository is fine and it will somehow then be moved to docs repository, I will drop this part!
Notes
core
and CI depends on development branches of Scramble. This is due to me finding the generated API specification inaccuracies – I want to update Scramble to fix/improve such inconsistencies. After that is done, I tag versions an use them.Further improvements
allowedIncludes
(or other methods; for example->allowedIncludes(self::ALLOWED_INCLUDES)
), the corresponding expected parameters are not documented#[Parameter(...)]
and#[QueryParameter(...)], ...
etc attributesRequest
suffix from the laravel data objects that are used only as a requestsThe generated specification demo: https://elements-demo.stoplight.io/?spec=https://gist.githubusercontent.com/romalytvynenko/b0c750bc3f66177b488913d8bc1dcf34/raw/b4b28031d148b84a3ea873d5c624775f8b67ceae/spec3.json
Let me know what you think!