swagger-api / swagger-api/swagger-codegen

Code Generation of Enum attributes in aspnetcore server omits quotes.

Open
#8,474 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Code Generation of Enum attributes in aspnetcore server omits quotes.

Swagger-codegen version

2.3.1

Swagger declaration file content or url
https://gist.github.com/dpmartin990/d38d14b160998ce0ad780d6b3df3e1b1
Command line used for generation

java -jar swagger-codegen-cli.jar generate -i "C:\Users\dmartin3\Documents\PE\GitHub\Sandbox\MyCode\MyCode\swagger.forservergeneration.json" -l aspnetcore -o "C:\Users\dmartin3\Documents\PE\GitHub\Sandbox\XXXCompany.API.Admin" -D"packageName"="XXXCompany.API.Admin"

(Note I replaced my real company name with this fake one.)

Steps to reproduce

Files were generated as expected, when I opened the solution in VS 2007 latest updates I had to

  1. Remove the project and then re-add it, I see others have used this workaround since the project will not load

  2. Do a search and replace looking for Enum attributes like the below and change them to have quotes, i.e.

         [EnumMember(Value = TypeMismatch)]
         TypeMismatchEnum = 6
    

to this:
[EnumMember(Value = "TypeMismatch")]
TypeMismatchEnum = 6

Related issues/PRs

I could not find any related issues

Suggest a fix/enhancement

I think it should be a simple matter of adding quotes in the code. Not sure quite what's wrong with the project file.

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

Start by reproducing the aspnetcore server generation with the linked Swagger declaration and the documented swagger-codegen command, then inspect the templates responsible for generated enum attributes. Done means generated EnumMember Value attributes contain quoted enum names and the generated project loads without the reported workaround.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.