OpenAPITools / OpenAPITools/openapi-generator

[BUG][C#][API client: csharp] Integer Enumeration produce same code as String Enumeration

Open
#4,395 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When generatin API client for C#. the code for Integer Enumerator produce have the same properties as if it was a String Enumerator.

openapi-generator version

4.2.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: "1"
  title: BUG Report
paths:
  /Create:
    put:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/new_item'
      responses:
        default:
          description:  return
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/new_item'
components:
  schemas:
    new_item:
      properties:
        class:
          type: string
          enum:
            - high
            - low
        size:
          type: integer
          format: int8
          enum:
            - 2
            - 4
            - 8
Command line used for generation

java -jar openapi-generator-cli.jar generate -i my.yaml -g csharp

Steps to reproduce

Just run the command and compare JSON attribute of "enum ClassEnum" and "enum SizeEnum" at src/Org.OpenAPITools/Model/NewItem.cs

Related issues/PRs

Resamble but more simple then:
https://github.com/OpenAPITools/openapi-generator/issues/3246

Suggest a fix

The JSON attribute "[JsonConverter(typeof(StringEnumConverter))]" should be used on string Enomurators,
but should be omit in case of Integer Enomurators.

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 generating the C# client with the provided OpenAPI YAML and command, then compare the enum declarations in src/Org.OpenAPITools/Model/NewItem.cs. Check the JSON attributes on ClassEnum and SizeEnum; done means string enums retain StringEnumConverter while integer enums do not.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, 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.