Skip to content

CodegenOperation & CodegenProperty: turn fields into getters #21225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@

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

/**
* Check if there's at least one required parameter
*
* @return true if required parameter exists, false otherwise
*/
public boolean getHasRequiredParam() {
return nonEmpty(requiredParams);
}

/**
* Check if there's exactly one parameter
*
* @return true if exactly one parameter exists, false otherwise
*/
public boolean getHasSingleParam() {
return allParams.size() == 1;
}

/**
* Check if there's at least one body parameter
*
Expand Down Expand Up @@ -372,7 +388,6 @@ public String toString() {
sb.append(", hasConsumes=").append(hasConsumes);
sb.append(", hasProduces=").append(hasProduces);
sb.append(", hasOptionalParams=").append(hasOptionalParams);
sb.append(", hasRequiredParams=").append(hasRequiredParams);
sb.append(", returnTypeIsPrimitive=").append(returnTypeIsPrimitive);
sb.append(", returnSimpleType=").append(returnSimpleType);
sb.append(", subresourceOperation=").append(subresourceOperation);
Expand All @@ -385,16 +400,7 @@ public String toString() {
sb.append(", isResponseFile=").append(isResponseFile);
sb.append(", isResponseOptional=").append(isResponseOptional);
sb.append(", hasReference=").append(hasReference);
sb.append(", hasDefaultResponse=").append(hasDefaultResponse);
sb.append(", hasOnlyDefaultResponse=").append(hasOnlyDefaultResponse);
sb.append(", hasErrorResponseObject=").append(hasErrorResponseObject);
sb.append(", hasSingleParam=").append(hasSingleParam);
sb.append(", isRestfulIndex=").append(isRestfulIndex);
sb.append(", isRestfulShow=").append(isRestfulShow);
sb.append(", isRestfulCreate=").append(isRestfulCreate);
sb.append(", isRestfulUpdate=").append(isRestfulUpdate);
sb.append(", isRestfulDestroy=").append(isRestfulDestroy);
sb.append(", isRestful=").append(isRestful);
sb.append(", isDeprecated=").append(isDeprecated);
sb.append(", isCallbackRequest=").append(isCallbackRequest);
sb.append(", uniqueItems='").append(uniqueItems);
Expand Down Expand Up @@ -454,7 +460,6 @@ public boolean equals(Object o) {
hasConsumes == that.hasConsumes &&
hasProduces == that.hasProduces &&
hasOptionalParams == that.hasOptionalParams &&
hasRequiredParams == that.hasRequiredParams &&
returnTypeIsPrimitive == that.returnTypeIsPrimitive &&
returnSimpleType == that.returnSimpleType &&
subresourceOperation == that.subresourceOperation &&
Expand All @@ -466,16 +471,7 @@ public boolean equals(Object o) {
isResponseFile == that.isResponseFile &&
isResponseOptional == that.isResponseOptional &&
hasReference == that.hasReference &&
hasDefaultResponse == that.hasDefaultResponse &&
hasOnlyDefaultResponse == that.hasOnlyDefaultResponse &&
hasErrorResponseObject == that.hasErrorResponseObject &&
hasSingleParam == that.hasSingleParam &&
isRestfulIndex == that.isRestfulIndex &&
isRestfulShow == that.isRestfulShow &&
isRestfulCreate == that.isRestfulCreate &&
isRestfulUpdate == that.isRestfulUpdate &&
isRestfulDestroy == that.isRestfulDestroy &&
isRestful == that.isRestful &&
isDeprecated == that.isDeprecated &&
isCallbackRequest == that.isCallbackRequest &&
uniqueItems == that.uniqueItems &&
Expand Down Expand Up @@ -530,15 +526,14 @@ public boolean equals(Object o) {
public int hashCode() {

return Objects.hash(responseHeaders, hasAuthMethods, hasConsumes, hasProduces, hasOptionalParams,
hasRequiredParams, returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMap,
returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMap,
isArray, isMultipart, isVoid, isResponseBinary, isResponseFile, isResponseOptional, hasReference,
hasDefaultResponse, hasOnlyDefaultResponse, isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
isRestful, isDeprecated, isCallbackRequest, uniqueItems, path, operationId, returnType, httpMethod,
isDeprecated, isCallbackRequest, uniqueItems, path, operationId, returnType, httpMethod,
returnBaseType, returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse,
discriminator, consumes, produces, prioritizedContentTypes, servers, bodyParam, allParams, bodyParams,
pathParams, queryParams, headerParams, formParams, cookieParams, requiredParams, returnProperty, optionalParams,
authMethods, tags, responses, callbacks, imports, examples, requestBodyExamples, externalDocs,
vendorExtensions, nickname, operationIdOriginal, operationIdLowerCase, operationIdCamelCase,
operationIdSnakeCase, hasErrorResponseObject, hasSingleParam, requiredAndNotNullableParams, notNullableParams, constantParams);
operationIdSnakeCase, hasErrorResponseObject, requiredAndNotNullableParams, notNullableParams, constantParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
public boolean exclusiveMaximum;
@Setter public boolean required;
public boolean deprecated;
public boolean hasMoreNonReadOnly; // for model constructor, true if next property is not readonly
public boolean isPrimitiveType;
public boolean isModel;
/**
Expand Down Expand Up @@ -995,7 +994,6 @@ public String toString() {
sb.append(", exclusiveMaximum=").append(exclusiveMaximum);
sb.append(", required=").append(required);
sb.append(", deprecated=").append(deprecated);
sb.append(", hasMoreNonReadOnly=").append(hasMoreNonReadOnly);
sb.append(", isPrimitiveType=").append(isPrimitiveType);
sb.append(", isModel=").append(isModel);
sb.append(", isContainer=").append(isContainer);
Expand Down Expand Up @@ -1092,7 +1090,6 @@ public boolean equals(Object o) {
exclusiveMaximum == that.exclusiveMaximum &&
required == that.required &&
deprecated == that.deprecated &&
hasMoreNonReadOnly == that.hasMoreNonReadOnly &&
isPrimitiveType == that.isPrimitiveType &&
isModel == that.isModel &&
isContainer == that.isContainer &&
Expand Down Expand Up @@ -1209,7 +1206,7 @@ public int hashCode() {
defaultValueWithParam, baseType, containerType, containerTypeMapped, title, unescapedDescription,
maxLength, minLength, pattern, example, jsonSchema, minimum, maximum,
exclusiveMinimum, exclusiveMaximum, required, deprecated,
hasMoreNonReadOnly, isPrimitiveType, isModel, isContainer, isString, isNumeric,
isPrimitiveType, isModel, isContainer, isString, isNumeric,
isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isFile,
isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword, isFreeFormObject,
isArray, isMap, isOptional, isEnum, isInnerEnum, isEnumRef, isAnyType, isReadOnly, isWriteOnly, isNullable, isShort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4834,19 +4834,6 @@ public CodegenOperation fromOperation(String path,
// legacy support
op.nickname = op.operationId;

op.hasRequiredParams = op.requiredParams.size() > 0;

// check if the operation has only a single parameter
op.hasSingleParam = op.allParams.size() == 1;

// set Restful Flag
op.isRestfulShow = op.isRestfulShow();
op.isRestfulIndex = op.isRestfulIndex();
op.isRestfulCreate = op.isRestfulCreate();
op.isRestfulUpdate = op.isRestfulUpdate();
op.isRestfulDestroy = op.isRestfulDestroy();
op.isRestful = op.isRestful();

return op;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,12 +721,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
this.isMultipart = o.isMultipart;
this.isResponseBinary = o.isResponseBinary;
this.hasReference = o.hasReference;
this.isRestfulIndex = o.isRestfulIndex;
this.isRestfulShow = o.isRestfulShow;
this.isRestfulCreate = o.isRestfulCreate;
this.isRestfulUpdate = o.isRestfulUpdate;
this.isRestfulDestroy = o.isRestfulDestroy;
this.isRestful = o.isRestful;
this.path = o.path;
this.operationId = o.operationId;
this.returnType = o.returnType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
this.isResponseFile = o.isResponseFile;
this.isResponseOptional = o.isResponseOptional;
this.hasReference = o.hasReference;
this.isRestfulIndex = o.isRestfulIndex;
this.isRestfulShow = o.isRestfulShow;
this.isRestfulCreate = o.isRestfulCreate;
this.isRestfulUpdate = o.isRestfulUpdate;
this.isRestfulDestroy = o.isRestfulDestroy;
this.isRestful = o.isRestful;
this.path = o.path;
this.operationId = o.operationId;
this.returnType = o.returnType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,6 @@ class ExtendedCodegenOperation extends CodegenOperation {
this.isMultipart = o.isMultipart;
this.isResponseBinary = o.isResponseBinary;
this.hasReference = o.hasReference;
this.isRestfulIndex = o.isRestfulIndex;
this.isRestfulShow = o.isRestfulShow;
this.isRestfulCreate = o.isRestfulCreate;
this.isRestfulUpdate = o.isRestfulUpdate;
this.isRestfulDestroy = o.isRestfulDestroy;
this.isRestful = o.isRestful;
this.path = o.path;
this.operationId = o.operationId;
this.returnType = o.returnType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,6 @@ public ExtendedCodegenProperty(CodegenProperty cp) {
this.exclusiveMaximum = cp.exclusiveMaximum;
this.required = cp.required;
this.deprecated = cp.deprecated;
this.hasMoreNonReadOnly = cp.hasMoreNonReadOnly;
this.isPrimitiveType = cp.isPrimitiveType;
this.isModel = cp.isModel;
this.isContainer = cp.isContainer;
Expand Down Expand Up @@ -1380,7 +1379,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
this.hasConsumes = o.hasConsumes;
this.hasProduces = o.hasProduces;
this.hasOptionalParams = o.hasOptionalParams;
this.hasRequiredParams = o.hasRequiredParams;
this.returnTypeIsPrimitive = o.returnTypeIsPrimitive;
this.returnSimpleType = o.returnSimpleType;
this.subresourceOperation = o.subresourceOperation;
Expand All @@ -1391,12 +1389,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
this.isResponseFile = o.isResponseFile;
this.isResponseOptional = o.isResponseOptional;
this.hasReference = o.hasReference;
this.isRestfulIndex = o.isRestfulIndex;
this.isRestfulShow = o.isRestfulShow;
this.isRestfulCreate = o.isRestfulCreate;
this.isRestfulUpdate = o.isRestfulUpdate;
this.isRestfulDestroy = o.isRestfulDestroy;
this.isRestful = o.isRestful;
this.isDeprecated = o.isDeprecated;
this.isCallbackRequest = o.isCallbackRequest;
this.uniqueItems = o.uniqueItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
this.hasConsumes = o.hasConsumes;
this.hasProduces = o.hasProduces;
this.hasOptionalParams = o.hasOptionalParams;
this.hasRequiredParams = o.hasRequiredParams;
this.returnTypeIsPrimitive = o.returnTypeIsPrimitive;
this.returnSimpleType = o.returnSimpleType;
this.subresourceOperation = o.subresourceOperation;
Expand All @@ -359,12 +358,6 @@ public ExtendedCodegenOperation(CodegenOperation o) {
this.isResponseBinary = o.isResponseBinary;
this.isResponseFile = o.isResponseFile;
this.hasReference = o.hasReference;
this.isRestfulIndex = o.isRestfulIndex;
this.isRestfulShow = o.isRestfulShow;
this.isRestfulCreate = o.isRestfulCreate;
this.isRestfulUpdate = o.isRestfulUpdate;
this.isRestfulDestroy = o.isRestfulDestroy;
this.isRestful = o.isRestful;
this.isDeprecated = o.isDeprecated;
this.isCallbackRequest = o.isCallbackRequest;
this.path = o.path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5000,7 +5000,7 @@ public void testMultipleRequestParameter_hasSingleParamFalse() {
CodegenOperation codegenOperation = codegen.fromOperation(path, "GET", openAPI.getPaths().get(path).getGet(), null);

// When & Then
assertThat(codegenOperation.hasSingleParam).isFalse();
assertThat(codegenOperation.getHasSingleParam()).isFalse();
}

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

// When & Then
assertThat(codegenOperation.hasSingleParam).isTrue();
assertThat(codegenOperation.getHasSingleParam()).isTrue();
}
}
Loading
Loading