We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug
This is similar to #1797, but specifically about enums. When running datamodel-codegen on the schema below, the result includes
class PropertyOperator(str, Enum): exact = "exact" is_not = "is_not" icontains = "icontains" not_icontains = "not_icontains" class EventPropertyFilter(BaseModel): operator: Optional[PropertyOperator] = "exact"
This is invalid, because "exact" is not an instance of PropertyOperator.
"exact"
PropertyOperator
To Reproduce
Example schema:
{ "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "EventPropertyFilter": { "properties": { "operator": { "$ref": "#/definitions/PropertyOperator", "default": "exact" } }, "required": ["operator"], "type": "object" }, "PropertyOperator": { "enum": [ "exact", "is_not", "icontains", "not_icontains" ], "type": "string" } } }
Used commandline:
$ datamodel-codegen \ --class-name='SchemaRoot' --collapse-root-models --target-python-version 3.10 --disable-timestamp \ --use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum \ --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel
Expected behavior
The output should be this:
class EventPropertyFilter(BaseModel): - operator: Optional[PropertyOperator] = "exact" + operator: Optional[PropertyOperator] = PropertyOperator("exact")
Version:
The text was updated successfully, but these errors were encountered:
@Twixes We have the --set-default-enum-member to set the enum member as the default value.
--set-default-enum-member
--set-default-enum-member Set enum members as default values for enum field
... class EventPropertyFilter(BaseModel): operator: Optional[PropertyOperator] = PropertyOperator.exact
Sorry, something went wrong.
Thank you! I missed --set-default-enum-member completely, but it's perfect.
No branches or pull requests
Describe the bug
This is similar to #1797, but specifically about enums. When running datamodel-codegen on the schema below, the result includes
This is invalid, because
"exact"
is not an instance ofPropertyOperator
.To Reproduce
Example schema:
Used commandline:
Expected behavior
The output should be this:
Version:
The text was updated successfully, but these errors were encountered: