swagger-api / swagger-api/swagger-codegen

[JAVA SPRING] Error type generated for enum integer type.

Open
#5,177 1 comment 0 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

integer type should generate integer output instead of string.

Swagger-codegen version

2.2.2

Swagger declaration file content or url
definitions:
  BaseModel:
    discriminator: baseModelType
    properties:
      code:
        type: integer
        format: int32
        default: 0
        enum: [0, 1]
        description:  0 normal, 1 error.
    required:
      - code
      - baseModelType
Command line used for generation

-l spring --library spring-mvc

Generated Java Model

public class BaseModel   {
  /**
   * 0 normal, 1 error.
   */
  public enum CodeEnum {
    NUMBER_0(0),
    
    NUMBER_1(1);

    private Integer value;

    CodeEnum(Integer value) {
      this.value = value;
    }

    @Override
    @JsonValue
    public String toString() {
      return String.valueOf(value);
    }

which output string json value instead of integer:

{
  "code": "0"
}

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

Reproduce the issue with the supplied YAML and the command -l spring --library spring-mvc, then inspect the generated BaseModel.CodeEnum shown in the report. Done means the enum's JSON output is numeric, producing {"code": 0} rather than a quoted string.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
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.