Skip to content

Commit d87f086

Browse files
committed
feat: use vendorExtensions instead of extending CodegenParameter
1 parent 9c7fcfa commit d87f086

File tree

2 files changed

+4
-156
lines changed

2 files changed

+4
-156
lines changed

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

Lines changed: 2 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package org.openapitools.codegen.languages;
1818

1919
import io.swagger.v3.oas.models.media.Schema;
20-
import io.swagger.v3.oas.models.parameters.Parameter;
21-
import io.swagger.v3.oas.models.parameters.RequestBody;
2220
import lombok.Getter;
2321
import lombok.Setter;
2422
import org.openapitools.codegen.*;
@@ -269,34 +267,6 @@ private boolean isLanguageGenericType(String type) {
269267
return false;
270268
}
271269

272-
@Override
273-
public List<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body, Set<String> imports) {
274-
List<CodegenParameter> superParams = super.fromRequestBodyToFormParameters(body, imports);
275-
List<CodegenParameter> extendedParams = new ArrayList<CodegenParameter>();
276-
for (CodegenParameter cp : superParams) {
277-
extendedParams.add(new ExtendedCodegenParameter(cp));
278-
}
279-
return extendedParams;
280-
}
281-
282-
@Override
283-
public ExtendedCodegenParameter fromParameter(Parameter parameter, Set<String> imports) {
284-
CodegenParameter cp = super.fromParameter(parameter, imports);
285-
return new ExtendedCodegenParameter(cp);
286-
}
287-
288-
@Override
289-
public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set<String> imports) {
290-
CodegenParameter cp = super.fromFormProperty(name, propertySchema, imports);
291-
return new ExtendedCodegenParameter(cp);
292-
}
293-
294-
@Override
295-
public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, String bodyParameterName) {
296-
CodegenParameter cp = super.fromRequestBody(body, imports, bodyParameterName);
297-
return new ExtendedCodegenParameter(cp);
298-
}
299-
300270
@Override
301271
public void postProcessParameter(CodegenParameter parameter) {
302272
super.postProcessParameter(parameter);
@@ -360,10 +330,8 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap operations, L
360330
// Overwrite path to TypeScript template string, after applying everything we just did.
361331
op.path = pathBuffer.toString();
362332

363-
for (CodegenParameter cpParam : op.allParams) {
364-
ExtendedCodegenParameter param = (ExtendedCodegenParameter) cpParam;
365-
366-
param.hasSanitizedName = !param.baseName.equals(param.paramName);
333+
for (CodegenParameter param : op.allParams) {
334+
param.vendorExtensions.putIfAbsent("x-param-has-sanitized-name", !param.baseName.equals(param.paramName));
367335
}
368336
}
369337

@@ -520,126 +488,6 @@ public String removeModelPrefixSuffix(String name) {
520488
return result;
521489
}
522490

523-
public class ExtendedCodegenParameter extends CodegenParameter {
524-
public boolean hasSanitizedName = false;
525-
526-
public ExtendedCodegenParameter(CodegenParameter cp) {
527-
super();
528-
529-
this.isFormParam = cp.isFormParam;
530-
this.isQueryParam = cp.isQueryParam;
531-
this.isPathParam = cp.isPathParam;
532-
this.isHeaderParam = cp.isHeaderParam;
533-
this.isCookieParam = cp.isCookieParam;
534-
this.isBodyParam = cp.isBodyParam;
535-
this.isContainer = cp.isContainer;
536-
this.isCollectionFormatMulti = cp.isCollectionFormatMulti;
537-
this.isPrimitiveType = cp.isPrimitiveType;
538-
this.isModel = cp.isModel;
539-
this.isExplode = cp.isExplode;
540-
this.baseName = cp.baseName;
541-
this.paramName = cp.paramName;
542-
this.dataType = cp.dataType;
543-
this.datatypeWithEnum = cp.datatypeWithEnum;
544-
this.dataFormat = cp.dataFormat;
545-
this.contentType = cp.contentType;
546-
this.collectionFormat = cp.collectionFormat;
547-
this.description = cp.description;
548-
this.unescapedDescription = cp.unescapedDescription;
549-
this.baseType = cp.baseType;
550-
this.defaultValue = cp.defaultValue;
551-
this.enumName = cp.enumName;
552-
this.style = cp.style;
553-
this.nameInLowerCase = cp.nameInLowerCase;
554-
this.example = cp.example;
555-
this.jsonSchema = cp.jsonSchema;
556-
this.isString = cp.isString;
557-
this.isNumeric = cp.isNumeric;
558-
this.isInteger = cp.isInteger;
559-
this.isLong = cp.isLong;
560-
this.isNumber = cp.isNumber;
561-
this.isFloat = cp.isFloat;
562-
this.isDouble = cp.isDouble;
563-
this.isDecimal = cp.isDecimal;
564-
this.isByteArray = cp.isByteArray;
565-
this.isBinary = cp.isBinary;
566-
this.isBoolean = cp.isBoolean;
567-
this.isDate = cp.isDate;
568-
this.isDateTime = cp.isDateTime;
569-
this.isUuid = cp.isUuid;
570-
this.isUri = cp.isUri;
571-
this.isEmail = cp.isEmail;
572-
this.isFreeFormObject = cp.isFreeFormObject;
573-
this.isAnyType = cp.isAnyType;
574-
this.isArray = cp.isArray;
575-
this.isMap = cp.isMap;
576-
this.isFile = cp.isFile;
577-
this.isEnum = cp.isEnum;
578-
this.isEnumRef = cp.isEnumRef;
579-
this._enum = cp._enum;
580-
this.allowableValues = cp.allowableValues;
581-
this.items = cp.items;
582-
this.additionalProperties = cp.additionalProperties;
583-
this.vars = cp.vars;
584-
this.requiredVars = cp.requiredVars;
585-
this.mostInnerItems = cp.mostInnerItems;
586-
this.vendorExtensions = cp.vendorExtensions;
587-
this.hasValidation = cp.hasValidation;
588-
this.isNullable = cp.isNullable;
589-
this.required = cp.required;
590-
this.maximum = cp.maximum;
591-
this.exclusiveMaximum = cp.exclusiveMaximum;
592-
this.minimum = cp.minimum;
593-
this.exclusiveMinimum = cp.exclusiveMinimum;
594-
this.maxLength = cp.maxLength;
595-
this.minLength = cp.minLength;
596-
this.pattern = cp.pattern;
597-
this.maxItems = cp.maxItems;
598-
this.minItems = cp.minItems;
599-
this.uniqueItems = cp.uniqueItems;
600-
this.multipleOf = cp.multipleOf;
601-
this.setHasVars(cp.getHasVars());
602-
this.setHasRequired(cp.getHasRequired());
603-
this.setMaxProperties(cp.getMaxProperties());
604-
this.setMinProperties(cp.getMinProperties());
605-
}
606-
607-
@Override
608-
public ExtendedCodegenParameter copy() {
609-
CodegenParameter superCopy = super.copy();
610-
ExtendedCodegenParameter output = new ExtendedCodegenParameter(superCopy);
611-
output.hasSanitizedName = this.hasSanitizedName;
612-
return output;
613-
}
614-
615-
@Override
616-
public boolean equals(Object o) {
617-
if (o == null)
618-
return false;
619-
620-
if (this.getClass() != o.getClass())
621-
return false;
622-
623-
boolean result = super.equals(o);
624-
ExtendedCodegenParameter that = (ExtendedCodegenParameter) o;
625-
return result && hasSanitizedName == that.hasSanitizedName;
626-
}
627-
628-
@Override
629-
public int hashCode() {
630-
int superHash = super.hashCode();
631-
return Objects.hash(superHash, hasSanitizedName);
632-
}
633-
634-
@Override
635-
public String toString() {
636-
String superString = super.toString();
637-
final StringBuilder sb = new StringBuilder(superString);
638-
sb.append(", hasSanitizedName=").append(hasSanitizedName);
639-
return sb.toString();
640-
}
641-
}
642-
643491
/**
644492
* Validates that the given string value only contains '-', '.' and alpha numeric characters.
645493
* Throws an IllegalArgumentException, if the string contains any other characters.

modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface {{classname}}{{operationIdCamelCase}}Request {
3535
* @type {{=<% %>=}}{<%&dataType%>}<%={{ }}=%>
3636
* @memberof {{classname}}{{operationIdCamelCase}}
3737
*/
38-
readonly {{#hasSanitizedName}}'{{{baseName}}}'{{/hasSanitizedName}}{{^hasSanitizedName}}{{{paramName}}}{{/hasSanitizedName}}{{^required}}?{{/required}}: {{{dataType}}}
38+
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}}}
3939
{{^-last}}
4040

4141
{{/-last}}
@@ -106,7 +106,7 @@ export class {{classname}} {
106106
{{#useSingleRequestParameter}}
107107
const {
108108
{{#allParams}}
109-
{{#hasSanitizedName}}'{{{baseName}}}': {{/hasSanitizedName}}{{paramName}},
109+
{{#vendorExtensions.x-param-has-sanitized-name}}'{{{baseName}}}': {{/vendorExtensions.x-param-has-sanitized-name}}{{paramName}},
110110
{{/allParams}}
111111
} = requestParameters;
112112

0 commit comments

Comments
 (0)