fix(openapi-typescript): Stringify primitive constant values #1149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1118
Changes
#1118
The
escStr
function claims to always return a string, but in fact would return whatever was passed into it, preserving the original type.This PR aligns the behavior of the function with type signature, and keeps the original behavior mostly the same.
Because these values were being turned into strings (through implicit
toString()
during backtick string expansion), the final generated output was mostly correct.Additionally, because there was special handling for
const
values with a specified type, some string consts were being quoted.In this PR, I removed the special handling of
const
types, and instead pass every const value throughescStr
.escStr
then passes non-string arguments throughJSON.stringify
.How to Review
Ensure JSON stringification of primitive types is the correct treatment for OpenAPI
const
members, even with notype
specified.I added tests for
string
andnumber
consts with both explicit and implicittype
arguments.const
described? I couldn't find it in the 3.1 spec.true
,false
)Checklist
examples/
directory updated (only applicable for openapi-typescript)