OpenAPITools / OpenAPITools/openapi-generator

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

Open
#19,419 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • [v] Have you provided a full/minimal spec to reproduce the issue?
  • [v] Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?

Not with master, but with the latest released version in npm.

  • [v] Have you searched for related issues/PRs?
  • [v] What's the actual output vs expected output?
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:

  • 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided openapi-generator-cli command and inspect the generated Notification.cs file for properties with empty names. Trace how the CSharp generator handles schema properties when --skip-validate-spec is used, then verify that empty-name properties are skipped with a warning and that generated code no longer contains the shown build errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.