PropertyNameGenerator: add passing and failing tests demonstrating issue with CodeGeneration #4711
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.
As mentioned here: #1874 (comment)
I've identified an issue with the TypeScript code generation of clients when using the
PropertyNameGenerator
property to control naming.Essentially, when using
TypeScriptTypeStyle.Class
this is respected. When usingTypeScriptTypeStyle.Interface
it is ignored. This is illustrated by the enclosing tests, one of which fails; demonstrating the issue.I'd love to help get this fixed and I figured this was a first step!
I've also added a C# test as well as I thought it'd be useful for coverage.
With the following
CustomPropertyNameGenerator
we can demostrate the issue.If this is working as expected, all property names should be prefixed with
XX_
:But if using
TypeScriptTypeStyle.Interface
it is ignored and instead this is generated:Ideally the
CustomPropertyNameGenerator
should always be in play.Having had a dig through the code I wonder if the issue lies in NJsonSchema somewhere:
https://github.com/RicoSuter/NJsonSchema/blob/master/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptTypeResolver.cs
https://github.com/RicoSuter/NJsonSchema/blob/3585d60e949e43284601e0bea16c33de4c6c21f5/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptGeneratorSettings.cs#L36