swagger-api / swagger-api/swagger-codegen

[C#] Invalid C# enum generated when allOf is used

Open
#8,234 0 comments 0 reactions 1 assignee View on GitHub

@HugoMario is already working on this.

Since May 12, 2020.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

We're composing a model with allOf. It has a string enum as one of the properties. The C# code generated by swagger-codegen does not compile. If I remove allOf and explicitly describe the data model, the enum is generated correctly.

Swagger-codegen version

2.3.1

Swagger declaration file content or url

For this json definition, which uses allOf, the generated enum for ActivityType in the Models namespace is not valid C#.

This json file, without allOf, will generate the correct enum.

Command line used for generation

swagger-codegen generate -i ./bad_enum.json -l csharp -o ./output_bad/

Steps to reproduce
  1. Run the example command against the bad_enum.json from the gist linked above.
  2. Observe that the ActivityType.cs file defines an invalid enum with circular references.
  3. Run the example command agains the good_enum.json from the other gist linked above.
  4. Observe the correctly defined enum in ActivityType.cs for this output.
Related issues/PRs

Similar to #3338, although in my case the generator is able to output code, but the code will not compile.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.