Conversation
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>
There was a problem hiding this comment.
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
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
SecuritySchemedefinitions underOA\Components(securitySchemes: [...])within the rootOA\OpenApiattribute.
| 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 on lines
+19
to
+25
| new OA\SecurityScheme( | ||
| securityScheme: 'AuthToken', | ||
| type: 'http', | ||
| in: 'header', | ||
| bearerFormat: 'JWT', | ||
| scheme: 'bearer' | ||
| ), |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #545
Generated openapi.yaml before this change: no servers block at the root, and externalDocs 6 times (2 operations + 4 schemas).
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:
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.