-
Notifications
You must be signed in to change notification settings - Fork 195
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
fix: schema generation when property name cannot be escaped #2018
fix: schema generation when property name cannot be escaped #2018
Conversation
bf9616f
to
d4faecd
Compare
// `escapedText` or `text` is available. | ||
// Only `text` will be available when propertyName contains strange characters and it cannot be escaped | ||
// or if it is a number. | ||
return ((propertyName as ts.Identifier).escapedText as string) || (propertyName as ts.StringLiteral).text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use ?? Instead so that it doesn't fall through for empty strings (if that's possible)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, hey @baloghbence0915 can you test this out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Weirdly both TS and JS allows empty strings as property names.
Regardless, in such a case escapedText
won't be available at all and will fall back to text
, altough I aggree with the general approach of trusting escapedText
if it present so changed OR to nullish coalescing (??) operator.
Also extended the testing with this case.
5fb2463
to
b1c5743
Compare
thanks! |
🚀 PR was released in |
Fixes: #2017
Conclusion:
After deeper insight, the described issue only occured, in case of nested properties and when the property doesn't have explict type definition and it's key is a string literal that cannot be escaped or a number.
By that, it didn't impact interfaces since they are explicit type definitions themselves, but unit test was provided for class and interface anyway.
Version
Published prerelease version:
v2.4.0-next.1
Changelog
🎉 This release contains work from a new contributor! 🎉
Thank you, Bence Balogh (@baloghbence0915), for all your work!
🚀 Enhancement
--expose all
with generic types #2009 (@arthurfiorette)🐛 Bug Fix
next
🔩 Dependency Updates
Authors: 4