Repository navigation
ci(python): check generated Python Connexion server code in a GitHub workflow - #25654
Open
khayashi4337 wants to merge 1 commit into
Open
khayashi4337 wants to merge 1 commit into
khayashi4337 wants to merge 1 commit into
Conversation
…workflow The unit tests must not require a python3 toolchain (OpenAPITools#25556). OpenAPITools#25579 removed testJsonContentHeaderParamsGeneratedTestsCompile and re-enabled testInfoTitleEmbeddedAsPythonStringLiteral with Java-only assertions; this workflow restores the Python-level checks (py_compile of the generated tests and evaluating the setup() literals with ast): - bin/utils/check-python-connexion-generated.py runs py_compile on the generated test_default_controller.py (with warnings promoted to errors) and evaluates the setup() kwargs (description/author_email/long_description) with ast, comparing all three against the values the generator derives from the input spec's info object -- spec values where present, generator defaults otherwise. - The workflow builds the CLI, generates the two Connexion test specs under python-flask, python-flask useConnexion3=true, python-aiohttp and python-blueplanet (8 combinations), and runs the check script over each output. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 issue found across 2 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=".github/workflows/samples-python-connexion-generated-code.yaml">
<violation number="1" location=".github/workflows/samples-python-connexion-generated-code.yaml:11">
P2: The path filters miss `DefaultCodegen.java` and `DefaultGenerator.java`. The Python Connexion escaping and the default `long_description` both come from those files. Add them to both `push` and `pull_request` paths so changes to them run this check.</violation>
</file>
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
View guided diff | Re-trigger cubic
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAiohttpConnexionServerCodegen.java | ||
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java | ||
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java | ||
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonStringUtils.java |
Contributor
There was a problem hiding this comment.
P2: The path filters miss DefaultCodegen.java and DefaultGenerator.java. The Python Connexion escaping and the default long_description both come from those files. Add them to both push and pull_request paths so changes to them run this check.
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 .github/workflows/samples-python-connexion-generated-code.yaml, line 11:
<comment>The path filters miss `DefaultCodegen.java` and `DefaultGenerator.java`. The Python Connexion escaping and the default `long_description` both come from those files. Add them to both `push` and `pull_request` paths so changes to them run this check.</comment>
<file context>
@@ -0,0 +1,97 @@
+ - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAiohttpConnexionServerCodegen.java
+ - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java
+ - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java
+ - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonStringUtils.java
+ - modules/openapi-generator/src/main/resources/python-flask/**
+ - modules/openapi-generator/src/main/resources/python-aiohttp/**
</file context>
Suggested change
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonStringUtils.java | |
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java | |
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java | |
| - modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonStringUtils.java |
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.
Follow-up to #25556, as promised in #25556 (comment).
#25556 asked for the unit tests to stop depending on a local
python3. #25579 (merged) did the Java side: it removedtestJsonContentHeaderParamsGeneratedTestsCompileand re-enabledtestInfoTitleEmbeddedAsPythonStringLiteralwith Java-only assertions, so./mvnw testno longer needspython3. Those Java assertions pin the generated text line by line; they cannot tell whether the result is valid Python or what the string literals evaluate to. This PR adds a GitHub workflow that checks exactly that, modelled onsamples-python-fastapi-server.yaml.What the workflow does
.github/workflows/samples-python-connexion-generated-code.yaml:~/.m2/repositorycache asopenapi-generator.yaml) and sets up Python 3.11;3_0/python/connexion-json-header-test-values.yamland3_0/python/info-title-special-chars.yaml, with each ofpython-flask,python-flaskwithuseConnexion3=true,python-aiohttpandpython-blueplanet(8 outputs);bin/utils/check-python-connexion-generated.pyon each output. For every output the script:test_default_controller.py, treating warnings such as invalid escape sequences as errors;setup.pywith Python'sast, evaluates the keyword arguments ofsetup(), and compares three of them with the values the generator should produce from the spec:description(info.title),author_email(info.contact.email, or""when absent) andlong_description(info.description, or the generator's "No description provided …" text when absent);Unlike the other
samples-python-*workflows, this one generates its inputs instead of checking committed samples: the two specs exist to exercise edge cases (JSON content header parameters; a title, description and contact email full of quotes, triple quotes, backslashes,&,<>and control characters), and committing eight more sample trees for them seemed heavier than generating them in CI.It runs on
pushandpull_requestwhen the Connexion generators,AbstractPythonCodegenorPythonStringUtils(which implement the escaping), their templates, the two specs,AbstractPythonConnexionServerCodegenTest, the script or the workflow itself change.Verified
"\d"in a generated test;descriptionin a generatedsetup.py;author_emailin thesetup.pygenerated from the spec without a contact email;actions/checkout@v7,actions/setup-java@v6,actions/setup-python@v7andactions/cache@v6match the versions used by the existing workflows.No Java code, template or sample changes.
cc @wing328
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
🤖 Generated with Claude Code
Summary by cubic
Adds a GitHub workflow that verifies generated Python Connexion server code stays valid and correct, after #25579 removed the unit tests'
python3dependency.python-flask(with and withoutuseConnexion3=true),python-aiohttp, andpython-blueplanet.bin/utils/check-python-connexion-generated.pyon each output, which compilestest_default_controller.py(warnings as errors) and evaluatessetup.py'sdescription,author_email, andlong_descriptionagainst the spec-derived values.AbstractPythonCodegen,PythonStringUtils, templates, the two specs, or the workflow itself change.No Java, template, or sample changes.
Written for commit 88e0000. Summary will update on new commits.