Closed chmerk closed 6 years ago
Thanks for taking the time to report this Chris. I know it takes time and effort, so it is appreciated.
You're the first person to report this, so thank you for being diligent. In return, I spent my evening looking into it. It's down to the way Python's json
package formats floats. I've monkey-patched the json
package for now, so this will be fixed in the next release. The monkey-patch will likely remain in place until the service is rewritten in Go later this year.
This was actually fixed a while back - but I've rolled far too many updates into the forthcoming release, so it got pushed-out. Should be with you less than a week.
Regarding 1. { "price": 12.3 }
now generates:
"price": {
"$id": "#/properties/price",
"type": "number",
"title": "The Price Schema",
"default": 0.0,
"examples": [
12.3
]
}
Regarding 2. "storage": [2,13,5,42]
now generates:
"storage": {
"$id": "#/properties/storage",
"type": "array",
"title": "The Storage Schema",
"items": {
"$id": "#/properties/storage/items",
"type": "integer",
"title": "The Items Schema",
"default": 0,
"examples": [
2,
13,
5,
42
]
}
}
I found two funny bugs in the generated examples, possibly related:
When using a numeric value with fractional digits, some digits are appended or the number gets "rounded" in a weird way. Example:
"price": 12.3,
producesor
"Y": 9.386496
produces..."examples": [ 9.386495590209961 ]
The "example generator" also seems to have an issue with the numbers "4" and "5" in numeric arrays:
"storage": [2,13,5,42]
produces"examples": [ 2, 13, 42 ]
or to exaggerate this:
"numArray": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
produces... "examples": [ 0, 1, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ] // 4 and 5 are missing!