Skip to content

[BUG][Python] OneOf creates a pydantic Field which is not support in pydantic v2 const=True #16176

Description

@bykof

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

If I create a schema that has a oneOf or anyOf field, it generates a pydantic Field with const=True.
The keyword const=True is deprecated and removed in pydantic v2.
The error is: PydanticUserError('constis removed, useLiteral instead'

openapi-generator version

v6.6.0

OpenAPI declaration file content or url
openapi: 3.0.3
servers:
  - url: https://petstore3.swagger.io/api/v3
paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
      responses:
        '200':
          description: Updated
components:
  schemas:
    Dog:
      type: object
      properties:
        bark:
          type: boolean
        breed:
          type: string
          enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer
Generation Details

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -g python --additional-properties=generateSourceCodeOnly=true,packageName=client --skip-validate-spec -o /local/ -i /local/openapi.yaml

Suggest a fix

Change to Literal instead of using Field(..., const=True)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions