swagger-api / swagger-api/swagger-codegen

Swagger-codegen generates enumerations whose first value is 1 instead of 0

Open
#7,240 0 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

I am facing an issue with swagge-codegen as I try to generate a c# client SDK regarding the generation of the models for enumerations. Indeed, I have some enumeration definitions in my Open API description, and the model generated from their description has a default value of 1, which is tricky for me because in my web API their default values are 0.

I haven't found the information on how to make the generated enum integer values start from 0, or not be explicitely set (and there for implicitely start from 0).

Swagger-codegen version

2.3.0-SNAPSHOT

Swagger declaration file content or url

Here is a sample of one of my enumeration definitions

"errorCode": {
"enum": [
"OK",
"Error"
],
"type": "string":

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

Use the sample OpenAPI enum with string values OK and Error to reproduce the generated C# model and inspect the C# generation templates or entry points responsible for enum values. Done means the generated enum uses zero-based or implicit integer values consistent with the reported API behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, 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.