swagger-api / swagger-api/swagger-codegen

Swagger codegen generates a nullable integer as method return value in SDK for operation that returns an integer

Open
#6,872 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Enhancement: General General: Question help wanted
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I have an operation which returns an integer, and when I generate a C# SDK using codegen, the method associated with the operation returns a nullable integer instead of an integer. I tried to set the produced response schema as required using an operation filter and setting the default value as 0 but it had no effect.

Here is the definition of my operation responses:

       "responses":{  
           "200":{  
              "description":"Success",
              "schema":{  
                 "format":"int32",
                 "default":0,
                 "required":[  
                    "200"
                 ],
                 "type":"integer"
              }
           }
        }

Thank you for any insight

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 C# SDK generation in Swagger codegen with the provided response schema, then inspect the generated operation method and the C# generation templates involved. Done means an operation returning a required integer produces a non-nullable integer return value rather than a nullable integer.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.