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
Describe the bug
When generating an OpenAPI contract with discriminator in schema, Pydantic V1 and V2 models use an alias instead of the field name for discriminator, which is why Pydantic fails with error:
V1: pydantic.v1.errors.ConfigError: Model 'BadRequestError' needs a discriminator field for key '$type'
V2: pydantic.errors.PydanticUserError: Model 'BadRequestError' needs a discriminator field for key '$type'
Expected behavior
If we change the value of the discriminator from the alias Field(..., discriminator='$type') to the field name Field(..., discriminator='field_type'), then it starts to work correctly
Describe the bug
When generating an OpenAPI contract with discriminator in schema, Pydantic V1 and V2 models use an alias instead of the field name for discriminator, which is why Pydantic fails with error:
V1:
pydantic.v1.errors.ConfigError: Model 'BadRequestError' needs a discriminator field for key '$type'
V2:
pydantic.errors.PydanticUserError: Model 'BadRequestError' needs a discriminator field for key '$type'
To Reproduce
Example schema:
Used commandline:
Output:
Expected behavior
If we change the value of the discriminator from the alias
Field(..., discriminator='$type')
to the field nameField(..., discriminator='field_type')
, then it starts to work correctlyVersion:
The text was updated successfully, but these errors were encountered: