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
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using OAPI3 "discriminator" support, openapi-generator generates warnings when discriminator properties are specified with "$ref".
This is not ideal for large APIs that wish to use a shared enum that contains the discriminator mappings for many objects.
It is possible to silence the warning by re-defining the discriminator's type property in each polymorphic API object. In the example spec posted, this would look like:
BarBazType:
type: string
description: A discriminator reference.
enum:
- BAR
- BAZ
Baz:
required:
- type
properties:
type:
type: string
$ref: "#/components/schemas/BarBazType"
However, this produces an incorrect client, because the type property is generated as StrictStr with no enum constraints.
Actual output ... [main] WARN o.o.codegen.DefaultCodegen - 'Foo' defines discriminator 'type', but the referenced schema 'Bar' is incorrect. invalid type for type, set it to string [main] WARN o.o.codegen.DefaultCodegen - 'Foo' defines discriminator 'type', but the referenced schema 'Baz' is incorrect. invalid type for type, set it to string ...
Expected output
No warnings.
openapi-generator version
Bug detected on 7.2.0, confirmed against master (hash 6f01a7ad823).
Although the warning generated is the same, the root cause in my case seems to be the fact that the discriminator property in my minimal example uses "$ref".
Suggest a fix
When scanning the spec file to find the discriminator's property, inherit the type from child "$refs".
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
When using OAPI3 "discriminator" support,
openapi-generator
generates warnings when discriminator properties are specified with "$ref".This is not ideal for large APIs that wish to use a shared
enum
that contains the discriminator mappings for many objects.It is possible to silence the warning by re-defining the discriminator's
type
property in each polymorphic API object. In the example spec posted, this would look like:However, this produces an incorrect client, because the
type
property is generated asStrictStr
with noenum
constraints.Actual output
... [main] WARN o.o.codegen.DefaultCodegen - 'Foo' defines discriminator 'type', but the referenced schema 'Bar' is incorrect. invalid type for type, set it to string [main] WARN o.o.codegen.DefaultCodegen - 'Foo' defines discriminator 'type', but the referenced schema 'Baz' is incorrect. invalid type for type, set it to string ...
Expected output
No warnings.
openapi-generator version
Bug detected on 7.2.0, confirmed against master (hash
6f01a7ad823
).OpenAPI declaration file content or url
Minimal spec to reproduce:
https://gist.github.com/Hnefi/86cb2d748748b468b449ed4984e71bef
Generation Details
Command-line parameters to reproduce:
openapi-generator generate -g python -i oapi3.yaml -o /tmp/python_client
Steps to reproduce
Related issues/PRs
The most relevant issue is:
Although the warning generated is the same, the root cause in my case seems to be the fact that the discriminator property in my minimal example uses "$ref".
Suggest a fix
When scanning the spec file to find the discriminator's property, inherit the type from child "$refs".
The text was updated successfully, but these errors were encountered: