Skip to content

fix(openapi): move root attributes into OA\OpenApi - #551

Open
dq042000 wants to merge 1 commit into
dotkernel:7.0from
dq042000:fix/issue-545-openapi-root-attributes
Open

dq042000 wants to merge 1 commit into
dotkernel:7.0from
dq042000:fix/issue-545-openapi-root-attributes

Conversation

@dq042000

Copy link
Copy Markdown
Contributor

Fixes #545

Generated openapi.yaml before this change: no servers block at the root, and externalDocs 6 times (2 operations + 4 schemas).

$ grep -c "^servers:" openapi.yaml
0
$ grep -c externalDocs openapi.yaml
6

OA\Server and OA\ExternalDocumentation both accept an operation as a parent, and in src/App/src/OpenAPI.php they sit in the same attribute list as OA\Get, OA\Post and OA\Schema, so swagger-php nests them there instead of the document root. Wrapping the root metadata in one OA\OpenApi attribute leaves nothing to guess.

After:

$ grep -c "^servers:" openapi.yaml
1
$ grep -c externalDocs openapi.yaml
1

The two security schemes had to move into OA\Components. They render in the same place as before, so components is byte identical apart from the externalDocs copies being gone. Nothing outside the attribute block changed, and the rest of the document only loses the duplicates (2011 -> 1992 lines).

Checked locally with phpcs, phpstan and the unit test suite, all green.

The generated openapi.yaml has no servers block at the root, and externalDocs
shows up 6 times (in the 2 operations and in 4 schemas) instead of once.

OA\Server and OA\ExternalDocumentation both allow operations as a parent, and
they sit in the same attribute list as OA\Get, OA\Post and OA\Schema, so
swagger-php puts them there instead of at the root. Nesting the root metadata
in a single OA\OpenApi attribute leaves nothing to guess.

The two security schemes move into OA\Components, which is where they end up
in the output either way, so that part of the document is unchanged.

Fixes dotkernel#545

Signed-off-by: MikeCi <dq042000@gmail.com>
Copilot AI lite review requested due to automatic review settings September 23, 2026 01:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The HTTP bearer security scheme currently includes an in: 'header' field, which is not valid for type: 'http' and may break strict OpenAPI validation/tooling.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR addresses swagger-php attribute parent ambiguity by explicitly wrapping document-root OpenAPI metadata into a single #[OA\OpenApi(...)] attribute, ensuring servers and externalDocs are emitted once at the root (instead of being absorbed into operations).

Changes:

  • Wrap root-level OpenAPI metadata (info, servers, externalDocs) into #[OA\OpenApi(...)] to force correct document-root placement.
  • Move SecurityScheme definitions under OA\Components(securitySchemes: [...]) within the root OA\OpenApi attribute.
File Description
src/​App/​src/​OpenAPI.php Refactors OpenAPI attributes to remove root/operation ambiguity by nesting metadata under OA\OpenApi and placing security schemes under OA\Components.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/App/src/OpenAPI.php
Comment on lines +19 to +25
new OA\SecurityScheme(
securityScheme: 'AuthToken',
type: 'http',
in: 'header',
bearerFormat: 'JWT',
scheme: 'bearer'
),
@arhimede
arhimede requested a review from alexmerlin September 23, 2026 09:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Root-level OA attributes are absorbed into the operations

2 participants