fix(python-aiohttp, python-blueplanet, python-flask): map params iterate .items(); free-form params skip from_dict
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.mustache renders map conversions as {k: ...(v) for k, v in {{paramName}}}, without .items(). At runtime this tries to unpack each key string into k, v, which fails with ValueError. The python-blueplanet and python-flask templates already use .items(). This PR adds .items(), and also guards optional map parameters with if {{paramName}} is not None:, since they default to None.
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 plain object, and the templates emit x = object.from_dict(x) (python-flask), or x = .from_dict(x) (python-aiohttp and python-blueplanet, which fail to import with SyntaxError). object has no from_dict, so the handler fails at runtime.
AbstractPythonConnexionServerCodegen now marks parameters that are free-form or any-type and whose dataType is plain object with the vendor extension x-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 / oneOf refs), which are also any-type but carry a model dataType.
Tests and verification
- New specs:
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.- Compared with 7.26.0 output: for
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. - Called the generated python-aiohttp handler with real map and free-form values, and with the optional maps omitted. It returned 200.
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
- Read the contribution guidelines.
- Run the following to build the project and update samples:
Ran the Python generator tests listed above and regenerated the samples for the three affected generators' configs. No sample changed. Generator options and docs are unchanged../mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
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 iterate dict.items(), and free-form or untyped object parameters no longer get deserialized via from_dict.
Bug Fixes
- Adds
.items()to map parameter comprehensions inpython-aiohttpand guards optional maps with aNonecheck. - Marks free-form and
{}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. - Adds test specs and generator tests covering map, free-form, and composed model parameters, including maps with
additionalProperties.