Open mg1308 opened 3 years ago
We are experiencing the same problem, and would like to have a solution.
I have the same issue that responses containing decimals are rendered without them, e.g. -1.0 is rendered as -1
This is a javascript limitation...
const double = 1.0 // will be 1
Hi all,
Yes as @mathis-m mentioned, it's a JavaScript thing.
Number 0.0
is not decimal or integer. It's a float, specifically double-precision 64-bit binary format IEEE 754. The only difference between 0.0
and 0
is the notation that was used to create aforementioned floats. There is also a special case of -0
and +0
which is even more confusing ;]
-0 === +0; // true
Object.is(-0, +0); // true
Basically if numbers are defined in JSON Schema or transfered via API, there no way to get the information for the JavaScript, what notation was used to create the number.
Related problem https://github.com/swagger-api/swagger-ui/issues/7478#issuecomment-916190335
I understand the reasoning that it is JavaScript's way of formatting numbers. But this is JSON returned as a string by an API. Why does it need to be parsed as a number?
@fredebk this is because swagger-ui is formatting the response.
Yes we need to parse the response to display it - and that's where the original notation is lost.
I understand that. However, after identifying that this is a number, and adding syntax highlighting, the original string should be written, rather than the parsed number.
I understand that. However, after identifying that this is a number, and adding syntax highlighting, the original string should be written, rather than the parsed number.
That would include significant effort, probably involving creating custom JSON parser and mechanism to map resulting highlighted code to parsed CST nodes from custom parser.
This is unfortunate issue of JavaScript that we'll not be mitigating currently. It's possible that I'm wrong and the problem is somehow fixable with minimal effort solution that I don't currently see. In that case please issue a PR, and we'll collaborate further there.
This should no longer be an issue with 3.X. Please reopen otherwise.
Originally posted by @webron in https://github.com/swagger-api/swagger-ui/issues/2088#issuecomment-288948198
I still see this issue of double not rendered correctly under "example" tab