Skip to content

Commit 057c108

Browse files
authored
[Codegen] Add hasDefaultResponse property (#9203)
Check if there's a default response in the specs.
1 parent 83adc06 commit 057c108

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class CodegenOperation {
2929
isArray, isMultipart,
3030
isResponseBinary = false, isResponseFile = false, hasReference = false,
3131
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
32-
isRestful, isDeprecated, isCallbackRequest, uniqueItems;
32+
isRestful, isDeprecated, isCallbackRequest, uniqueItems, hasDefaultResponse = false;
3333
public String path, operationId, returnType, returnFormat, httpMethod, returnBaseType,
3434
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse;
3535
public CodegenDiscriminator discriminator;
@@ -168,6 +168,15 @@ public boolean getHasExamples() {
168168
return nonempty(examples);
169169
}
170170

171+
/**
172+
* Check if there's a default response
173+
*
174+
* @return true if responses contain a default response, false otherwise
175+
*/
176+
public boolean getHasDefaultResponse() {
177+
return responses.stream().filter(response -> response.isDefault).findFirst().isPresent();
178+
}
179+
171180
/**
172181
* Check if act as Restful index method
173182
*
@@ -270,6 +279,7 @@ public String toString() {
270279
sb.append(", isResponseBinary=").append(isResponseBinary);
271280
sb.append(", isResponseFile=").append(isResponseFile);
272281
sb.append(", hasReference=").append(hasReference);
282+
sb.append(", hasDefaultResponse=").append(hasDefaultResponse);
273283
sb.append(", isRestfulIndex=").append(isRestfulIndex);
274284
sb.append(", isRestfulShow=").append(isRestfulShow);
275285
sb.append(", isRestfulCreate=").append(isRestfulCreate);
@@ -343,6 +353,7 @@ public boolean equals(Object o) {
343353
isResponseBinary == that.isResponseBinary &&
344354
isResponseFile == that.isResponseFile &&
345355
hasReference == that.hasReference &&
356+
hasDefaultResponse == that.hasDefaultResponse &&
346357
isRestfulIndex == that.isRestfulIndex &&
347358
isRestfulShow == that.isRestfulShow &&
348359
isRestfulCreate == that.isRestfulCreate &&
@@ -400,7 +411,7 @@ public int hashCode() {
400411

401412
return Objects.hash(responseHeaders, hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams,
402413
hasRequiredParams, returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMap,
403-
isArray, isMultipart, isResponseBinary, isResponseFile, hasReference, isRestfulIndex,
414+
isArray, isMultipart, isResponseBinary, isResponseFile, hasReference, hasDefaultResponse, isRestfulIndex,
404415
isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy, isRestful, isDeprecated,
405416
isCallbackRequest, uniqueItems, path, operationId, returnType, httpMethod, returnBaseType,
406417
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse, discriminator, consumes,

0 commit comments

Comments
 (0)