Okay, this is obviously a really minor one, but I did just get caught out by it. π
Describe the bug
When running datamodel-codegen --help
(or reading the README), the flag --strict-nullable
appears in the "OpenAPI-only options" section and has "(Only OpenAPI)" in its description. However, that flag also has an effect on JSON Schema input.
To Reproduce
Example schema:
{
"type": "object",
"required": [ "foo" ],
"properties": {
"foo": { "type": "string" },
"bar": { "type": "integer", "default": 5 }
}
}
Used commandline:
~/tmp $ datamodel-codegen --input example.schema.json --input-file-type jsonschema
# generated by datamodel-codegen:
# filename: example.schema.json
# timestamp: 2023-11-05T05:53:29+00:00
from __future__ import annotations
from typing import Optional
from pydantic import BaseModel
class Model(BaseModel):
foo: str
bar: Optional[int] = 5
~/tmp $ datamodel-codegen --input example.schema.json --input-file-type jsonschema --strict-nullable
# generated by datamodel-codegen:
# filename: example.schema.json
# timestamp: 2023-11-05T05:53:47+00:00
from __future__ import annotations
from pydantic import BaseModel
class Model(BaseModel):
foo: str
bar: int = 5
In this example, adding the --strict-nullable
flag changes the type of bar
from Optional[int]
to just int
.
Expected behavior
The --strict-nullable
flag should not be identified as only applying to OpenAPI, as it makes the flag significantly less discoverable for those who need its effect when working with JSON Schema.
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