marshmallow-code / apispec

A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification)..
https://apispec.readthedocs.io/
MIT License
1.18k stars 177 forks source link

Fix decimal range validators #870

Closed intZero closed 11 months ago

intZero commented 1 year ago

"Native" numerical types such as Int and Float serialize correctly but Decimal needs to specifically be serialized to a float for the renderer.

From this issue: https://github.com/marshmallow-code/apispec/issues/869

Previously, this field

conversion_factor = fields.Decimal(required=True, validate=[Range(min=0, max=1000000)])

would render to:

conversion_factor:
  type: number
  minimum: !!python/object/apply:decimal.Decimal
  - '0'
  maximum: !!python/object/apply:decimal.Decimal
  - '1000000'

Now it will render to:

conversion_factor:
  type: number
  minimum: 0.0
  maximum: 1000000.0
lafrech commented 1 year ago

I think it is the same issue as flask-smorest's https://github.com/marshmallow-code/flask-smorest/issues/517, except in flask-smorest we want to solve it by using flask json serializer.

Did you set as_string=True? See docstring in Decimal field.