Skip to content

fix(python-aiohttp, python-blueplanet): avoid '= .from_dict(' for $ref header/query parameters - #25352

Merged
wing328 merged 5 commits into
OpenAPITools:masterfrom
khayashi4337:fix/python-connexion-header-content
Nov 2, 2026
Merged

wing328 merged 5 commits into
OpenAPITools:masterfrom
khayashi4337:fix/python-connexion-header-content

Conversation

@khayashi4337

@khayashi4337 khayashi4337 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

For a parameter whose schema is a $ref to a model and that is not a container — for example a header defined with content: application/json + $ref — DefaultCodegen.fromParameter leaves baseType null (it is only set for map and array parameters). The python-aiohttp and python-blueplanet controller templates render {{baseType}}.from_dict(...), so the generated controller contains

x_json_arg = .from_dict(x_json_arg)                                   # python-aiohttp
x_json_arg = .from_dict(connexion.request.get_json())  # noqa: E501   # python-blueplanet

and the module fails to import (SyntaxError: invalid syntax). Reproduced with the released openapi-generator-cli 7.26.0 and src/test/resources/3_1/python/json-header-content.yaml.

Change

Apply the fallback that python-flask's controller.mustache already uses ({{baseType}}{{^baseType}}{{#dataType}}{{.}}{{/dataType}}{{/baseType}}) to the python-aiohttp and python-blueplanet controller templates, so the line becomes x_json_arg = HeaderArg.from_dict(...). CodegenParameter has no complexType field, and dataType is the field that holds the model name for these parameters. The template is changed rather than DefaultCodegen, because filling baseType there would affect every generator's {{#baseType}} branches.

Only lines that previously rendered as = .from_dict( change. Comparing 7.26.0 and this branch on a spec with ~20 parameter shapes ($ref enum/object/allOf, inline and free-form objects, uuid/binary/date, arrays, maps, bodies, header/query/path/cookie), every other line is identical. python-flask output is unchanged.

Tests

  • Two tests in AbstractPythonConnexionServerCodegenTest (python-aiohttp and python-blueplanet) generate from the existing json-header-content.yaml. They assert HeaderArg.from_dict( is emitted and = .from_dict( is not. Both fail without the template change.
  • Python*Test, AbstractPython*Test: 164 run, 0 failures. Samples for bin/configs/python-aiohttp*, python-blueplanet*, python-flask* regenerate with no changes.

Scope and known limitations (pre-existing, not changed here)

This makes the generated controllers importable again. It does not make JSON header parameters work end to end:

  • Connexion does not pass in: header parameters to handler functions. Only path, query, body and files are injected (see Connexion's request handling docs and the 2.14.2 / 3.x argument-building code). Handlers that declare a header argument therefore still fail at request time in python-aiohttp, python-blueplanet and python-flask alike.
  • python-blueplanet and python-flask deserialize non-body model parameters from request.get_json(), which is the request body.
  • A free-form type: object parameter renders object.from_dict(...) (previously .from_dict(...)), which is the same as python-flask's current output.

These look like separate issues and I'm happy to open them if that's useful.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    Ran ./mvnw -pl modules/openapi-generator test (5521 tests, 0 failures), ./bin/generate-samples.sh for the three affected generators' configs, and ./bin/utils/export_docs_generators.sh. Neither produced changed files.
  • 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 invalid .from_dict(...) calls in the python-aiohttp and python-blueplanet controllers when a header or query parameter references a model via $ref. The controller templates now fall back to dataType when baseType is null, matching python-flask, so the generated module imports without a SyntaxError.

Adds tests for both generators using json-header-content.yaml, asserting HeaderArg.from_dict( is emitted, no = .from_dict( appears, and that the blueplanet controller reads the header from the request headers. Free-form parameters keep skipping from_dict via the x-python-connexion-skip-from-dict guard.

Limitations

  • Connexion does not pass in: header parameters to handlers, so JSON header parameters still fail at request time in all three generators.
  • python-flask deserializes non-body model parameters from request.get_json(), which is the request body.

Written for commit 20b8e87. Summary will update on new commits.

View guided diff

…seType is null in controller

Non-container parameters created via DefaultCodegen.fromParameter (such as
header or query parameters referencing a model schema via content+$ref or
schema+$ref) populate CodegenParameter.dataType without setting baseType.
Fall back to dataType in python-aiohttp and python-blueplanet controller
templates (matching the existing python-flask pattern) so model.from_dict()
calls do not emit a leading dot and cause a SyntaxError.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

View guided diff | Re-trigger cubic

khayashi4337 and others added 4 commits October 26, 2026 17:56
…ion-header-content

Resolves conflicts with OpenAPITools#25361 (free-form params skip from_dict): keep the
x-python-connexion-skip-from-dict guard from master and this branch's
dataType fallback for a null baseType on the same line, and keep both
sets of new tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ion-header-content

Resolves conflicts with OpenAPITools#25362: master now splits the body and non-body
model conversion; keep that structure and apply this branch's dataType
fallback (for a null baseType) to the body line as well. The blueplanet
JSON-header test now expects the header to be read from the request
headers (OpenAPITools#25362) instead of the request body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ion-header-content

# Conflicts:
#	modules/openapi-generator/src/test/java/org/openapitools/codegen/python/AbstractPythonConnexionServerCodegenTest.java
…ion-header-content

# Conflicts:
#	modules/openapi-generator/src/test/java/org/openapitools/codegen/python/AbstractPythonConnexionServerCodegenTest.java
@wing328
wing328 merged commit b3f5335 into OpenAPITools:master Nov 2, 2026
15 checks passed
@wing328 wing328 added this to the 7.28.0 milestone Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants