Skip to content

Commit

Permalink
adapt TS templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jablan committed Oct 6, 2023
1 parent 4879b2b commit 5943520
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
50 changes: 25 additions & 25 deletions openapi-generator/templates/typescript-fetch/apis.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class {{classname}} extends runtime.BaseAPI {
const queryParameters: any = {};
{{#queryParams}}
{{#isListContainer}}
{{#isArray}}
if (requestParameters.{{paramName}}) {
{{#isCollectionFormatMulti}}
queryParameters['{{baseName}}'] = requestParameters.{{paramName}};
Expand All @@ -111,8 +111,8 @@ export class {{classname}} extends runtime.BaseAPI {
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
{{/isArray}}
{{^isArray}}
if (requestParameters.{{paramName}} !== undefined) {
{{#isDateTime}}
queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString();
Expand All @@ -127,7 +127,7 @@ export class {{classname}} extends runtime.BaseAPI {
{{/isDateTime}}
}
{{/isListContainer}}
{{/isArray}}
{{/queryParams}}
const headerParameters: runtime.HTTPHeaders = {};
Expand All @@ -142,18 +142,18 @@ export class {{classname}} extends runtime.BaseAPI {
{{/consumes.0}}
{{/bodyParam}}
{{#headerParams}}
{{#isListContainer}}
{{#isArray}}
if (requestParameters.{{paramName}}) {
headerParameters['{{baseName}}'] = requestParameters.{{paramName}}.join(runtime.COLLECTION_FORMATS["{{collectionFormat}}"]);
}
{{/isListContainer}}
{{^isListContainer}}
{{/isArray}}
{{^isArray}}
if (requestParameters.{{paramName}} !== undefined && requestParameters.{{paramName}} !== null) {
headerParameters['{{baseName}}'] = String(requestParameters.{{paramName}});
}
{{/isListContainer}}
{{/isArray}}
{{/headerParams}}
{{#authMethods}}
{{#isBasic}}
Expand Down Expand Up @@ -223,7 +223,7 @@ export class {{classname}} extends runtime.BaseAPI {
}
{{#formParams}}
{{#isListContainer}}
{{#isArray}}
if (requestParameters.{{paramName}}) {
{{#isCollectionFormatMulti}}
requestParameters.{{paramName}}.forEach((element) => {
Expand All @@ -235,8 +235,8 @@ export class {{classname}} extends runtime.BaseAPI {
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
{{/isArray}}
{{^isArray}}
if (requestParameters.{{paramName}} !== undefined) {
{{#isFreeFormObject}}
this.flattenDeepParams({
Expand All @@ -250,7 +250,7 @@ export class {{classname}} extends runtime.BaseAPI {
{{/isFreeFormObject}}
}
{{/isListContainer}}
{{/isArray}}
{{/formParams}}
{{/hasFormParams}}
const response = await this.request({
Expand All @@ -261,7 +261,7 @@ export class {{classname}} extends runtime.BaseAPI {
{{#hasBodyParam}}
{{#bodyParam}}
{{#isContainer}}
body: requestParameters.{{paramName}}{{#isListContainer}}{{#items}}{{^isPrimitiveType}}.map({{datatype}}ToJSON){{/isPrimitiveType}}{{/items}}{{/isListContainer}},
body: requestParameters.{{paramName}}{{#isArray}}{{#items}}{{^isPrimitiveType}}.map({{datatype}}ToJSON){{/isPrimitiveType}}{{/items}}{{/isArray}},
{{/isContainer}}
{{^isContainer}}
{{^isPrimitiveType}}
Expand All @@ -284,28 +284,28 @@ export class {{classname}} extends runtime.BaseAPI {
{{/isResponseFile}}
{{^isResponseFile}}
{{#returnTypeIsPrimitive}}
{{#isMapContainer}}
{{#isMap}}
return new runtime.JSONApiResponse<any>(response);
{{/isMapContainer}}
{{#isListContainer}}
{{/isMap}}
{{#isArray}}
return new runtime.JSONApiResponse<any>(response);
{{/isListContainer}}
{{/isArray}}
{{#returnSimpleType}}
return new runtime.TextApiResponse(response) as any;
{{/returnSimpleType}}
{{/returnTypeIsPrimitive}}
{{^returnTypeIsPrimitive}}
{{#isListContainer}}
{{#isArray}}
return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map({{returnBaseType}}FromJSON));
{{/isListContainer}}
{{^isListContainer}}
{{#isMapContainer}}
{{/isArray}}
{{^isArray}}
{{#isMap}}
return new runtime.JSONApiResponse(response, (jsonValue) => runtime.mapValues(jsonValue, {{returnBaseType}}FromJSON));
{{/isMapContainer}}
{{^isMapContainer}}
{{/isMap}}
{{^isMap}}
return new runtime.JSONApiResponse(response, (jsonValue) => {{returnBaseType}}FromJSON(jsonValue));
{{/isMapContainer}}
{{/isListContainer}}
{{/isMap}}
{{/isArray}}
{{/returnTypeIsPrimitive}}
{{/isResponseFile}}
{{/returnType}}
Expand Down
32 changes: 16 additions & 16 deletions openapi-generator/templates/typescript-fetch/modelGeneric.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole
{{/isDate}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isListContainer}}
{{#isArray}}
'{{name}}': {{^required}}!exists(json, '{{baseName}}') ? undefined : {{/required}}({{#isNullable}}json['{{baseName}}'] === null ? null : {{/isNullable}}(json['{{baseName}}'] as Array<any>).map({{#items}}{{datatype}}{{/items}}FromJSON)),
{{/isListContainer}}
{{#isMapContainer}}
{{/isArray}}
{{#isMap}}
'{{name}}': {{^required}}!exists(json, '{{baseName}}') ? undefined : {{/required}}({{#isNullable}}json['{{baseName}}'] === null ? null : {{/isNullable}}mapValues(json['{{baseName}}'], {{#items}}{{datatype}}{{/items}}FromJSON)),
{{/isMapContainer}}
{{^isListContainer}}
{{^isMapContainer}}
{{/isMap}}
{{^isArray}}
{{^isMap}}
{{^isFreeFormObject}}
'{{name}}': {{^required}}!exists(json, '{{baseName}}') ? undefined : {{/required}}{{datatype}}FromJSON(json['{{baseName}}']),
{{/isFreeFormObject}}
{{#isFreeFormObject}}
'{{name}}': {{^required}}!exists(json, '{{baseName}}') ? undefined : {{/required}}json['{{baseName}}'],
{{/isFreeFormObject}}
{{/isMapContainer}}
{{/isListContainer}}
{{/isMap}}
{{/isArray}}
{{/isPrimitiveType}}
{{/vars}}
};
Expand Down Expand Up @@ -119,22 +119,22 @@ export function {{classname}}ToJSON(value?: {{classname}} | null): any {
'{{baseName}}': {{#isDate}}{{^required}}value.{{name}} === undefined ? undefined : {{/required}}({{#isNullable}}value.{{name}} === null ? null : {{/isNullable}}value.{{name}}.toISOString().substr(0,10)){{/isDate}}{{#isDateTime}}{{^required}}value.{{name}} === undefined ? undefined : {{/required}}({{#isNullable}}value.{{name}} === null ? null : {{/isNullable}}value.{{name}}.toISOString()){{/isDateTime}}{{^isDate}}{{^isDateTime}}value.{{name}}{{/isDateTime}}{{/isDate}},
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isListContainer}}
{{#isArray}}
'{{baseName}}': {{^required}}value.{{name}} === undefined ? undefined : {{/required}}({{#isNullable}}value.{{name}} === null ? null : {{/isNullable}}(value.{{name}} as Array<any>).map({{#items}}{{datatype}}{{/items}}ToJSON)),
{{/isListContainer}}
{{#isMapContainer}}
{{/isArray}}
{{#isMap}}
'{{baseName}}': {{^required}}value.{{name}} === undefined ? undefined : {{/required}}({{#isNullable}}value.{{name}} === null ? null : {{/isNullable}}mapValues(value.{{name}}, {{#items}}{{datatype}}{{/items}}ToJSON)),
{{/isMapContainer}}
{{^isListContainer}}
{{^isMapContainer}}
{{/isMap}}
{{^isArray}}
{{^isMap}}
{{^isFreeFormObject}}
'{{baseName}}': {{datatype}}ToJSON(value.{{name}}),
{{/isFreeFormObject}}
{{#isFreeFormObject}}
'{{baseName}}': value.{{name}},
{{/isFreeFormObject}}
{{/isMapContainer}}
{{/isListContainer}}
{{/isMap}}
{{/isArray}}
{{/isPrimitiveType}}
{{/isReadOnly}}
{{/vars}}
Expand Down

0 comments on commit 5943520

Please sign in to comment.