swagger-api / swagger-api/swagger-codegen-generators

Incorrect dataType output when using a $ref to an enum as the schema in the requestBody

Open
#95 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

The snippet below from an OpenAPI document shows a parameter in path and request body whose schemas are both references to an enum StuffType:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
  termsOfService: http://swagger.io/terms/
  contact:
    name: Swagger API Team
    email: apiteam@swagger.io
    url: http://swagger.io
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: http://petstore.swagger.io/api
paths:
  /stuff/{stuffType}:
    post:
      tags:
        - 'stuff'
      description: "Do some stuff"
      operationId: "doStuff"
      parameters:
        - name: "stuffType"
          in: "path"
          required: true
          schema:
            $ref: '#/components/schemas/StuffType'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StuffType'
      responses:
        '200':
          description: 'A response'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StuffType'
components:
  schemas:
    StuffType:
      type: string
      enum:
        - A_1
        - B_1
        - D_2

This is the method generated by jaxrs-spec:

@POST
@Path("/{stuffType}")
@ApiOperation(value = "", notes = "Do some stuff", response = StuffType.class, tags={ "stuff" })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "A response", response = StuffType.class)
})
public Response doStuff(@PathParam("stuffType") StuffType stuffType,@Valid String body) {
    return Response.ok().entity("magic!").build();
}

While the generated method uses StuffType as the type for the path parameter, String is used as the type for body.

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 in the jaxrs-spec generation path that resolves requestBody schemas, comparing it with the existing path-parameter handling for the same $ref enum. Use the supplied OpenAPI document and inspect the generated method; done means the request body is generated as StuffType rather than String.

Written by the indexing model from the issue text.

Assessment

Domain
api, 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.