Skip to content

Commit

Permalink
fix #20198
Browse files Browse the repository at this point in the history
get rid of `local_var_` in order to make the code more readable.
Get rid of the "unbox" of parameters at function start, so that we dont have any problem with name clashes.
  • Loading branch information
xMAC94x committed Nov 29, 2024
1 parent 34bd021 commit 48c6524
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import org.openapitools.codegen.CliOption;
Expand All @@ -39,6 +40,7 @@
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.meta.features.ClientModificationFeature;
Expand All @@ -62,6 +64,8 @@

import io.swagger.v3.oas.models.media.Discriminator;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import joptsimple.internal.Strings;
import lombok.AccessLevel;
Expand Down Expand Up @@ -678,4 +682,142 @@ public String toDefaultValue(Schema p) {
return null;
}
}

public class ExtendedCodegenParameter extends CodegenParameter {
@Setter protected String paramIdentifier; // either `{{paramName}}` or `params.{{paramName}}`


public ExtendedCodegenParameter(CodegenParameter cp) {
super();

// CodegenParameter members
this.isFormParam = cp.isFormParam;
this.isQueryParam = cp.isQueryParam;
this.isPathParam = cp.isPathParam;
this.isHeaderParam = cp.isHeaderParam;
this.isCookieParam = cp.isCookieParam;
this.isBodyParam = cp.isBodyParam;
this.isContainer = cp.isContainer;
this.isCollectionFormatMulti = cp.isCollectionFormatMulti;
this.isPrimitiveType = cp.isPrimitiveType;
this.isModel = cp.isModel;
this.isExplode = cp.isExplode;
this.baseName = cp.baseName;
this.paramName = cp.paramName;
this.dataType = cp.dataType;
this.datatypeWithEnum = cp.datatypeWithEnum;
this.dataFormat = cp.dataFormat;
this.contentType = cp.contentType;
this.collectionFormat = cp.collectionFormat;
this.description = cp.description;
this.unescapedDescription = cp.unescapedDescription;
this.baseType = cp.baseType;
this.defaultValue = cp.defaultValue;
this.enumName = cp.enumName;
this.style = cp.style;
this.nameInLowerCase = cp.nameInLowerCase;
this.example = cp.example;
this.jsonSchema = cp.jsonSchema;
this.isString = cp.isString;
this.isNumeric = cp.isNumeric;
this.isInteger = cp.isInteger;
this.isLong = cp.isLong;
this.isNumber = cp.isNumber;
this.isFloat = cp.isFloat;
this.isDouble = cp.isDouble;
this.isDecimal = cp.isDecimal;
this.isByteArray = cp.isByteArray;
this.isBinary = cp.isBinary;
this.isBoolean = cp.isBoolean;
this.isDate = cp.isDate;
this.isDateTime = cp.isDateTime;
this.isUuid = cp.isUuid;
this.isUri = cp.isUri;
this.isEmail = cp.isEmail;
this.isFreeFormObject = cp.isFreeFormObject;
this.isAnyType = cp.isAnyType;
this.isArray = cp.isArray;
this.isMap = cp.isMap;
this.isFile = cp.isFile;
this.isEnum = cp.isEnum;
this.isEnumRef = cp.isEnumRef;
this._enum = cp._enum;
this.allowableValues = cp.allowableValues;
this.items = cp.items;
this.additionalProperties = cp.additionalProperties;
this.vars = cp.vars;
this.requiredVars = cp.requiredVars;
this.mostInnerItems = cp.mostInnerItems;
this.vendorExtensions = cp.vendorExtensions;
this.hasValidation = cp.hasValidation;
this.isNullable = cp.isNullable;
this.required = cp.required;
this.maximum = cp.maximum;
this.exclusiveMaximum = cp.exclusiveMaximum;
this.minimum = cp.minimum;
this.exclusiveMinimum = cp.exclusiveMinimum;
this.maxLength = cp.maxLength;
this.minLength = cp.minLength;
this.pattern = cp.pattern;
this.maxItems = cp.maxItems;
this.minItems = cp.minItems;
this.uniqueItems = cp.uniqueItems;
this.multipleOf = cp.multipleOf;
this.setHasVars(cp.getHasVars());
this.setHasRequired(cp.getHasRequired());
this.setMaxProperties(cp.getMaxProperties());
this.setMinProperties(cp.getMinProperties());

this.paramIdentifier = cp.paramName;
}

@Override
public ExtendedCodegenParameter copy() {
CodegenParameter superCopy = super.copy();
ExtendedCodegenParameter output = new ExtendedCodegenParameter(superCopy);
output.paramIdentifier = this.paramIdentifier;
return output;
}

@Override
public String toString() {
String superString = super.toString();
final StringBuilder sb = new StringBuilder(superString);
sb.append(", paramIdentifier=").append(paramIdentifier).append('\'');
return sb.toString();
}

protected void setPrefix(boolean prefix) {
if (prefix) {
this.paramIdentifier = "params." + this.paramName;
} else {
this.paramIdentifier = this.paramName;
}
}
}

@Override
public ExtendedCodegenParameter fromParameter(Parameter parameter, Set<String> imports) {
CodegenParameter cp = super.fromParameter(parameter, imports);
ExtendedCodegenParameter ecp = new ExtendedCodegenParameter(cp);
ecp.setPrefix(this.useSingleRequestParameter);
return ecp;
}

@Override
public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set<String> imports) {
CodegenParameter cp = super.fromFormProperty(name, propertySchema, imports);
ExtendedCodegenParameter ecp = new ExtendedCodegenParameter(cp);
ecp.setPrefix(this.useSingleRequestParameter);
return ecp;
}

@Override
public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName) {
CodegenParameter cp = super.fromRequestBody(body, imports, bodyParameterName);
ExtendedCodegenParameter ecp = new ExtendedCodegenParameter(cp);
ecp.setPrefix(this.useSingleRequestParameter);
return ecp;
}

}
Loading

0 comments on commit 48c6524

Please sign in to comment.