Skip to content

Commit 5117616

Browse files
authored
CodegenOperation & CodegenProperty: turn fields into getters (#21225)
* turn fields into getters * update samples
1 parent 5e5a053 commit 5117616

File tree

10 files changed

+30
-84
lines changed

10 files changed

+30
-84
lines changed

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

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424

2525
public class CodegenOperation {
2626
public final List<CodegenProperty> responseHeaders = new ArrayList<CodegenProperty>();
27-
public boolean hasAuthMethods, hasConsumes, hasProduces, hasOptionalParams, hasRequiredParams,
27+
public boolean hasAuthMethods, hasConsumes, hasProduces, hasOptionalParams,
2828
returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMap,
2929
isArray, isMultipart, isVoid = false,
3030
hasVersionHeaders = false, hasVersionQueryParams = false,
3131
isResponseBinary = false, isResponseFile = false, isResponseOptional = false, hasReference = false, defaultReturnType = false,
32-
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
33-
isRestful, isDeprecated, isCallbackRequest, uniqueItems, hasDefaultResponse = false, hasOnlyDefaultResponse = false, hasConstantParams = false,
34-
hasErrorResponseObject, // if 4xx, 5xx responses have at least one error object defined
35-
hasSingleParam = false; // if the operation has only one parameter;
32+
isDeprecated, isCallbackRequest, uniqueItems,
33+
hasErrorResponseObject; // if 4xx, 5xx responses have at least one error object defined
3634
public CodegenProperty returnProperty;
3735
public String path, operationId, returnType, returnFormat, httpMethod, returnBaseType,
3836
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse;
@@ -90,6 +88,24 @@ public boolean getHasParams() {
9088
return nonEmpty(allParams);
9189
}
9290

91+
/**
92+
* Check if there's at least one required parameter
93+
*
94+
* @return true if required parameter exists, false otherwise
95+
*/
96+
public boolean getHasRequiredParam() {
97+
return nonEmpty(requiredParams);
98+
}
99+
100+
/**
101+
* Check if there's exactly one parameter
102+
*
103+
* @return true if exactly one parameter exists, false otherwise
104+
*/
105+
public boolean getHasSingleParam() {
106+
return allParams.size() == 1;
107+
}
108+
93109
/**
94110
* Check if there's at least one body parameter
95111
*
@@ -372,7 +388,6 @@ public String toString() {
372388
sb.append(", hasConsumes=").append(hasConsumes);
373389
sb.append(", hasProduces=").append(hasProduces);
374390
sb.append(", hasOptionalParams=").append(hasOptionalParams);
375-
sb.append(", hasRequiredParams=").append(hasRequiredParams);
376391
sb.append(", returnTypeIsPrimitive=").append(returnTypeIsPrimitive);
377392
sb.append(", returnSimpleType=").append(returnSimpleType);
378393
sb.append(", subresourceOperation=").append(subresourceOperation);
@@ -385,16 +400,7 @@ public String toString() {
385400
sb.append(", isResponseFile=").append(isResponseFile);
386401
sb.append(", isResponseOptional=").append(isResponseOptional);
387402
sb.append(", hasReference=").append(hasReference);
388-
sb.append(", hasDefaultResponse=").append(hasDefaultResponse);
389-
sb.append(", hasOnlyDefaultResponse=").append(hasOnlyDefaultResponse);
390403
sb.append(", hasErrorResponseObject=").append(hasErrorResponseObject);
391-
sb.append(", hasSingleParam=").append(hasSingleParam);
392-
sb.append(", isRestfulIndex=").append(isRestfulIndex);
393-
sb.append(", isRestfulShow=").append(isRestfulShow);
394-
sb.append(", isRestfulCreate=").append(isRestfulCreate);
395-
sb.append(", isRestfulUpdate=").append(isRestfulUpdate);
396-
sb.append(", isRestfulDestroy=").append(isRestfulDestroy);
397-
sb.append(", isRestful=").append(isRestful);
398404
sb.append(", isDeprecated=").append(isDeprecated);
399405
sb.append(", isCallbackRequest=").append(isCallbackRequest);
400406
sb.append(", uniqueItems='").append(uniqueItems);
@@ -454,7 +460,6 @@ public boolean equals(Object o) {
454460
hasConsumes == that.hasConsumes &&
455461
hasProduces == that.hasProduces &&
456462
hasOptionalParams == that.hasOptionalParams &&
457-
hasRequiredParams == that.hasRequiredParams &&
458463
returnTypeIsPrimitive == that.returnTypeIsPrimitive &&
459464
returnSimpleType == that.returnSimpleType &&
460465
subresourceOperation == that.subresourceOperation &&
@@ -466,16 +471,7 @@ public boolean equals(Object o) {
466471
isResponseFile == that.isResponseFile &&
467472
isResponseOptional == that.isResponseOptional &&
468473
hasReference == that.hasReference &&
469-
hasDefaultResponse == that.hasDefaultResponse &&
470-
hasOnlyDefaultResponse == that.hasOnlyDefaultResponse &&
471474
hasErrorResponseObject == that.hasErrorResponseObject &&
472-
hasSingleParam == that.hasSingleParam &&
473-
isRestfulIndex == that.isRestfulIndex &&
474-
isRestfulShow == that.isRestfulShow &&
475-
isRestfulCreate == that.isRestfulCreate &&
476-
isRestfulUpdate == that.isRestfulUpdate &&
477-
isRestfulDestroy == that.isRestfulDestroy &&
478-
isRestful == that.isRestful &&
479475
isDeprecated == that.isDeprecated &&
480476
isCallbackRequest == that.isCallbackRequest &&
481477
uniqueItems == that.uniqueItems &&
@@ -530,15 +526,14 @@ public boolean equals(Object o) {
530526
public int hashCode() {
531527

532528
return Objects.hash(responseHeaders, hasAuthMethods, hasConsumes, hasProduces, hasOptionalParams,
533-
hasRequiredParams, returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMap,
529+
returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMap,
534530
isArray, isMultipart, isVoid, isResponseBinary, isResponseFile, isResponseOptional, hasReference,
535-
hasDefaultResponse, hasOnlyDefaultResponse, isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
536-
isRestful, isDeprecated, isCallbackRequest, uniqueItems, path, operationId, returnType, httpMethod,
531+
isDeprecated, isCallbackRequest, uniqueItems, path, operationId, returnType, httpMethod,
537532
returnBaseType, returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse,
538533
discriminator, consumes, produces, prioritizedContentTypes, servers, bodyParam, allParams, bodyParams,
539534
pathParams, queryParams, headerParams, formParams, cookieParams, requiredParams, returnProperty, optionalParams,
540535
authMethods, tags, responses, callbacks, imports, examples, requestBodyExamples, externalDocs,
541536
vendorExtensions, nickname, operationIdOriginal, operationIdLowerCase, operationIdCamelCase,
542-
operationIdSnakeCase, hasErrorResponseObject, hasSingleParam, requiredAndNotNullableParams, notNullableParams, constantParams);
537+
operationIdSnakeCase, hasErrorResponseObject, requiredAndNotNullableParams, notNullableParams, constantParams);
543538
}
544539
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
128128
public boolean exclusiveMaximum;
129129
@Setter public boolean required;
130130
public boolean deprecated;
131-
public boolean hasMoreNonReadOnly; // for model constructor, true if next property is not readonly
132131
public boolean isPrimitiveType;
133132
public boolean isModel;
134133
/**
@@ -995,7 +994,6 @@ public String toString() {
995994
sb.append(", exclusiveMaximum=").append(exclusiveMaximum);
996995
sb.append(", required=").append(required);
997996
sb.append(", deprecated=").append(deprecated);
998-
sb.append(", hasMoreNonReadOnly=").append(hasMoreNonReadOnly);
999997
sb.append(", isPrimitiveType=").append(isPrimitiveType);
1000998
sb.append(", isModel=").append(isModel);
1001999
sb.append(", isContainer=").append(isContainer);
@@ -1092,7 +1090,6 @@ public boolean equals(Object o) {
10921090
exclusiveMaximum == that.exclusiveMaximum &&
10931091
required == that.required &&
10941092
deprecated == that.deprecated &&
1095-
hasMoreNonReadOnly == that.hasMoreNonReadOnly &&
10961093
isPrimitiveType == that.isPrimitiveType &&
10971094
isModel == that.isModel &&
10981095
isContainer == that.isContainer &&
@@ -1209,7 +1206,7 @@ public int hashCode() {
12091206
defaultValueWithParam, baseType, containerType, containerTypeMapped, title, unescapedDescription,
12101207
maxLength, minLength, pattern, example, jsonSchema, minimum, maximum,
12111208
exclusiveMinimum, exclusiveMaximum, required, deprecated,
1212-
hasMoreNonReadOnly, isPrimitiveType, isModel, isContainer, isString, isNumeric,
1209+
isPrimitiveType, isModel, isContainer, isString, isNumeric,
12131210
isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isFile,
12141211
isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword, isFreeFormObject,
12151212
isArray, isMap, isOptional, isEnum, isInnerEnum, isEnumRef, isAnyType, isReadOnly, isWriteOnly, isNullable, isShort,

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4834,19 +4834,6 @@ public CodegenOperation fromOperation(String path,
48344834
// legacy support
48354835
op.nickname = op.operationId;
48364836

4837-
op.hasRequiredParams = op.requiredParams.size() > 0;
4838-
4839-
// check if the operation has only a single parameter
4840-
op.hasSingleParam = op.allParams.size() == 1;
4841-
4842-
// set Restful Flag
4843-
op.isRestfulShow = op.isRestfulShow();
4844-
op.isRestfulIndex = op.isRestfulIndex();
4845-
op.isRestfulCreate = op.isRestfulCreate();
4846-
op.isRestfulUpdate = op.isRestfulUpdate();
4847-
op.isRestfulDestroy = op.isRestfulDestroy();
4848-
op.isRestful = op.isRestful();
4849-
48504837
return op;
48514838
}
48524839

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,12 +721,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
721721
this.isMultipart = o.isMultipart;
722722
this.isResponseBinary = o.isResponseBinary;
723723
this.hasReference = o.hasReference;
724-
this.isRestfulIndex = o.isRestfulIndex;
725-
this.isRestfulShow = o.isRestfulShow;
726-
this.isRestfulCreate = o.isRestfulCreate;
727-
this.isRestfulUpdate = o.isRestfulUpdate;
728-
this.isRestfulDestroy = o.isRestfulDestroy;
729-
this.isRestful = o.isRestful;
730724
this.path = o.path;
731725
this.operationId = o.operationId;
732726
this.returnType = o.returnType;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
428428
this.isResponseFile = o.isResponseFile;
429429
this.isResponseOptional = o.isResponseOptional;
430430
this.hasReference = o.hasReference;
431-
this.isRestfulIndex = o.isRestfulIndex;
432-
this.isRestfulShow = o.isRestfulShow;
433-
this.isRestfulCreate = o.isRestfulCreate;
434-
this.isRestfulUpdate = o.isRestfulUpdate;
435-
this.isRestfulDestroy = o.isRestfulDestroy;
436-
this.isRestful = o.isRestful;
437431
this.path = o.path;
438432
this.operationId = o.operationId;
439433
this.returnType = o.returnType;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,6 @@ class ExtendedCodegenOperation extends CodegenOperation {
516516
this.isMultipart = o.isMultipart;
517517
this.isResponseBinary = o.isResponseBinary;
518518
this.hasReference = o.hasReference;
519-
this.isRestfulIndex = o.isRestfulIndex;
520-
this.isRestfulShow = o.isRestfulShow;
521-
this.isRestfulCreate = o.isRestfulCreate;
522-
this.isRestfulUpdate = o.isRestfulUpdate;
523-
this.isRestfulDestroy = o.isRestfulDestroy;
524-
this.isRestful = o.isRestful;
525519
this.path = o.path;
526520
this.operationId = o.operationId;
527521
this.returnType = o.returnType;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,6 @@ public ExtendedCodegenProperty(CodegenProperty cp) {
12711271
this.exclusiveMaximum = cp.exclusiveMaximum;
12721272
this.required = cp.required;
12731273
this.deprecated = cp.deprecated;
1274-
this.hasMoreNonReadOnly = cp.hasMoreNonReadOnly;
12751274
this.isPrimitiveType = cp.isPrimitiveType;
12761275
this.isModel = cp.isModel;
12771276
this.isContainer = cp.isContainer;
@@ -1380,7 +1379,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
13801379
this.hasConsumes = o.hasConsumes;
13811380
this.hasProduces = o.hasProduces;
13821381
this.hasOptionalParams = o.hasOptionalParams;
1383-
this.hasRequiredParams = o.hasRequiredParams;
13841382
this.returnTypeIsPrimitive = o.returnTypeIsPrimitive;
13851383
this.returnSimpleType = o.returnSimpleType;
13861384
this.subresourceOperation = o.subresourceOperation;
@@ -1391,12 +1389,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
13911389
this.isResponseFile = o.isResponseFile;
13921390
this.isResponseOptional = o.isResponseOptional;
13931391
this.hasReference = o.hasReference;
1394-
this.isRestfulIndex = o.isRestfulIndex;
1395-
this.isRestfulShow = o.isRestfulShow;
1396-
this.isRestfulCreate = o.isRestfulCreate;
1397-
this.isRestfulUpdate = o.isRestfulUpdate;
1398-
this.isRestfulDestroy = o.isRestfulDestroy;
1399-
this.isRestful = o.isRestful;
14001392
this.isDeprecated = o.isDeprecated;
14011393
this.isCallbackRequest = o.isCallbackRequest;
14021394
this.uniqueItems = o.uniqueItems;

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
349349
this.hasConsumes = o.hasConsumes;
350350
this.hasProduces = o.hasProduces;
351351
this.hasOptionalParams = o.hasOptionalParams;
352-
this.hasRequiredParams = o.hasRequiredParams;
353352
this.returnTypeIsPrimitive = o.returnTypeIsPrimitive;
354353
this.returnSimpleType = o.returnSimpleType;
355354
this.subresourceOperation = o.subresourceOperation;
@@ -359,12 +358,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
359358
this.isResponseBinary = o.isResponseBinary;
360359
this.isResponseFile = o.isResponseFile;
361360
this.hasReference = o.hasReference;
362-
this.isRestfulIndex = o.isRestfulIndex;
363-
this.isRestfulShow = o.isRestfulShow;
364-
this.isRestfulCreate = o.isRestfulCreate;
365-
this.isRestfulUpdate = o.isRestfulUpdate;
366-
this.isRestfulDestroy = o.isRestfulDestroy;
367-
this.isRestful = o.isRestful;
368361
this.isDeprecated = o.isDeprecated;
369362
this.isCallbackRequest = o.isCallbackRequest;
370363
this.path = o.path;

modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,7 +5000,7 @@ public void testMultipleRequestParameter_hasSingleParamFalse() {
50005000
CodegenOperation codegenOperation = codegen.fromOperation(path, "GET", openAPI.getPaths().get(path).getGet(), null);
50015001

50025002
// When & Then
5003-
assertThat(codegenOperation.hasSingleParam).isFalse();
5003+
assertThat(codegenOperation.getHasSingleParam()).isFalse();
50045004
}
50055005

50065006
@Test
@@ -5013,6 +5013,6 @@ public void testSingleRequestParameter_hasSingleParamTrue() {
50135013
CodegenOperation codegenOperation = codegen.fromOperation(path, "POST", openAPI.getPaths().get(path).getPost(), null);
50145014

50155015
// When & Then
5016-
assertThat(codegenOperation.hasSingleParam).isTrue();
5016+
assertThat(codegenOperation.getHasSingleParam()).isTrue();
50175017
}
50185018
}

0 commit comments

Comments
 (0)