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

Wildcard in http response code #199

Open
jmini opened this issue Jun 1, 2018 · 0 comments
Open

Wildcard in http response code #199

jmini opened this issue Jun 1, 2018 · 0 comments

Comments

@jmini
Copy link
Member

jmini commented Jun 1, 2018

Given this OAS3 spec:

openapi: 3.0.1
info:
  title: OpenAPI Example
  description: Example spec
  version: 1.0.0
servers:
  - url: 'http://api.company.xyz/v2'
paths:
  /lorem/ping:
    get:
      operationId: op
      tags:
        - lorem
      responses:
        '200':
          description: a pet to be returned
          content: 
            application/json:
              schema:
                $ref: '#/components/schemas/SomeObject'
        default:
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorModel'
components:
  schemas:
    SomeObject:
      type: object
      properties:
        id:
          type: integer
          format: int32
        firstName:
          type: string
        lastName:
          type: string

    ErrorModel:
      type: object
      properties:
        statusCode:
          type: integer
          description: http status code
          format: int32
        statusDescription:
          type: string
          description: http status reason phrase
        errorMessage:
          type: string
          description: error description

Inspired by the example from the Responses Object Example section in the official OpenAPI Specification.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#responses-object-example

Related topic: it is now possible to work with 2xx as http status (a wildcard that represent an http status in the 200 - 299 range)

The generated code for jaxrs (jersey2 library) looks wrong:

    @GET
    @Path("/issue")
    
    @Produces({ "application/json" })
    @io.swagger.annotations.ApiOperation(value = "", notes = "", response = SomeObject.class, tags={ "ipsum", })
    @io.swagger.annotations.ApiResponses(value = { 
        @io.swagger.annotations.ApiResponse(code = 200, message = "a pet to be returned", response = SomeObject.class),
        
        @io.swagger.annotations.ApiResponse(code = 200, message = "Unexpected error", response = ErrorModel.class) })
    public Response op(@Context SecurityContext securityContext)
    throws NotFoundException {
        return delegate.op(securityContext);
    }

First point: Is the "default" http status supported by CodegenResponse (and other wildcard like "3xx" that seems to be new with OAS3).

Other problem for JaxRS: @io.swagger.annotations.ApiResponse expect an int for the code.
We might need to update to Swagger core v3 first (see issue #27), because the @io.swagger.v3.oas.annotations.responses.ApiResponse annotation in the v3 core has a String responseCode member.

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

No branches or pull requests

1 participant