From d87f086ed0b3be5bf965043c80bc27077a8a3dc0 Mon Sep 17 00:00:00 2001 From: Gregory Merlet Date: Fri, 29 Nov 2024 16:31:12 +0100 Subject: [PATCH] feat: use vendorExtensions instead of extending CodegenParameter --- .../TypeScriptNestjsClientCodegen.java | 156 +----------------- .../typescript-nestjs/api.service.mustache | 4 +- 2 files changed, 4 insertions(+), 156 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNestjsClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNestjsClientCodegen.java index 770167b0e765..e12e8b2f030f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNestjsClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNestjsClientCodegen.java @@ -17,8 +17,6 @@ package org.openapitools.codegen.languages; 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 lombok.Getter; import lombok.Setter; import org.openapitools.codegen.*; @@ -269,34 +267,6 @@ private boolean isLanguageGenericType(String type) { return false; } - @Override - public List fromRequestBodyToFormParameters(RequestBody body, Set imports) { - List superParams = super.fromRequestBodyToFormParameters(body, imports); - List extendedParams = new ArrayList(); - for (CodegenParameter cp : superParams) { - extendedParams.add(new ExtendedCodegenParameter(cp)); - } - return extendedParams; - } - - @Override - public ExtendedCodegenParameter fromParameter(Parameter parameter, Set imports) { - CodegenParameter cp = super.fromParameter(parameter, imports); - return new ExtendedCodegenParameter(cp); - } - - @Override - public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set imports) { - CodegenParameter cp = super.fromFormProperty(name, propertySchema, imports); - return new ExtendedCodegenParameter(cp); - } - - @Override - public CodegenParameter fromRequestBody(RequestBody body, Set imports, String bodyParameterName) { - CodegenParameter cp = super.fromRequestBody(body, imports, bodyParameterName); - return new ExtendedCodegenParameter(cp); - } - @Override public void postProcessParameter(CodegenParameter parameter) { super.postProcessParameter(parameter); @@ -360,10 +330,8 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap operations, L // Overwrite path to TypeScript template string, after applying everything we just did. op.path = pathBuffer.toString(); - for (CodegenParameter cpParam : op.allParams) { - ExtendedCodegenParameter param = (ExtendedCodegenParameter) cpParam; - - param.hasSanitizedName = !param.baseName.equals(param.paramName); + for (CodegenParameter param : op.allParams) { + param.vendorExtensions.putIfAbsent("x-param-has-sanitized-name", !param.baseName.equals(param.paramName)); } } @@ -520,126 +488,6 @@ public String removeModelPrefixSuffix(String name) { return result; } - public class ExtendedCodegenParameter extends CodegenParameter { - public boolean hasSanitizedName = false; - - public ExtendedCodegenParameter(CodegenParameter cp) { - super(); - - 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()); - } - - @Override - public ExtendedCodegenParameter copy() { - CodegenParameter superCopy = super.copy(); - ExtendedCodegenParameter output = new ExtendedCodegenParameter(superCopy); - output.hasSanitizedName = this.hasSanitizedName; - return output; - } - - @Override - public boolean equals(Object o) { - if (o == null) - return false; - - if (this.getClass() != o.getClass()) - return false; - - boolean result = super.equals(o); - ExtendedCodegenParameter that = (ExtendedCodegenParameter) o; - return result && hasSanitizedName == that.hasSanitizedName; - } - - @Override - public int hashCode() { - int superHash = super.hashCode(); - return Objects.hash(superHash, hasSanitizedName); - } - - @Override - public String toString() { - String superString = super.toString(); - final StringBuilder sb = new StringBuilder(superString); - sb.append(", hasSanitizedName=").append(hasSanitizedName); - return sb.toString(); - } - } - /** * Validates that the given string value only contains '-', '.' and alpha numeric characters. * Throws an IllegalArgumentException, if the string contains any other characters. diff --git a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache index dc67f59d27fe..12bf8d238860 100644 --- a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache @@ -35,7 +35,7 @@ export interface {{classname}}{{operationIdCamelCase}}Request { * @type {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> * @memberof {{classname}}{{operationIdCamelCase}} */ - readonly {{#hasSanitizedName}}'{{{baseName}}}'{{/hasSanitizedName}}{{^hasSanitizedName}}{{{paramName}}}{{/hasSanitizedName}}{{^required}}?{{/required}}: {{{dataType}}} + readonly {{#vendorExtensions.x-param-has-sanitized-name}}'{{{baseName}}}'{{/vendorExtensions.x-param-has-sanitized-name}}{{^vendorExtensions.x-param-has-sanitized-name}}{{{paramName}}}{{/vendorExtensions.x-param-has-sanitized-name}}{{^required}}?{{/required}}: {{{dataType}}} {{^-last}} {{/-last}} @@ -106,7 +106,7 @@ export class {{classname}} { {{#useSingleRequestParameter}} const { {{#allParams}} - {{#hasSanitizedName}}'{{{baseName}}}': {{/hasSanitizedName}}{{paramName}}, + {{#vendorExtensions.x-param-has-sanitized-name}}'{{{baseName}}}': {{/vendorExtensions.x-param-has-sanitized-name}}{{paramName}}, {{/allParams}} } = requestParameters;