Describe the bug
When defining an integer with a maximum and exclusiveMaximum in an OpenAPI specification, the resulting python field uses lt and le at the same time, which results in a runtime error:
Traceback (most recent call last):
File "test.py", line 12, in <module>
class Problem(BaseModel):
File "pydantic/main.py", line 237, in pydantic.main.ModelMetaclass.__new__
File "pydantic/typing.py", line 161, in pydantic.typing.resolve_annotations
if isinstance(obj, type):
File "/usr/lib/python3.8/typing.py", line 270, in _eval_type
return t._evaluate(globalns, localns)
File "/usr/lib/python3.8/typing.py", line 518, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
File "pydantic/types.py", line 365, in pydantic.types.conint
File "pydantic/types.py", line 328, in pydantic.types.ConstrainedNumberMeta.__new__
pydantic.errors.ConfigError: bounds lt and le cannot be specified at the same time
To Reproduce
Example schema:
openapi: 3.0.3
info:
version: 1.0.0
title: Bug
servers: []
paths: {}
components:
schemas:
Problem:
type: object
properties:
status:
type: integer
minimum: 100
maximum: 600
exclusiveMaximum: true
Used commandline:
$ datamodel-codegen --input spec.yaml --output test.py
This results in:
class Problem(BaseModel):
status: Optional[conint(ge=100, le=600, lt=1)] = None
Expected behavior
The resulting code should be lt=600, without an additional le argument.
Version:
@languitar
I could reproduce the bug.
I have fixed it and released a new version as 0.5.38
Thanks again for the quick support!
Most helpful comment
Thanks again for the quick support!