Describe the bug
- Have an OpenAPI specification with an endpoint returning
NoContent
- Generate the request for this endpoint
- The request fails
To Reproduce
- Have this OpenAPI specification
{
"openapi": "3.0.0",
"info": {
"title": "NoContent issue",
"version": "0.1"
},
"paths": {
"/empty": {
"post": {
"responses": {
"204": {
"description": "Returns nothing"
}
}
}
}
}
}
- Run the generator, and obtain
empty config =
Http.request
{ url = Url.Builder.absolute [ "empty" ] []
, method = "POST"
, headers = []
, expect =
OpenApi.Common.expectJsonCustom
config.toMsg
(Dict.fromList [])
(Json.Decode.succeed ())
, body = Http.emptyBody
, timeout = Nothing
, tracker = Nothing
}
- Run the
empty request
- Obtain a failure.
When matching on the failure type, the error is a OpenApi.Common.BadBody (also generated). The underlying reason is that the generated OpenApi.Common.expectJsonCustom does this in the good case:
Http.GoodStatus_ httpMetadata body ->
case Json.Decode.decodeString successDecoder body of
The issue is that for NoContent the call Json.Decode.decodeString successDecoder body tries to decode the case where body is the empty string. Since the empty string is not valid JSON, the decoding fails.
One possible solution is to check the httpMetadata.statusCode to specifically handle the 204 case differently.
Describe the bug
NoContentTo Reproduce
{ "openapi": "3.0.0", "info": { "title": "NoContent issue", "version": "0.1" }, "paths": { "/empty": { "post": { "responses": { "204": { "description": "Returns nothing" } } } } } }emptyrequestWhen matching on the failure type, the error is a
OpenApi.Common.BadBody(also generated). The underlying reason is that the generatedOpenApi.Common.expectJsonCustomdoes this in the good case:The issue is that for
NoContentthe callJson.Decode.decodeString successDecoder bodytries to decode the case wherebodyis the empty string. Since the empty string is not valid JSON, the decoding fails.One possible solution is to check the
httpMetadata.statusCodeto specifically handle the204case differently.