[BUG] Haskell-http-client gives empty responses a polymorphic return type in some cases
Created by: ivanbakel
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
- The success (
200
) response has no schema, so that it does not return any content, and - Some error (e.g.
500
) response has some schema, which returns content, and -
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
- Save the above YAML as
test.yaml
. - Run the above generator command.
- Open
./test-haskell/lib/Test/API/General.hs
- See that
getFoo
has the typeTestRequest GetFoo MimeNoContent res MimeJSON
, despite the fact that the success case does not return any content - when the expected type isTestRequest GetFoo MimeNoContent NoContent MimeNoContent
.
Related issues/PRs
Seems very related to https://github.com/OpenAPITools/openapi-generator/pull/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.