Skip to content

Conversation

WolfgangHG
Copy link
Contributor

This is the second attempt to fix RicoSuter/NSwag#4849 and RicoSuter/NSwag#4837 and a followup for #1716: since NSwag 14, the resulting C# file generated from a yaml file might contain lower case class names.
This seems to happen if an array item has as lower case type name hint (e.g. "data"), and a class "Data" was already generated.
In this situation, DefaultTypeNameGenerator.GenerateAnonymousTypeName does not call ConversionUtilities.ConvertToUpperCamelCase and thus picks the lower case class name "data" as "not used".

With my fix, it would generate a class "Data2" again.

The first fix worked locally for me because I had one additional line that I forget to add to my pull request. This request adds this line and removes an unneccesary ConvertToUpperCamelCase from the previous pull request (variable typeNameHint is already camel cased now).

Sorry for the confusion, I had some problems building/running NSwag/NJsonSchema and first added workaround code to my local NSwag copy, then applied it to NJsonSchema, where I lost one important line. But this time I really tested a fixed "NJsonSchema.dll" with NSwag console and can confirm that the generated cs file is valid ;-).

@RicoSuter RicoSuter merged commit f22ecff into RicoSuter:master Apr 28, 2025
2 checks passed
@RicoSuter
Copy link
Owner

Thanks for the PR.
Would be good to have a follow-up PR with some unit tests to avoid regressions in the future.

@WolfgangHG
Copy link
Contributor Author

@RicoSuter I know, a test would be appropriate But I ran into this issue when consuming a closed source api description, and I don't have enough OpenApi knowledge to build a sample file myself.

@RicoSuter
Copy link
Owner

image

doesnt seem to work correctly...
https://github.com/RicoSuter/NSwag/pull/5161/files

Seems that i need to revert.

@WolfgangHG
Copy link
Contributor Author

@RicoSuter According to your diff screenshot, the right side of the code is the expected behaviour, as it eliminates the lower case class names. Or did I have a misunderstanding?

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

Successfully merging this pull request may close these issues.

Generated class names cause compiler warning.
2 participants