Use the first status code in 2XX range, fallback to 200 (#12637)

This is in line with the OpenAPI specification:

The Responses Object MUST contain at least one response code, and
it SHOULD be the response for a successful operation call.

and excludes the 2XX range response itself.
This commit is contained in:
Tom Bärwinkel 2022-07-06 19:14:32 +02:00 committed by GitHub
parent 728c80abea
commit ac9e595476
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -576,7 +576,16 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
if (returnType.indexOf(" ") >= 0) { if (returnType.indexOf(" ") >= 0) {
returnType = "(" + returnType + ")"; returnType = "(" + returnType + ")";
} }
path.add("Verb '" + op.httpMethod.toUpperCase(Locale.ROOT) + " 200 '[JSON] " + returnType);
String code = "200";
for (CodegenResponse r : op.responses) {
if (r.code.matches("2[0-9][0-9]")) {
code = r.code;
break;
}
}
path.add("Verb '" + op.httpMethod.toUpperCase(Locale.ROOT) + " " + code + " '[JSON] " + returnType);
type.add("m " + returnType); type.add("m " + returnType);
op.vendorExtensions.put("x-route-type", joinStrings(" :> ", path)); op.vendorExtensions.put("x-route-type", joinStrings(" :> ", path));