Skip to content

Commit

Permalink
Haskell-http-generator - Make endpoints which don't return anything y…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ivanbakel committed Jul 15, 2021
1 parent 79866e9 commit 65a271c
Show file tree
Hide file tree
Showing 22 changed files with 1,395 additions and 1,381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -879,15 +879,8 @@ public boolean isDataTypeBinary(final String dataType) {
private void processReturnType(CodegenOperation op) {
String returnType = op.returnType;
if (returnType == null || returnType.equals("null")) {
if (op.hasProduces) {
returnType = "res";
op.vendorExtensions.put(VENDOR_EXTENSION_X_HAS_UNKNOWN_RETURN, true);
} else {
returnType = "NoContent";
if (!op.vendorExtensions.containsKey(VENDOR_EXTENSION_X_INLINE_ACCEPT)) {
SetNoContent(op, VENDOR_EXTENSION_X_INLINE_ACCEPT);
}
}
returnType = "NoContent";
SetNoContent(op, VENDOR_EXTENSION_X_INLINE_ACCEPT);
}
if (returnType.contains(" ")) {
returnType = "(" + returnType + ")";
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,12 @@ ParamBodyMultipartFormData :: [Part] -> ParamBody
_mkRequest :: Method -> [ByteString] -> OpenAPIPetstoreRequest req contentType res accept
_mkParams :: Params
setHeader :: OpenAPIPetstoreRequest req contentType res accept -> [Header] -> OpenAPIPetstoreRequest req contentType res accept
addHeader :: OpenAPIPetstoreRequest req contentType res accept -> [Header] -> OpenAPIPetstoreRequest req contentType res accept
removeHeader :: OpenAPIPetstoreRequest req contentType res accept -> [HeaderName] -> OpenAPIPetstoreRequest req contentType res accept
_setContentTypeHeader :: forall req contentType res accept. MimeType contentType => OpenAPIPetstoreRequest req contentType res accept -> OpenAPIPetstoreRequest req contentType res accept
_setAcceptHeader :: forall req contentType res accept. MimeType accept => OpenAPIPetstoreRequest req contentType res accept -> OpenAPIPetstoreRequest req contentType res accept
setQuery :: OpenAPIPetstoreRequest req contentType res accept -> [QueryItem] -> OpenAPIPetstoreRequest req contentType res accept
addQuery :: OpenAPIPetstoreRequest req contentType res accept -> [QueryItem] -> OpenAPIPetstoreRequest req contentType res accept
addForm :: OpenAPIPetstoreRequest req contentType res accept -> Form -> OpenAPIPetstoreRequest req contentType res accept
_addMultiFormPart :: OpenAPIPetstoreRequest req contentType res accept -> Part -> OpenAPIPetstoreRequest req contentType res accept
_setBodyBS :: OpenAPIPetstoreRequest req contentType res accept -> ByteString -> OpenAPIPetstoreRequest req contentType res accept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
</span><a name="line-69"></a><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><a href="OpenAPIPetstore.MimeTypes.html#Consumes"><span class="hs-identifier hs-type">Consumes</span></a><span> </span><a href="OpenAPIPetstore.API.AnotherFake.html#Op123testSpecialTags"><span class="hs-identifier hs-type">Op123testSpecialTags</span></a><span> </span><a href="OpenAPIPetstore.MimeTypes.html#MimeJSON"><span class="hs-identifier hs-type">MimeJSON</span></a><span class="hs-special">,</span><span> </span><a href="OpenAPIPetstore.MimeTypes.html#MimeRender"><span class="hs-identifier hs-type">MimeRender</span></a><span> </span><a href="OpenAPIPetstore.MimeTypes.html#MimeJSON"><span class="hs-identifier hs-type">MimeJSON</span></a><span> </span><a href="OpenAPIPetstore.Model.html#Client"><span class="hs-identifier hs-type">Client</span></a><span class="hs-special">)</span><span>
</span><a name="line-70"></a><span> </span><span class="hs-glyph">=&gt;</span><span> </span><a href="OpenAPIPetstore.Model.html#Client"><span class="hs-identifier hs-type">Client</span></a><span> </span><span class="hs-comment">-- ^ &quot;body&quot; - client model</span><span>
</span><a name="line-71"></a><span> </span><span class="hs-glyph">-&gt;</span><span> </span><a href="OpenAPIPetstore.Core.html#OpenAPIPetstoreRequest"><span class="hs-identifier hs-type">OpenAPIPetstoreRequest</span></a><span> </span><a href="OpenAPIPetstore.API.AnotherFake.html#Op123testSpecialTags"><span class="hs-identifier hs-type">Op123testSpecialTags</span></a><span> </span><a href="OpenAPIPetstore.MimeTypes.html#MimeJSON"><span class="hs-identifier hs-type">MimeJSON</span></a><span> </span><a href="OpenAPIPetstore.Model.html#Client"><span class="hs-identifier hs-type">Client</span></a><span> </span><a href="OpenAPIPetstore.MimeTypes.html#MimeJSON"><span class="hs-identifier hs-type">MimeJSON</span></a><span>
</span><a name="line-72"></a><a name="op123testSpecialTags"><a href="OpenAPIPetstore.API.AnotherFake.html#op123testSpecialTags"><span class="hs-identifier">op123testSpecialTags</span></a></a><span> </span><a name="local-6989586621679189378"><a href="#local-6989586621679189378"><span class="hs-identifier">body</span></a></a><span> </span><span class="hs-glyph">=</span><span>
</span><a name="line-72"></a><a name="op123testSpecialTags"><a href="OpenAPIPetstore.API.AnotherFake.html#op123testSpecialTags"><span class="hs-identifier">op123testSpecialTags</span></a></a><span> </span><a name="local-6989586621679189127"><a href="#local-6989586621679189127"><span class="hs-identifier">body</span></a></a><span> </span><span class="hs-glyph">=</span><span>
</span><a name="line-73"></a><span> </span><a href="OpenAPIPetstore.Core.html#_mkRequest"><span class="hs-identifier hs-var">_mkRequest</span></a><span> </span><span class="hs-string">&quot;PATCH&quot;</span><span> </span><span class="hs-special">[</span><span class="hs-string">&quot;/another-fake/dummy&quot;</span><span class="hs-special">]</span><span>
</span><a name="line-74"></a><span> </span><span class="hs-special">`</span><a href="OpenAPIPetstore.Core.html#setBodyParam"><span class="hs-identifier hs-var">setBodyParam</span></a><span class="hs-special">`</span><span> </span><a href="#local-6989586621679189378"><span class="hs-identifier hs-var">body</span></a><span>
</span><a name="line-74"></a><span> </span><span class="hs-special">`</span><a href="OpenAPIPetstore.Core.html#setBodyParam"><span class="hs-identifier hs-var">setBodyParam</span></a><span class="hs-special">`</span><span> </span><a href="#local-6989586621679189127"><span class="hs-identifier hs-var">body</span></a><span>
</span><a name="line-75"></a><span>
</span><a name="line-76"></a><span class="hs-keyword">data</span><span> </span><a name="Op123testSpecialTags"><a href="OpenAPIPetstore.API.AnotherFake.html#Op123testSpecialTags"><span class="hs-identifier">Op123testSpecialTags</span></a></a><span>
</span><a name="line-77"></a><span>
Expand Down
Loading

0 comments on commit 65a271c

Please sign in to comment.