OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.01k stars 6.6k forks source link

[BUG] [CSharp] Skip model properties in schemas with empty names "" #19419

Open LazaroOnline opened 3 months ago

LazaroOnline commented 3 months ago

Bug Report Checklist

Description

In CSharp code generation, there is a build error in generated code due to model properties with empty names in the schema, like this one "": { "type": "string" } (bad practice, but it is out of my control, I didn't define the json schema, just generating code for it), this would not happen if the code generator just skipped these properties completely.

openapi-generator version

openapi-generator-cli version Did set selected version to 7.8.0

Steps to reproduce
openapi-generator-cli generate -g csharp --skip-validate-spec  -i https://raw.githubusercontent.com/PagerDuty/api-schema/5d679f79622d30b767c777be5f2e9787ef21e092/reference/REST/openapiv3.json

In the code generated, if you open the Notification.cs file, you will find multiple build errors due to the property code missing the name like this:

Suggest a fix

When reading a json schema with empty property names, just show a warning to the console, but skip it during code generation specially when using the flag --skip-validate-spec.

wing328 commented 3 months ago

https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#name-mapping

you may want to try this option to map the empty string to something else (e.g. Unnamed)

LazaroOnline commented 3 months ago

I tried the custom name mappings but it resulted in the same code with the same error.
I guess the mappings only work with actual non-empty names:

Tested with:

openapi-generator-cli generate -g csharp --skip-validate-spec  -i https://raw.githubusercontent.com/PagerDuty/api-schema/5d679f79622d30b767c777be5f2e9787ef21e092/reference/REST/openapiv3.json --name-mappings =MISSINGNAME, --parameter-name-mappings =MISSINGNAMEPROP
openapi-generator-cli generate -g csharp --skip-validate-spec  -i https://raw.githubusercontent.com/PagerDuty/api-schema/5d679f79622d30b767c777be5f2e9787ef21e092/reference/REST/openapiv3.json --name-mappings ""=MISSINGNAME, --parameter-name-mappings ""=MISSINGNAMEPROP