Skip to content

Write the OpenAPI docs in the API templates as attributes and drop doctrine/annotations #597

Closed

Description

@armanist

Summary

Write the OpenAPI documentation in the shipped API module templates as PHP attributes (#[OA\...]) instead of @OA\... annotations, and remove the abandoned doctrine/annotations package. Part of the PHP 8.1 update (#595).

Why

Composer reports doctrine/annotations as abandoned, with no replacement. It is kept only because the OpenAPI docs use annotations, and zircote/swagger-php reads annotations only when that package is installed (it is a suggestion there, not a requirement). The 3.0.3 changelog notes that it stays "on the PHP 8.0 baseline", because swagger-php's attribute scanning needs PHP 8.1. With 8.1 as the minimum, that reason is gone.

Current state

  • 7 template files under src/Module/Templates (DefaultApi and DemoApi, in Controllers/OpenApi) use @OA\... annotations. None use attributes.
  • OpenApiCommand generates the spec with Generator::scan().
  • doctrine/annotations is required in composer.json and not imported in src.

Proposed change

  • Convert the annotations in those templates to #[OA\...] attributes.
  • Check that the generated spec is the same as before for the same API.
  • Remove doctrine/annotations from composer.json.
  • Describe the change for existing projects in the changelog and the upgrade guide.

Breaking changes

  • A project whose own controllers carry @OA\... annotations (for example generated from the earlier templates) loses its OpenAPI output once doctrine/annotations is gone. It has to convert its annotations to attributes. This needs a clear upgrade note.

Out of scope

  • Changing the API documentation content.
  • Upgrading zircote/swagger-php.

Acceptance criteria

  • the templates use attributes only and php qt generates the same OpenAPI spec as before
  • doctrine/annotations is no longer required
  • composer test, composer cs:check, composer phpstan and composer rector:check pass
  • the upgrade note explains how to convert annotations

Notes

Relevant code: src/Module/Templates/DefaultApi, src/Module/Templates/DemoApi, src/Console/Commands/OpenApiCommand.php, composer.json.

Activity

  1. added this to the 3.1.0 milestone on Oct 23, 2026
  2. added
    breaking changeIntroduces or coordinates a breaking change
    tech debtTechnical debt reduction
    openapiOpenAPI generation or hosting
    templatesShipped templates and scaffolding
    on Oct 23, 2026
  3. self-assigned this
    on Oct 23, 2026
  4. added a commit that references this issue on Oct 23, 2026
  5. added 9 commits that reference this issue on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

breaking changeIntroduces or coordinates a breaking changeopenapiOpenAPI generation or hostingtech debtTechnical debt reductiontemplatesShipped templates and scaffolding

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions