Bug Report Checklist
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)
Bug Report Checklist
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
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
Literalinstead of usingField(..., const=True)