swagger-api / swagger-api/swagger-codegen

[C#] Warning CS0472 for "required" enum parameters

Open
#8,519 1 comment 3 reactions 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

When marking an enum parameter as required, i am getting the following warning:

warning CS0472: The result of the expression is always 'false' since a value of type 'Order.IdEnum' is never equal to 'null' of type 'Order.IdEnum?'
Swagger-codegen version

It is happening with latest master branch (dbd0a4bb535de0d587c9ccec1465a25c8288ee96).

Swagger declaration file content or url

Here is a simplified code to reproduce the issue:

definitions:
  Order:
    type: "object"
    required:
      - id
    properties:
      id:
        type: "string"
        enum:
          - Value
Command line used for generation

java -jar modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i c:\temp\cs_warning.yaml -l csharp -o c:\temp\out

Steps to reproduce

Generate C# code with the above yaml code and compile the generated code.

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 with the simplified YAML definition and run the documented swagger-codegen CLI command with the csharp generator. Inspect the generated C# for the required enum parameter and the nullable comparison that produces CS0472. Done means the generated code compiles without that warning for the reproduction case.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.