Repository navigation
Issue/597 Write the OpenAPI docs in the API templates as attributes - #605
Conversation
…OpenAPI spec The OpenAPI documentation in the DefaultApi and DemoApi templates had no test. The test renders the OpenAPI controllers of each template, generates the specification the way the openapi command does, and checks that it validates, has a title and the bearer_token security scheme, and describes every operation with a summary and responses.
…attributes The API info and the bearer_token security scheme are PHP attributes instead of docblock annotations. The generated OpenAPI specification is identical.
… as attributes The status operation is a PHP attribute with its nested response, JSON content and properties instead of a docblock annotation. The generated OpenAPI specification is identical.
…ributes The API info and the bearer_token security scheme are PHP attributes instead of docblock annotations. The generated OpenAPI specification is identical.
… templates to 3.x The API info of the DefaultApi and DemoApi templates still said version 2.9.0.
…emplates use attributes only
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Closes #597. Part of #595. The changelog entry is written in a final pull request, after the sub-issues.
What changed
DefaultApi:OpenApiController,OpenApiMainController;DemoApi:OpenApiControllerand the Comment, Account, Post and Auth controllers) describe the API with#[OA\...]attributes instead of@OA\...docblocks. Values are unchanged; text lines of the docblocks are kept.OpenApiControllertemplates is3.xinstead of2.9.0.doctrine/annotationsis removed fromcomposer.json. Nothing insrcused it.OpenApiTemplatesTestrenders the API templates and runs swagger-php on them: the specification must validate, describe the API and its security scheme, give every operation a summary and responses, and no template may contain@OA\again.Why
swagger-php 5 reads attributes natively and needs
doctrine/annotationsonly for docblock annotations, where it is just a suggestion. The package is abandoned, so the framework should not require it. New modules start with attributes.Breaking changes
doctrine/annotationsis no longer installed with the framework. An existing application whose controllers use@OAdocblocks must convert them to#[OA\...]attributes, or requiredoctrine/annotationsitself. Otherwiseinstall:openapifails withRequired @OA\PathItem() not found.Testing
OpenApiTemplatesTestis new (8 tests).3.xversion.module:generate -t DemoApiand published withinstall:openapishows its 20 paths in Swagger UI in the browser. The DefaultApi module generates a valid specification with 1 path.Notes for reviewers
install:openapifails when the module has noresourcesfolder (mkdir()is not recursive) and whenpublic/assets/OpenApiUidoes not exist. Both exist before this change and are not touched here.Summary by CodeRabbit
Documentation
3.x.Chores
doctrine/annotationsdependency.