Repository navigation
fix(python-flask, python-aiohttp, python-blueplanet): don't HTML-escape names inside generated Python string literals - #25457
Open
khayashi4337 wants to merge 8 commits into
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>
3 tasks done
…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>
Contributor
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>
Contributor
Author
|
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>
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.
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 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, blueplanet header/cookie names in generated tests, and blueplanet controller lookups usex-python-connexion-quoted-nameto match feat(python-flask, python-aiohttp): deserialize object-typed query and header parameters #25427.info.titleremains HTML-escaped in the Swagger UI title.escapeForPythonSingleQuotedLiteral, covered by unit tests and generated-file assertions for all three generators.Written for commit 2a344aa. Summary will update on new commits.