Skip to content
New issue

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

minimum and maximum property are restricted to f64. Which looks weird and its also encoding wrong for large numbers. #910

Open
stevenj opened this issue Nov 7, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@stevenj
Copy link

stevenj commented Nov 7, 2024

Description of the feature

Currently Poem defines minimum and maximum as f64.
When it encodes the openapi it results in things like this:

"limit": {
            "type": "integer",
            "format": "u64",
            "title": "Limit",
            "description": "The size `limit.",
            "default": 100,
            "example": 10,
            "maximum": 100.0,
            "minimum": 1.0
          },

Note the type is an integer, but the min/max are floats which confusingly suggests that I could set a value of 6.8 and it be valid. Which is not correct.

Also, using floats corrupts large numbers as f64 can not encode above 2^53 without losing precision.
If I have a value that can be larger than that, which is stored in a u64, the document is wrong.

It should be possible to select if the min/max are floats or integers. If they are integers, ideally they would support large values.
Instead of f64, min/max could be encoded with https://crates.io/crates/bigdecimal and if the type is an "integer" the value is serialized without any decimal place, if its a "float" the min/max serializes with a decimal place.

This way there would be no arbitrary limit on the parameter, and the min/max would follow the underlying type.

This is an example where the maximum results in invalid data in the document:

          "remaining": {
            "type": "integer",
            "format": "u64",
            "title": "Remaining",
            "description": "The number of items remaining.",
            "example": 18446744073709551615,
            "maximum": 1.8446744073709552e19,
            "minimum": 0.0
          }
@stevenj stevenj added the enhancement New feature or request label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant