Closed DanielContrerasAladro closed 2 years ago
@DanielContrerasAladro Thank you very much for the contribution.
The PR looks really good, I wanted to understand when (what use-case) the number transformation would happen?
The example above is the result after the openapi-format, what would be the initial state of the "maximum" & "minimum" number? That way I can create a test for it to prevent any future regression from happening.
Because I need to see numbers like that on the output
components: schemas: NumberLimitsSchema: type: number maximum: 9999999999999.99999 minimum: 0 multipleOf: 0.0000000001
So the steps to reproduce would be:
components: schemas: NumberLimitsSchema: type: number maximum: 9999999999999.99999 minimum: 0 multipleOf: 0.0000000001
components: schemas: NumberLimitsSchema: type: number maximum: 10000000000000 minimum: 0 multipleOf: 1e-1
components: schemas: NumberLimitsSchema: type: number maximum: 9999999999999.99999 minimum: 0 multipleOf: 0.0000000001
Is that correct?
Exactly, it's exactly the case. That's the reason I've created the '-b' flag to activate this fix on the CLI
If the reproduce behaviour is correct, than I would not make it an CLI option but default behaviour, since it seems like an unwanted number conversion done by openapi-format.
Would you agree that this should be default?
Perfect for me
Would it be OK if I keep only the 2 parts:
fileContent = fileContent.replace( /\b([0-9]*\.?[0-9]+)\b/g, ( number ) => {
return `'${ number }'`;
} );
o = o.replace( /'([0-9]*\.?[0-9]+)'/g, ( number ) => {
return number.replace( /'/g, '' );
} );
Would you prefer that you modify your PR or that I patch it in a new PR?
I've just removed
@DanielContrerasAladro Thanks again for the contribution. I'm going to merge it in and create an additional test for it so that I can release it this week.
You're welcome!
@DanielContrerasAladro After running some tests, is it OK that openapi-format target specifically the "minimum" & "maximum" properties? Or would this unwanted conversion also would happen on other properties?
The test suite was complaining about unwanted conversions. So I might tweak your regex or target specific properties.
It would happen on other properties too, 'multipleOf' for example....and could happen on more other properties
FYI: I reported the issue with the YAML @stoplight/yaml package, which we are using behind the scenes: https://github.com/stoplightio/yaml/issues/53
@DanielContrerasAladro I might have to revert the PR, since the impact is quite big as currently all number values are being converted, which is not desired and can cause for invalid OpenAPI documents.
I'll continue this week to figure out a safe way to handle these large numbers.
Fixing large number transformation like
components: schemas: NumberLimitsSchema: type: number maximum: 9999999999999.99999 minimum: 0 multipleOf: 0.0000000001
components: schemas: NumberLimitsSchema: type: number maximum: 10000000000000 minimum: 0 multipleOf: 1e-10
allowing to parse to a readable data instead of rounded or scientific notation