Skip to content
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

Merged

Conversation

baloghbence0915
Copy link
Contributor

@baloghbence0915 baloghbence0915 commented Jul 9, 2024

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

🐛 Bug Fix

⚠️ Pushed to next

🔩 Dependency Updates

Authors: 4

test/valid-data-struct.test.ts Outdated Show resolved Hide resolved
src/NodeParser/TypeLiteralNodeParser.ts Outdated Show resolved Hide resolved
@arthurfiorette arthurfiorette marked this pull request as ready for review July 10, 2024 11:29
test/valid-data-struct.test.ts Outdated Show resolved Hide resolved
// `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;
Copy link
Member

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)?

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@baloghbence0915 baloghbence0915 force-pushed the fix-2017-property-names-resolution branch from 5fb2463 to b1c5743 Compare July 11, 2024 06:51
@arthurfiorette
Copy link
Collaborator

thanks!

@arthurfiorette arthurfiorette changed the title fix: schema generation when property name cannot be escaped (#2017) fix: schema generation when property name cannot be escaped Jul 11, 2024
@domoritz domoritz merged commit b1722e1 into vega:next Jul 11, 2024
4 checks passed
Copy link

🚀 PR was released in v2.4.0-next.1 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema generator fails when nested property name is StringLiteral (kind 11)
3 participants