You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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.1title: Test APIdescription: Test APIlicense:
name: Apache 2.0url: http://www.apache.org/licenses/LICENSE-2.0.htmlconsumes:
- "application/json"produces:
- "application/json"paths:
/status:
post:
tags:
- generaloperationId: getFoo description: Get fooresponses:
'200':
description: Get foo'500':
description: Errorschema:
type: string
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.
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.
The text was updated successfully, but these errors were encountered:
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.
…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
Bug Report Checklist
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
200
) response has no schema, so that it does not return any content, and500
) response has some schema, which returns content, andproduces
is set for the request configuration so that the request has a MIME type configured for its responsesThen 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 forproduces
- 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
Generation Details
Steps to reproduce
test.yaml
../test-haskell/lib/Test/API/General.hs
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 #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 theMimeNoContent
MIME-type when there's no return type, rather than use the polymorphicres
type. But I'm not confident that this would be the right fix.The text was updated successfully, but these errors were encountered: