Describe the bug
Often the name is used as the value of Literal
To Reproduce
Example schema:
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-aa9b01fc0c17eb0cbc200533fc20d6a49c5e764ceaf8049e08b294532be6e9ff.yml
Used commandline:
$ datamodel-codegen \
--input openai-aa9b01fc0c17eb0cbc200533fc20d6a49c5e764ceaf8049e08b294532be6e9ff.yml \
--output models.py \
--output-model-type pydantic_v2.BaseModel \
--target-python-version 3.12 \
--enum-field-as-literal all \
--field-constraints \
--use-standard-collections \
--use-union-operator \
--field-include-all-keys \
--use-default-kwarg \
--use-exact-imports \
--use-schema-description \
--treat-dot-as-module \
--use-title-as-name \
Expected behavior
(part of yml)
OtherChunkingStrategyResponseParam:
type: object
title: Other Chunking Strategy
description: >-
This is returned when the chunking strategy is unknown. Typically, this is because the file was
indexed before the `chunking_strategy` concept was introduced in the API.
additionalProperties: false
properties:
type:
type: string
description: Always `other`.
enum:
- other
required:
- type
(what i expected)
class OtherChunkingStrategy(BaseModel):
"""
This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the `chunking_strategy` concept was introduced in the API.
"""
model_config = ConfigDict(
extra='forbid',
)
type: Literal['other'] = Field(
..., description='Always `other`.'
)
(What actually happened)
class OtherChunkingStrategy(BaseModel):
"""
This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the `chunking_strategy` concept was introduced in the API.
"""
model_config = ConfigDict(
extra='forbid',
)
type: Literal['OtherChunkingStrategyResponseParam'] = Field(
..., description='Always `other`.'
)
Noted that the 'Literal['OtherChunkingStrategyResponseParam']' instead of Literal['other']
Version:
Additional context
In this case, the frequency of occurrence of only one enumeration value is highγ
e.g
class CodeInterpreterImageOutput(BaseModel):
index: int = Field(..., description='The index of the output in the outputs array.')
type: Literal['RunStepDeltaStepDetailsToolCallsCodeOutputImageObject'] = Field(
..., description='Always `image`.'
)
image: Image1 | None = None
class CodeInterpreterLogOutput(BaseModel):
"""
Text output from the Code Interpreter tool call as part of a run step.
"""
index: int = Field(..., description='The index of the output in the outputs array.')
type: Literal['RunStepDeltaStepDetailsToolCallsCodeOutputLogsObject'] = Field(
..., description='Always `logs`.'
)
logs: str | None = Field(
default=None, description='The text output from the Code Interpreter tool call.'
)
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too