Skip to content

Commit f40f72c

Browse files
authored
[typescript] fix: explode: true should yield appended query params (#19519)
* [typescript] fix: `explode: true` should yield appended `query` params * fix: object keys should be `set`
1 parent 8678ee8 commit f40f72c

97 files changed

Lines changed: 14183 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generatorName: typescript
2+
outputDir: samples/openapi3/client/petstore/typescript/builds/explode-query
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/snakecase-discriminator.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/typescript
5+
additionalProperties:
6+
platform: node
7+
npmName: ts-petstore-client
8+
projectName: ts-petstore-client
9+
moduleName: petstore

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,27 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
6666

6767
// Query Params
6868
if ({{paramName}} !== undefined) {
69+
{{#isPrimitiveType}}
6970
requestContext.setQueryParam("{{baseName}}", ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"));
71+
{{/isPrimitiveType}}
72+
{{^isPrimitiveType}}
73+
{{#isExplode}}
74+
const serializedParams = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}");
75+
{{#isArray}}
76+
for (const serializedParam of serializedParams) {
77+
requestContext.appendQueryParam("{{baseName}}", serializedParam);
78+
}
79+
{{/isArray}}
80+
{{^isArray}}
81+
for (const key of Object.keys(serializedParams)) {
82+
requestContext.setQueryParam(key, serializedParams[key]);
83+
}
84+
{{/isArray}}
85+
{{/isExplode}}
86+
{{^isExplode}}
87+
requestContext.setQueryParam("{{baseName}}", ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"));
88+
{{/isExplode}}
89+
{{/isPrimitiveType}}
7090
}
7191
{{/queryParams}}
7292
{{#headerParams}}

modules/openapi-generator/src/main/resources/typescript/http/http.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ export class RequestContext {
147147
this.url.searchParams.set(name, value);
148148
}
149149

150+
public appendQueryParam(name: string, value: string) {
151+
this.url.searchParams.append(name, value);
152+
}
153+
150154
/**
151155
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
152156
*

samples/client/others/typescript/builds/with-unique-items/http/http.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export class RequestContext {
105105
this.url.searchParams.set(name, value);
106106
}
107107

108+
public appendQueryParam(name: string, value: string) {
109+
this.url.searchParams.append(name, value);
110+
}
111+
108112
/**
109113
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
110114
*

samples/openapi3/client/petstore/typescript/builds/browser/http/http.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export class RequestContext {
105105
this.url.searchParams.set(name, value);
106106
}
107107

108+
public appendQueryParam(name: string, value: string) {
109+
this.url.searchParams.append(name, value);
110+
}
111+
108112
/**
109113
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
110114
*

samples/openapi3/client/petstore/typescript/builds/composed-schemas/http/http.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export class RequestContext {
105105
this.url.searchParams.set(name, value);
106106
}
107107

108+
public appendQueryParam(name: string, value: string) {
109+
this.url.searchParams.append(name, value);
110+
}
111+
108112
/**
109113
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
110114
*

samples/openapi3/client/petstore/typescript/builds/default/http/http.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ export class RequestContext {
114114
this.url.searchParams.set(name, value);
115115
}
116116

117+
public appendQueryParam(name: string, value: string) {
118+
this.url.searchParams.append(name, value);
119+
}
120+
117121
/**
118122
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
119123
*

samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export class RequestContext {
104104
this.url.searchParams.set(name, value);
105105
}
106106

107+
public appendQueryParam(name: string, value: string) {
108+
this.url.searchParams.append(name, value);
109+
}
110+
107111
/**
108112
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
109113
*

samples/openapi3/client/petstore/typescript/builds/deno_object_params/http/http.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export class RequestContext {
104104
this.url.searchParams.set(name, value);
105105
}
106106

107+
public appendQueryParam(name: string, value: string) {
108+
this.url.searchParams.append(name, value);
109+
}
110+
107111
/**
108112
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
109113
*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

0 commit comments

Comments
 (0)