datamodel-code-generator
datamodel-code-generator copied to clipboard
CLI help incorrectly shows --strict-nullable as only applying to OpenAPI
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:
- OS: Linux
- Python version: 3.11.4
- datamodel-code-generator version: 0.22.1