Skip to content

Pydantic throws an error on CommuncationDetails subclasses #19

Open

Description

@jorritn

PydanticUserError: Model 'WebSocketCommunicationDetails' needs field 'communicationProtocol' to be of type Literal

For further information visit https://errors.pydantic.dev/2.12/u/discriminator-needs-literal

Activity

  1. jorritn commented on Nov 25, 2025

    @jorritn
    ContributorAuthor

    There are a couple of things wrong. First of all, we need the discriminator in the generic ConnectionDetails object in the OpenAPI definition. Furthermore, there is an open PR to support the discriminator in the datamodel-code-gen tool (which is used by fast-api-codegen).

  2. jorritn commented on Nov 25, 2025

    @jorritn
    ContributorAuthor

    Quick fix is changing the type of the communicationProtocol field of the CommuniationDetails class to:

    communicationProtocol: Literal['Websocket'] | Literal['SomeOtherProtocol']
  3. jorritn commented on Nov 25, 2025

    @jorritn
    ContributorAuthor

    I've added the discriminator to the openapi spec #22 Still need to generate the models again once the PR that fixes this in the datamodel generator datamodel-code-generator/datamodel-code-generator#2530

  4. self-assigned this
    on Jan 26, 2026
  5. jorritn commented on Feb 5, 2026

    @jorritn
    ContributorAuthor

    Is fixed in datamodel-code-generator version 0.37.0. We're using a recent version now.

  6. reopened this on Feb 5, 2026
  7. jorritn commented on Feb 5, 2026

    @jorritn
    ContributorAuthor

    After upgrading to datamodel-code-generator version 0.53.0 the validation error persists... So I've applied the quick fix again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions