Skip to content

Commit d8e5502

Browse files
author
Sebastian Gaul
committed
Add support for deepObject-style parameters
1 parent b25aa8a commit d8e5502

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/templates/core/functions/getQueryString.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ function getQueryString(params: Record<string, any>): string {
77
value.forEach(value => {
88
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
99
});
10+
} else if (typeof value === 'object') {
11+
Object.entries(value).forEach(([innerKey, value]) => {
12+
const target = `${key}[${innerKey}]`
13+
qs.push(`${encodeURIComponent(target)}=${encodeURIComponent(String(value))}`);
14+
});
1015
} else {
1116
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
1217
}

test/__snapshots__/index.spec.js.snap

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,7 @@ export { ParametersService } from './services/ParametersService';
27042704
export { RequestBodyService } from './services/RequestBodyService';
27052705
export { ResponseService } from './services/ResponseService';
27062706
export { SimpleService } from './services/SimpleService';
2707+
export { StyleService } from './services/StyleService';
27072708
export { TypesService } from './services/TypesService';
27082709
export { UploadService } from './services/UploadService';
27092710
"
@@ -4957,6 +4958,38 @@ export class SimpleService {
49574958
}"
49584959
`;
49594960

4961+
exports[`v3 should generate: ./test/generated/v3/services/StyleService.ts 1`] = `
4962+
"/* istanbul ignore file */
4963+
/* tslint:disable */
4964+
/* eslint-disable */
4965+
import { request as __request } from '../core/request';
4966+
import { OpenAPI } from '../core/OpenAPI';
4967+
4968+
export class StyleService {
4969+
4970+
/**
4971+
* @param parameterDeepObject This is an object parameter that is send in deepObject style
4972+
* @throws ApiError
4973+
*/
4974+
public static async style(
4975+
parameterDeepObject?: {
4976+
propOne?: string,
4977+
propTwo?: boolean,
4978+
},
4979+
): Promise<void> {
4980+
const result = await __request({
4981+
method: 'GET',
4982+
path: \`/api/v\${OpenAPI.VERSION}/style\`,
4983+
query: {
4984+
'parameterDeepObject': parameterDeepObject,
4985+
},
4986+
});
4987+
return result.body;
4988+
}
4989+
4990+
}"
4991+
`;
4992+
49604993
exports[`v3 should generate: ./test/generated/v3/services/TypesService.ts 1`] = `
49614994
"/* istanbul ignore file */
49624995
/* tslint:disable */

test/spec/v3.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,34 @@
792792
]
793793
}
794794
},
795+
"/api/v{api-version}/style": {
796+
"get": {
797+
"tags": [
798+
"style"
799+
],
800+
"operationId": "Style",
801+
"parameters": [
802+
{
803+
"description": "This is an object parameter that is send in deepObject style",
804+
"name": "parameterDeepObject",
805+
"in": "query",
806+
"style": "deepObject",
807+
"schema": {
808+
"type": "object",
809+
"properties": {
810+
"propOne": {
811+
"type": "string"
812+
},
813+
"propTwo": {
814+
"type": "boolean"
815+
}
816+
}
817+
},
818+
"collectionFormat": "csv"
819+
}
820+
]
821+
}
822+
},
795823
"/api/v{api-version}/types": {
796824
"get": {
797825
"tags": [

0 commit comments

Comments
 (0)