Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated interface, contains string instead of enum in case of POST request #1896

Closed
matadini opened this issue Dec 2, 2024 · 0 comments · Fixed by #1913
Closed

Generated interface, contains string instead of enum in case of POST request #1896

matadini opened this issue Dec 2, 2024 · 0 comments · Fixed by #1913

Comments

@matadini
Copy link

matadini commented Dec 2, 2024

Expected Behavior

As a user, I want to generate a POST method declaration for the controller based on the OpenAPI yml file, where the request body is of enum type.

Actual Behaviour

The generated interface contains a variable of type String instead of the expected enum.

Steps To Reproduce

  1. Setup standard simple micronaut application with OpenAPI yml file.
  2. Declare simple endpoints:
  /api/v1/colors:
    get:
      tags: [ my-custom ]
      operationId: "getSelectedColor"
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Color'
    post:
      tags: [ my-custom ]
      operationId: "selectColor"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Color"
      responses:
        "200":
          description: "OK"
  1. Enum component declaration:
    Color:
      type: string
      enum:
        - GREEN
        - RED
        - WHITE
  1. Generated interface looks like this:
    /**
     * getSelectedColor
     *
     * @return OK (status code 200)
     */
    @Get("/api/v1/colors")
    Color getSelectedColor();

    /**
     * selectColor
     *
     * @param body (required)
     */
    @Post("/api/v1/colors")
    void selectColor(
        @Body @NotNull String body
    );

For the GET method, everything is fine, but for the POST method, the variable is a string. Is it possible to achieve an enum type as a result of the generation? If this is not a bug, please let me know what I am doing wrong.

Environment Information

  • OpenSUSE Tumbleweed
  • JDK21
  • Micronaut 4.7.1
  • Micronaut Gradle Plugin: 4.4.4

Example Application

https://github.com/matadini/openapi-micronaut-string-instead-enum

Version

4.7.0

altro3 added a commit to altro3/micronaut-openapi that referenced this issue Dec 6, 2024
altro3 added a commit to altro3/micronaut-openapi that referenced this issue Dec 15, 2024
altro3 added a commit to altro3/micronaut-openapi that referenced this issue Dec 15, 2024
altro3 added a commit to altro3/micronaut-openapi that referenced this issue Dec 15, 2024
altro3 added a commit to altro3/micronaut-openapi that referenced this issue Dec 15, 2024
altro3 added a commit to altro3/micronaut-openapi that referenced this issue Dec 18, 2024
altro3 added a commit to altro3/micronaut-openapi that referenced this issue Dec 18, 2024
altro3 added a commit to altro3/micronaut-openapi that referenced this issue Dec 18, 2024
altro3 added a commit to altro3/micronaut-openapi that referenced this issue Dec 18, 2024
@altro3 altro3 closed this as completed in e86e456 Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant