Skip to content

Commit

Permalink
πŸ› Make numeric constraints integer when the field is integer type.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalkrupinski committed Oct 21, 2024
1 parent 1dd9b7c commit ee2ce46
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lapidary/render/model/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,20 @@ def process_property(self, value: openapi.Schema, stack: Stack, prop_name: str,
else None
)

# constraints should be processed and applied per type, but for now we only have a single Field annotation,
# and pydantic doesn't like float constraints for int fields.
is_int = in_types(typ, (python.TypeHint.from_type(int),))

for k in value.model_fields_set:
v = getattr(value, k)

if k == 'maximum':
field_prop = 'lt' if value.exclusiveMaximum else 'le'
field_props[field_prop] = v
field_props[field_prop] = int(v) if is_int else v
continue
if k == 'minimum':
field_prop = 'gt' if value.exclusiveMinimum else 'ge'
field_props[field_prop] = v
field_props[field_prop] = int(v) if is_int else v
continue
if k not in FIELD_PROPS:
continue
Expand Down

0 comments on commit ee2ce46

Please sign in to comment.