I have the following OpenAPI spec which does not appear to work in terms of generating an Optional
field:
components:
Foo:
type: object
nullable: true
properties:
bar:
type: string
Thing:
type: object
properties:
foo:
$ref: '#/components/schemas/Foo'
This is using flags:
--use-title-as-name \
--input-file-type openapi \
--snake-case-field \
--base-class lib.CamelCaseBaseModel \
--target-python-version 3.9 \
--validation \
--strict-nullable
I have the following OpenAPI spec which does work in terms of generating an Optional
field:
Thing:
type: object
properties:
foo:
type: object
nullable: true
properties:
bar:
type: string
The correct output I'm after is:
foo: Optional[Foo] = Field(...)
What I'm actually doing is bundling via redoc
with:
redocly bundle openapi/openapi.yaml --output openapi-generated.yaml
python -m datamodel_code_generator \
--input openapi-generated.yaml \
--output lib/models.py \
--use-title-as-name \
--input-file-type openapi \
--snake-case-field \
--base-class lib.CamelCaseBaseModel \
--target-python-version 3.9 \
--validation \
--strict-nullable
I can work around (or will just use) --dereference
for redocly
but thought I'd flag what I think is a bug.
Version:
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