Open LazaroOnline opened 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)
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
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
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:public string { get; set; }
public Notification(..., string = default(string))
this. = ;
sb.Append(" : ").Append().Append("\n");
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
.