Repository navigation
fix(python-aiohttp, python-blueplanet, python-flask): map params iterate .items(); free-form params skip from_dict - #25361
Open
khayashi4337 wants to merge 3 commits into
Conversation
…ms and skip from_dict on free-form params
In python-aiohttp controller.mustache, map parameter comprehensions iterated
over dict keys instead of .items(), raising ValueError at runtime when
unpacking (k, v). Add .items() to match python-blueplanet and python-flask.
In python-aiohttp, python-blueplanet, and python-flask controller.mustache,
guard non-container model deserialization with {{^isFreeFormObject}} and
{{^isAnyType}} so free-form object (schema: {type: object}) and untyped
(schema: {}) parameters are not deserialized via .from_dict().
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…t dataType and guard None map params
Composed schemas without an explicit type (such as allOf or oneOf model $refs)
also set CodegenParameter.isAnyType=true while setting dataType to the model
class name, so guarding controller templates directly with {{^isAnyType}}
skipped Model.from_dict() on composed model parameters. Set the vendor
extension x-python-connexion-skip-from-dict in
AbstractPythonConnexionServerCodegen#postProcessOperationsWithModels only when
(isFreeFormObject || isAnyType) and dataType is "object", and guard the
python-aiohttp map parameter comprehensions with `if <param> is not None:`.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
3 tasks done
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
…ery param test
Verify that the WithAddl query parameter (which defines both properties and
additionalProperties: {type: string}) is classified by DefaultCodegen as a map
container (`isMap=true`, `isContainer=true`) and therefore emits `:type addl:
Dict[str, str]` in the docstring without a `.from_dict()` conversion line in
the controller body, matching 7.26.0 output.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.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.
Two small template bugs in the Connexion-based Python server generators (python-aiohttp, python-blueplanet, python-flask), both reproduced with the released openapi-generator-cli 7.26.0.
1. python-aiohttp: map parameters iterate the dict's keys
python-aiohttp/controller.mustacherenders map conversions as{k: ...(v) for k, v in {{paramName}}}, without.items(). At runtime this tries to unpack each key string intok, v, which fails withValueError. The python-blueplanet and python-flask templates already use.items(). This PR adds.items(), and also guards optional map parameters withif {{paramName}} is not None:, since they default toNone.2. Free-form / any-type parameters call
object.from_dict(...)For a non-container parameter whose schema is free-form (
{type: object}with no properties) or empty ({}), the type is plainobject, and the templates emitx = object.from_dict(x)(python-flask), orx = .from_dict(x)(python-aiohttp and python-blueplanet, which fail to import withSyntaxError).objecthas nofrom_dict, so the handler fails at runtime.AbstractPythonConnexionServerCodegennow marks parameters that are free-form or any-type and whose dataType is plainobjectwith the vendor extensionx-python-connexion-skip-from-dict. The templates skip the conversion for those parameters, so they receive the raw value. Parameters whose type is a model are not affected, including typeless composed models (allOf/oneOfrefs), which are also any-type but carry a model dataType.Tests and verification
src/test/resources/3_1/python/map-and-freeform-params.yamlandcomposed-query-params.yaml. New tests inAbstractPythonConnexionServerCodegenTest. They check that.items()and theNoneguard are emitted, that free-form and{}parameters get nofrom_dict, and thatComposed.from_dict/OneOfM.from_dict/Pet.from_dictare still emitted for model parameters. Each test fails without its fix.Python*Test,AbstractPython*Test: 164 tests, 0 failures. Samples forbin/configs/python-aiohttp*,python-blueplanet*andpython-flask*regenerate with no changes.composed-query-params.yaml,default_controller.pyis identical in all three generators. Formap-and-freeform-params.yaml, the python-aiohttp and python-blueplanet controllers no longer failpy_compile, and the python-flaskobject.from_dictlines are gone.Note on overlap
This touches the same
{{^isContainer}}…{{^isPrimitiveType}}blocks of the three controller templates as #25352 and #25362. Whichever lands first, I'll rebase the others.PR checklist
cc @cbornet @tomplus @krjakbrjak @fa0311 (Python technical committee)
Parts of this change were drafted with AI coding assistants (Devin, Claude Code) and reviewed and verified by me.
🤖 Generated with Claude Code
Summary by cubic
Fixes two template bugs in the Python Connexion server generators (
python-aiohttp,python-blueplanet,python-flask): map parameters now iteratedict.items(), and free-form or untyped object parameters no longer get deserialized viafrom_dict.Bug Fixes
.items()to map parameter comprehensions inpython-aiohttpand guards optional maps with aNonecheck.{}schema parameters (with plainobjectdataType) with the vendor extensionx-python-connexion-skip-from-dict, so controllers receive raw values; model and composed model parameters remain unchanged.additionalProperties.Written for commit 88f4c75. Summary will update on new commits.