Repository navigation
fix(python-flask, python-aiohttp, python-blueplanet): use imported model names in controller test examples - #25426
Open
khayashi4337 wants to merge 1 commit into
Conversation
…del names in controller test examples Model-typed non-body parameters (e.g. a $ref object in a query or header parameter) got the example "openapi_server.Filter()", but the generated controller tests import models by class name and never import the package, so the test module raised NameError. Strip the package prefix in the Connexion codegen so the example matches the import. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
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. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonFlaskConnexionServerCodegenTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonFlaskConnexionServerCodegenTest.java:168">
P3: The new regression test never covers the `p.defaultValue != null` early return in `setParameterExampleValue`. Add a model-typed parameter with a `default` to `model-typed-params.yaml` and assert that its default-derived example is emitted unchanged.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| } | ||
|
|
||
| @Test(description = "model examples in generated controller tests use the imported class name, not the package") | ||
| public void testControllerTestModelExampleUsesImportedName() throws IOException { |
Contributor
There was a problem hiding this comment.
P3: The new regression test never covers the p.defaultValue != null early return in setParameterExampleValue. Add a model-typed parameter with a default to model-typed-params.yaml and assert that its default-derived example is emitted unchanged.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonFlaskConnexionServerCodegenTest.java, line 168:
<comment>The new regression test never covers the `p.defaultValue != null` early return in `setParameterExampleValue`. Add a model-typed parameter with a `default` to `model-typed-params.yaml` and assert that its default-derived example is emitted unchanged.</comment>
<file context>
@@ -163,4 +163,25 @@ public void testDefaultController() throws IOException {
}
+
+ @Test(description = "model examples in generated controller tests use the imported class name, not the package")
+ public void testControllerTestModelExampleUsesImportedName() throws IOException {
+ final DefaultCodegen codegen = new PythonFlaskConnexionServerCodegen();
+ final String outputPath = generateFiles(codegen, "src/test/resources/3_0/python-flask/model-typed-params.yaml");
</file context>
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.
The generated controller tests of the Connexion-based Python servers (python-flask, python-aiohttp, python-blueplanet) raise
NameError: name 'openapi_server' is not definedfor operations with a model-typed non-body parameter (for example a$refobject in a query or header parameter, or a non-JSON request body):AbstractPythonCodegen.setParameterExampleValuebuilds model examples aspackageName + "." + type + "()", butcontroller_test.mustacheimports models by class name ({{#imports}}) and never imports the package. The package's__init__.pyis empty anyway, so the models are only reachable fromopenapi_server.models. I reproduced theNameErrorwith tests generated by v7.26.0 as well.Changes
AbstractPythonConnexionServerCodegen.setParameterExampleValue(CodegenParameter): rewrite only the exact forms the parent builds for model types, i.e.pkg.X(),[pkg.X()]and{'key': pkg.X()}, toX(),[X()]and{'key': X()}. Defaults and primitive-typed examples are left untouched, even when a user-supplied example happens to look likeopenapi_server.int().PythonFlaskConnexionServerCodegenTest: new test with3_0/python-flask/model-typed-params.yaml, covering query, header, array, map and body parameters, plus negative cases for string and integer examples that look like constructors.samples/server/petstore/python-blueplanet/.../test/test_{store,user}_controller.py: updated the 5 affected lines by hand. The generator never overwrites existing api test files, so regenerating the samples does not refresh them. The flask samples' test files are stale in unrelated ways (variable names, JSON examples), so the change does not show there.Verification
Python*Test/AbstractPython*Testpass. The new test fails without the change.Filter(),[Filter()]and{'key': Filter()}, and theimportlines for every referenced model.NameErroris gone.bin/generate-samples.shforbin/configs/python-{flask,flask-connexion3,aiohttp,aiohttp-srclayout,blueplanet}.yamlproduces no diff.Not fixed here (pre-existing)
NameErrorgone, a generated test with an object-typed query/header parameter now reaches the server and gets 400. Connexion only deserializesstyle: deepObjectobject query parameters, so it rejects the placeholder value. I'm working on that separately (it builds on fix(python-aiohttp, python-blueplanet, python-flask): read header/cookie params from the request; stop overwriting non-body params from the body #25362).[List[Filter]()]) still produce invalid examples.PR checklist
bin/configs/python-{flask,flask-connexion3,aiohttp,aiohttp-srclayout,blueplanet}.yaml): no diff. Updated the 5 stale blueplanet test lines by hand (see above). Generator options and docs are unchanged.cc @cbornet @tomplus @krjakbrjak @fa0311 (Python technical committee)
Parts of this change were drafted with AI coding assistants (Claude Code, with reviews by Codex and Fable) and reviewed and verified by me.
🤖 Generated with Claude Code