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

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

Open
devplayer0 opened this issue Jun 11, 2018 · 0 comments · May be fixed by #99
Open

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

devplayer0 opened this issue Jun 11, 2018 · 0 comments · May be fixed by #99

Comments

@devplayer0
Copy link
Contributor

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: [email protected]
    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.

devplayer0 added a commit to devplayer0/swagger-codegen-generators that referenced this issue Jun 12, 2018
This makes the behaviour of `fromRequestBody()` similar to that of
`fromParameter()` (by replacing most of the existing code with code
from `fromParameter()`) in order to fix a number of issues. Notably this
includes a lack of handling for enums, both as references (as can be
seen in swagger-api#95) and inline.

Also:
 - Add `postProcessRequestBody()` hook for code generators
 - Fix swagger-api#95
@devplayer0 devplayer0 linked a pull request Jun 12, 2018 that will close this issue
devplayer0 added a commit to devplayer0/swagger-codegen-generators that referenced this issue Jun 15, 2018
This makes the behaviour of `fromRequestBody()` similar to that of
`fromParameter()` (by replacing most of the existing code with code
from `fromParameter()`) in order to fix a number of issues. Notably this
includes a lack of handling for enums, both as references (as can be
seen in swagger-api#95) and inline.

Also:
 - Add `postProcessRequestBody()` hook for code generators
 - Fix swagger-api#95
devplayer0 added a commit to devplayer0/swagger-codegen-generators that referenced this issue Jun 29, 2018
This makes the behaviour of `fromRequestBody()` similar to that of
`fromParameter()` (by replacing most of the existing code with code
from `fromParameter()`) in order to fix a number of issues. Notably this
includes a lack of handling for enums, both as references (as can be
seen in swagger-api#95) and inline.

Also:
 - Add `postProcessRequestBody()` hook for code generators
 - Fix swagger-api#95
devplayer0 added a commit to devplayer0/swagger-codegen-generators that referenced this issue Jul 4, 2018
This makes the behaviour of `fromRequestBody()` similar to that of
`fromParameter()` (by replacing most of the existing code with code
from `fromParameter()`) in order to fix a number of issues. Notably this
includes a lack of handling for enums, both as references (as can be
seen in swagger-api#95) and inline.

Also:
 - Add `postProcessRequestBody()` hook for code generators
 - Fix swagger-api#95
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