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] Haskell-http-client gives empty responses a polymorphic return type in some cases #9901

Closed
5 of 6 tasks
ivanbakel opened this issue Jul 6, 2021 · 0 comments · Fixed by #9916
Closed
5 of 6 tasks
Assignees

Comments

@ivanbakel
Copy link
Contributor

ivanbakel commented Jul 6, 2021

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists? (Tested with the 6.0.0-SNAPSHOT)
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When using the Haskell-http-client generator, certain response configurations will cause the generator to produce a request type with a polymorphic type variable and incorrect MIME type for the success case.

Specifically, if

  1. The success (200) response has no schema, so that it does not return any content, and
  2. Some error (e.g. 500) response has some schema, which returns content, and
  3. produces is set for the request configuration so that the request has a MIME type configured for its responses

Then the generated request type should have no MIME type and produce no content as a response, because that is what happens in the success branch. Instead, the request type will return a polymorphic response type (represented by the res type variable), using the MIME type set for produces - even though that MIME type cannot be used to decode the success response, because it is empty.

This is an issue, because successful requests will error on decoding when the generated code expects some content in the response body.

openapi-generator version

5.1.1

OpenAPI declaration file content or url
---

swagger: '2.0'

info:
  version: 0.0.1
  title: Test API
  description: Test API
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html

consumes:
  - "application/json"
produces:
  - "application/json"

paths:
  /status:
    post:
      tags:
        - general
      operationId: getFoo 
      description: Get foo
      responses:
        '200':
          description: Get foo
        '500':
          description: Error
          schema:
            type: string 

Generation Details
openapi-generator generate -i test.yaml -g haskell-http-client -o test-haskell/
Steps to reproduce
  1. Save the above YAML as test.yaml.
  2. Run the above generator command.
  3. Open ./test-haskell/lib/Test/API/General.hs
  4. See that getFoo has the type TestRequest GetFoo MimeNoContent res MimeJSON, despite the fact that the success case does not return any content - when the expected type is TestRequest GetFoo MimeNoContent NoContent MimeNoContent.
Related issues/PRs

Seems very related to #9830, which touches a similar line in the Haskell-servant generator to the line in Haskell-http-client which makes the return type polymorphic.

Suggest a fix

Based on the above PR, it might be correct to make a similar change to the Haskell-http-client generator, and set it to return NoContent with the MimeNoContent MIME-type when there's no return type, rather than use the polymorphic res type. But I'm not confident that this would be the right fix.

ivanbakel added a commit to ivanbakel/openapi-generator that referenced this issue Jul 8, 2021
Relevant issue: OpenAPITools#9901

The haskell-http-client generator tries to generate a polymorphic return
type for endpoints which don't return anything in the success case, but
still produce content in other cases. This means that these endpoints
hit a decoding error in the success case, because there is no content to
decode.

This changes the behaviour so that endpoints that don't return anything
are *always* generated as returning NoContent, and never try to decode
the response. This change is based on a similar one for the
haskell-servant generator, which can be found at:

OpenAPITools#9830

which resolved a similar issue for that generator.
@jonschoning jonschoning self-assigned this Jul 14, 2021
jonschoning pushed a commit that referenced this issue Jul 15, 2021
…ield NoContent (#9916)

* Make endpoints which don't return anything yield NoContent

Relevant issue: #9901

The haskell-http-client generator tries to generate a polymorphic return
type for endpoints which don't return anything in the success case, but
still produce content in other cases. This means that these endpoints
hit a decoding error in the success case, because there is no content to
decode.

This changes the behaviour so that endpoints that don't return anything
are *always* generated as returning NoContent, and never try to decode
the response. This change is based on a similar one for the
haskell-servant generator, which can be found at:

#9830

which resolved a similar issue for that generator.

* Update samples after haskell-http-client NoContent change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants