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

[BUG][SCALA] Cannot Output Multiple Response Types #6318

Open
1 task
markgarland opened this issue May 15, 2020 · 0 comments
Open
1 task

[BUG][SCALA] Cannot Output Multiple Response Types #6318

markgarland opened this issue May 15, 2020 · 0 comments

Comments

@markgarland
Copy link

markgarland commented May 15, 2020

Bug Report Checklist

  • [Y] Have you provided a full/minimal spec to reproduce the issue?
  • [N] Have you validated the input using an OpenAPI validator (example)?
  • [Y] What's the version of OpenAPI Generator used?
  • [Y] Have you search for related issues/PRs?
  • [Y] What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

We have an endpoint (see yaml below) which has a body defined for a success, but a different body defined for an error response.
However, ApiInvoker expects a Manifest typed on the success response for all cases. The if statement on this case

case Some((manifest, state: ResponseState)) if manifest == mf =>
checks for this. If it doesn't match (as in our error case) it then ends up in this case (
Future.failed(ApiError(response.status.intValue, "Unexpected response code", Some(response.entity.toString)))
) and you get the ConfigServiceError as a string (which isn't what you need).
A workaround is to use asInstanceOf to change the ApiRequest to be typed on the error type, but that isn't practical outside of testing.

openapi-generator version

4.3.0

OpenAPI declaration file content or url
openapi: '3.0.0'
paths:
  /api/v1/config/revision:
    post:
      summary: Add a revision
      description: Add a revision of configuration without applying it
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RevisionRequest'
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RevisionResponse'
        '400':
          description: BadRequest
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConfigServiceError'
      security:
        - bearerAuth: []
      tags:
        - config
components:
  schemas:
    ConfigServiceError:
      description: A config service error
      type: object
      required:
        - type
      properties:
        type:
          type: string
        errors:
          type: array
          items:
            type: string
          description: The errors
Command line used for generation

Scala, openapi-generator(4.3.0) (but code affected same in master)
sbt clean openapiGenerate

Steps to reproduce

Use an ApiInvoker typed on the success response in an error scenario, and try to unmarshall the error response.

Related issues/PRs

#1096
#316
#3377

Suggest a fix

Have the ApiInvoker and internal map take multiple types? Type the ApiResponse with multiple types (success/failure)? Remove/amend the if from the case statement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant