Repository navigation
fix(python-flask, python-aiohttp, python-blueplanet): don't HTML-escape names inside generated Python string literals - #25457
Conversation
…pe names inside generated Python string literals
Mustache's {{...}} HTML-escapes its value. The Connexion server templates
wrote property and parameter names into Python string literals that way,
so a model property named 'a&b' produced attribute_map 'ab': 'a&b'
and from_dict() silently dropped its value. A ' in a name gave '&OpenAPITools#39;'.
These names are now rendered with {{{...}}} from vendor extensions that
hold them escaped for a single-quoted Python literal, losslessly
(backslash, quote, newline, CR, tab and other control characters):
- model attribute_map (python-flask, python-aiohttp, python-blueplanet);
- query keys in the generated controller tests (python-flask,
python-aiohttp), and header names in python-blueplanet's generated
tests. Parameters get x-python-connexion-quoted-name, the same name and
meaning as in OpenAPITools#25427, which covers the header/cookie lookups in the
python-flask/python-aiohttp controllers and tests.
The generated tests also sent an apiKey under the security scheme's name
instead of the header name (keyParamName). They now send keyParamName,
and only for apiKeys in a header. Query/cookie apiKeys are not sent, as
before.
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ion-model-attribute-names # Conflicts: # modules/openapi-generator/src/main/resources/python-aiohttp/controller_test.mustache # modules/openapi-generator/src/main/resources/python-flask/controller_test.mustache # modules/openapi-generator/src/test/java/org/openapitools/codegen/python/AbstractPythonConnexionServerCodegenTest.java
Merge the two fromSecurity overrides produced by the upstream merge so both the security-function-suffix and quoted-key-param-name extensions are set. Emit the escaped wire name (openapi-name or baseName) for query params and apiKey-in-query entries in x-test-query-string, and update the escaped-names test to expect the apikey query credential that the new upstream behavior correctly sends. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Mustache HTML-escapes {{name}}, so wire names containing &, ', <, > or "
were rendered as entities and the second query_string assignment sent the
escaped name instead of the real one. Use {{{name}}} like the other
string interpolations in these templates.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ion-model-attribute-names Resolve conflicts by combining both sides: keep this branch's lossless escapeForPythonSingleQuotedLiteral (also applied to upstream's new per-copy X_QUOTED_NAME loop so the value round-trips) and its quoted-key-param-name extension, while adopting upstream's quoted-name lookup for header params in the generated controller tests. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ames in the generated controller and test
The generated blueplanet controller read headers and cookies via
connexion.request.headers.get('{{baseName}}') / cookies.get('{{baseName}}'),
and the generated test sent query parameters under the sanitized
{{paramName}}. {{baseName}} is HTML-escaped by mustache, so names such as
"X-A&B'Head" or "X-C&oo'kie" were emitted as "X-A&B&OpenAPITools#39;Head" and the
lookup could never match; the query test line sent the sanitized name
("qwes") instead of the wire name ("q&we's").
Use the x-python-connexion-quoted-name vendor extension (already populated
for every parameter by AbstractPythonConnexionServerCodegen) in all three
places, matching python-flask and python-aiohttp. Add a cookie parameter to
the escaped-names test spec, assert the generated controller and test emit
the original names escaped for single-quoted Python literals, and py_compile
the generated controller and test.
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Follow-up commit d004e66 for the python-blueplanet server, which was still using HTML-escaped names where python-flask and python-aiohttp already emit the escaped Python literal:
CI on the new head is green (11/11). |
…ion-model-attribute-names Resolve controller_test.mustache conflicts by combining both intents: keep the quoted wire names (x-python-connexion-quoted-name / x-python-connexion-quoted-key-param-name, no HTML escaping) while taking upstream's x-python-connexion-test-header-value conditionals and the new cookie test blocks. Align upstream's added cookie/header lines in python-blueplanet to the quoted-name form too, and drop the per-param query iteration upstream replaced with x-test-query-string. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ion-model-attribute-names Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ion-model-attribute-names
# Conflicts:
# modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/test/controller_test.mustache
…s test The unit tests must not require a python3 toolchain (OpenAPITools#25556). Replace the python3 -m py_compile check in testEscapedNamesInAttributeMapAndApiKeyHeaders with Java assertions that pin the same guarantee: the escaped literal lines are now matched as whole lines (assertFileContainsTrimmedLine) and assertFileNotContains rules out the unterminated literal forms a missing escape would emit. The assertPythonCompiles helper goes away with its only call site, so this test no longer skips when python3 is absent. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Added a commit that drops the |
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
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/AbstractPythonConnexionServerCodegenTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/python/AbstractPythonConnexionServerCodegenTest.java:446">
P2: Dropping the `py_compile` check leaves the escaped-name output without any compile verification. The PR description promises generated files compile, and the file already has a skip-if-absent helper (`assertPythonSyntaxValid`) that could keep this check without requiring python3. Consider restoring the check through that helper.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| assertFileNotContains(blueplanetController, "&", "'"); | ||
| // an unescaped quote would leave a broken literal like 'X-A&B'Head' in the | ||
| // file; pin that no such unterminated form is emitted (replaces the former | ||
| // `python3 -m py_compile` syntax check, which must not be required by the |
There was a problem hiding this comment.
P2: Dropping the py_compile check leaves the escaped-name output without any compile verification. The PR description promises generated files compile, and the file already has a skip-if-absent helper (assertPythonSyntaxValid) that could keep this check without requiring python3. Consider restoring the check through that helper.
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/AbstractPythonConnexionServerCodegenTest.java, line 446:
<comment>Dropping the `py_compile` check leaves the escaped-name output without any compile verification. The PR description promises generated files compile, and the file already has a skip-if-absent helper (`assertPythonSyntaxValid`) that could keep this check without requiring python3. Consider restoring the check through that helper.</comment>
<file context>
@@ -440,21 +424,29 @@ public void testEscapedNamesInAttributeMapAndApiKeyHeaders() throws IOException,
- assertPythonCompiles(blueplanetController, blueplanetTest);
+ // an unescaped quote would leave a broken literal like 'X-A&B'Head' in the
+ // file; pin that no such unterminated form is emitted (replaces the former
+ // `python3 -m py_compile` syntax check, which must not be required by the
+ // unit tests — see #25556)
+ assertFileNotContains(blueplanetTest, "'X-A&B'Head'", "'q&we's'", "'X-C&oo'kie'");
</file context>
There was a problem hiding this comment.
Thanks. This is intentional: upstream disabled the python3-based tests (#25556) because the unit tests must not require python3, and the skip-if-absent helper assertPythonSyntaxValid is being removed in #25579. The escaped literals are now pinned by exact-line assertions instead, and the "all generated .py files compile" statement in the description is an author-run check (55/55 files), not a unit test.
…ion-model-attribute-names Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mustache's
{{...}}HTML-escapes its value. The Connexion server templates write property and parameter names into Python string literals that way, so a model property nameda&bproducesand
from_dict({'a&b': 'x'})silently drops the value (abisNone). A'in a name becomes'.Changes
{{{...}}}from vendor extensions that hold them escaped for a single-quoted Python literal. The escaping is lossless:\,', newline, CR, tab and other control characters. It is used for:attribute_map(python-flask, python-aiohttp, python-blueplanet);x-python-connexion-quoted-name, with the same name and meaning as in feat(python-flask, python-aiohttp): deserialize object-typed query and header parameters #25427. That PR covers the header/cookie lookups in the python-flask/python-aiohttp controllers and tests, so this PR leaves those lines alone to avoid conflicts.keyParamName). With schemeapiKeyAuthand headerX-Api-Key, the generated test got 401. They now sendkeyParamName, and only for apiKeys in a header.Verification
Python*Test/AbstractPython*Testpass. A new spec has propertiesa&b,o'k,back\slash,dq"xandunicodeé, a query parameterq&we's, a headerX-A&B'Head, and an apiKey headerX-A&B'Key; the test asserts the rendered names for all three generators, plus a unit test for the escaper. The tests fail without the template change..pyfiles passpython -m compileall. For python-flask, on Connexion 2.14.2,EscapedNames.from_dict({...})keeps all five values, and before the change they were dropped.bin/generate-samples.sh bin/configs/python*.yamlproduces no diff; no sample uses such names.Not changed (known)
info.titleis still HTML-escaped where it goes into a Python literal (arguments={'title': ...}). This only affects the Swagger UI title.PR checklist
bin/configs/python*.yamlsamples: no diff. Generator options and docs are unchanged.cc @cbornet @tomplus @krjakbrjak @fa0311 (Python technical committee)
Parts of this change were drafted with AI coding assistants (Devin, Claude Code, with reviews by Codex and Fable) and reviewed and verified by me.
🤖 Generated with Claude Code
Summary by cubic
Stops Mustache's HTML escaping from corrupting property, parameter, and apiKey names in generated Python Connexion servers. Names like
a&boro'kwere written into Python string literals asa&boro'k, sofrom_dictsilently dropped such values and generated tests sent the wrong keys. These names are now escaped losslessly for single-quoted Python literals via vendor extensions.Bug Fixes
attribute_mapin python-flask, python-aiohttp, and python-blueplanet now renders the escaped wire name; query keys in generated tests and blueplanet header/cookie lookups usex-python-connexion-quoted-name.info.titleremains HTML-escaped in the Swagger UI title.escapeForPythonSingleQuotedLiteral, covered by unit tests and generated-file assertions for all three generators that assert rendered literals directly instead of compiling withpython3, which must not be required by unit tests (Disabled python tests that require python3 #25556).Written for commit e7f9cae. Summary will update on new commits.