Fix FastAPI example generation#23537
Conversation
There was a problem hiding this comment.
1 issue found across 5 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java:686">
P2: Schema example extraction only checks `example` and ignores `examples`, which can drop explicit schema examples in generated Python metadata.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
...penapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java
Outdated
Show resolved
Hide resolved
8891f48 to
3a5bb74
Compare
|
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors. Let me know if you need help fixing it. |
- Fall back to first entry of `examples` array when `example` is absent, fixing schema example extraction for OAS 3.1 specs. - Add unit tests for plural and singular example precedence via TestableFastAPICodegen helper subclass. - Add nickname property with examples array to test fixture.
3a5bb74 to
dedc38c
Compare
Thanks for notifying me, fixed. |
--- a/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api.py
+++ b/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api.py
@@ -50,7 +50,8 @@ for _, name, _ in pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + "."):
response_model_by_alias=True,
)
async def update_pet(
- pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(None, description="Pet object that needs to be added to the store"),
+ pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(None, description="Pet object that needs to be added to the store")
+,
token_petstore_auth: TokenModel = Security(
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
),can we keep the ref: https://github.com/OpenAPITools/openapi-generator/actions/runs/24402803325/job/71278593153?pr=23537 (please update the samples by following step 3 in the PR checklist) |
Remove trailing newline from endpoint_argument_definition.mustache so the comma after each parameter stays inline rather than appearing on a new line. Regenerate python-fastapi petstore sample.
Fixes FastAPI server example generation so explicit OpenAPI examples are included in generated FastAPI/Pydantic metadata.
Changes:
Body(..., examples=[...])metadata.json_schema_extra={"examples": [...]}.'',None, or empty array placeholders into Swagger UI.examplesfor FastAPI metadata to avoidexampledeprecation warnings.Validation: