Multiple body-types in an endpoint with same model (referenced via `$ref`) results in ambiguity in generated code · Issue #1004 · openapi-generators/openapi-python-client · GitHub
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an endpoint has multiple body types, each referencing the same model (via a $ref key), the generator generates the same class name for each body types, which results then in the following generated code:
As you can see, both if-statement's conditions will resolve to True, therefore only the last body type will be used.
Desired Behavior
The body-type should be part of the generated class name to avoid such ambiguities.
Or an if/elseif/else should be used in the template (which would result in the first one being applied ONLY).
OpenAPI Spec File
The OpenAPI spec is from Netbox, but here is the relevant snippet:
With this custom template in a location like custom-templates/endpoint_module.py.jinja, openapi-python-client generate --custom-template-path=custom-templates generates the patched code. Using the patch requires setting the content-type header to the desired type when creating a Client object.
I suspect this is not a proper fix, which probably needs a better way of handling differing body types with the same class names. I'm not really knowledgable enough about this codebase to do that, just sharing in case it helps someone else.
Actual Behavior
When an endpoint has multiple body types, each referencing the same model (via a
$ref
key), the generator generates the same class name for each body types, which results then in the following generated code:As you can see, both if-statement's conditions will resolve to
True
, therefore only the last body type will be used.Desired Behavior
The body-type should be part of the generated class name to avoid such ambiguities.
Or an
if/elseif/else
should be used in the template (which would result in the first one being applied ONLY).OpenAPI Spec File
The OpenAPI spec is from Netbox, but here is the relevant snippet:
The text was updated successfully, but these errors were encountered: