-
Notifications
You must be signed in to change notification settings - Fork 4
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
representation of decimal numbers #79
Comments
The spec on number type: (JSON Schema refers to JSON RFC for this) https://tools.ietf.org/html/rfc8259#section-6
|
update 13/1: add new results with newer swagger-codegen (the one in SwaggerHub), and tests with string type and format number I did some tests with code generation:
|
proposition: In openapi-money, for MonetaryAmount, use type: string
format: decimal # decimal is a custom format only supported in some tooling
pattern: '^(\-|\+)?((\d+(\.\d*)?)|(\.\d+))$' # based on BigDecimal (Java) but without exponent support. At least one digit required, before or after comma
# valid values: "100.234567", "010", "-.05", "+1", "10", "100." I'll create a PR for validation next time. |
did some more tests with codegen tooling; updated the above comment with results. Seems like |
PR ready for review: #90 |
pull request was review in WG of March, and merged |
For future reference this page also sums up this problem space quite well: https://github.com/zalando/jackson-datatype-money/blob/main/MONEY.md |
How to represent decimal numbers with fixed precision: as number or as string type?
For use in MonetaryAmount, see belgif/openapi-money#2
For decimals with fixed precision:
So two options:
A) use number type with format, not in openapi-common
=> might be converted to float by default which is dangerous (can someone test?)
variant: add "multipleOf: 0.0001" to express precision. But this can also lead to other floating point problems for libraries implementing this (json-schema-org/json-schema-spec#312 , xeipuuv/gojsonschema#149).
B) define Decimal type based on string
=> has to be converted in code from string to appropriate decimal type (e.g. BigDecimal in Java)
The text was updated successfully, but these errors were encountered: