diff --git a/CI/circle_parallel.sh b/CI/circle_parallel.sh index 9c55aeea28c..f10d419eca0 100755 --- a/CI/circle_parallel.sh +++ b/CI/circle_parallel.sh @@ -74,8 +74,8 @@ elif [ "$NODE_INDEX" = "3" ]; then [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" #nvm install stable # install v16 instead of the latest stable version - nvm install 16 - nvm alias default 16 + nvm install 18 + nvm alias default 18 node --version # Each step uses the same `$BASH_ENV`, so need to modify it diff --git a/bin/configs/typescript-angular-v19-deep-object.yaml b/bin/configs/typescript-angular-v19-deep-object.yaml new file mode 100644 index 00000000000..e588d61a68c --- /dev/null +++ b/bin/configs/typescript-angular-v19-deep-object.yaml @@ -0,0 +1,8 @@ +generatorName: typescript-angular +outputDir: samples/client/petstore/typescript-angular-v19/builds/deep-object +inputSpec: modules/openapi-generator/src/test/resources/3_0/deep-object-query.yaml +templateDir: modules/openapi-generator/src/main/resources/typescript-angular +additionalProperties: + ngVersion: 19.0.0 + npmName: sample-angular-19-0-0-deep-object + supportsES6: true diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/api.base.service.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/api.base.service.mustache index 311fd1aa079..70e4601cbf8 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/api.base.service.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/api.base.service.mustache @@ -29,22 +29,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache index 31184b79de2..c48a2b6b6f0 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache @@ -130,7 +130,7 @@ export class {{classname}} extends BaseService { {{/isArray}} {{^isArray}} localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - {{paramName}}, '{{baseName}}'); + {{paramName}}, '{{baseName}}'{{#isDeepObject}}, true{{/isDeepObject}}); {{/isArray}} {{/queryParams}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java index fc169b604fc..c1935f26ac9 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java @@ -464,4 +464,29 @@ public class TypeScriptAngularClientCodegenTest { assertThat(fileContents).containsOnlyOnce("} as const;"); assertThat(fileContents).doesNotContain(" as Type"); } + + @Test + public void testDeepObject() throws IOException { + // GIVEN + final String specPath = "src/test/resources/3_0/deepobject.yaml"; + + File output = Files.createTempDirectory("test").toFile(); + output.deleteOnExit(); + + // WHEN + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("typescript-angular") + .setInputSpec(specPath) + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + final ClientOptInput clientOptInput = configurator.toClientOptInput(); + + Generator generator = new DefaultGenerator(); + generator.opts(clientOptInput).generate(); + + // THEN + final String fileContents = Files.readString(Paths.get(output + "/api/default.service.ts")); + assertThat(fileContents).containsOnlyOnce("options, 'options', true);"); + assertThat(fileContents).containsOnlyOnce("inputOptions, 'inputOptions', true);"); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/deep-object-query.yaml b/modules/openapi-generator/src/test/resources/3_0/deep-object-query.yaml new file mode 100644 index 00000000000..ee263a4768e --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/deep-object-query.yaml @@ -0,0 +1,49 @@ +openapi: 3.0.0 +info: + title: deepobject-query + version: 1.0.0 +paths: + /car: + get: + operationId: getCars + parameters: + - name: filter + in: query + required: false + style: deepObject + schema: + $ref: '#/components/schemas/CarFilter' + explode: true + responses: + '200': + description: OK + content: + text/plain: + schema: + type: array + items: + $ref: '#/components/schemas/Car' +components: + schemas: + Car: + type: object + properties: + id: + type: integer + format: int64 + example: 1 + make: + type: string + example: Toyota + model: + type: string + example: Camry + CarFilter: + type: object + properties: + make: + type: string + example: Toyota + model: + type: string + example: Camry diff --git a/samples/client/others/typescript-angular/builds/composed-schemas-tagged-unions/api.base.service.ts b/samples/client/others/typescript-angular/builds/composed-schemas-tagged-unions/api.base.service.ts index b4e99170329..5800e940ea6 100644 --- a/samples/client/others/typescript-angular/builds/composed-schemas-tagged-unions/api.base.service.ts +++ b/samples/client/others/typescript-angular/builds/composed-schemas-tagged-unions/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/others/typescript-angular/builds/composed-schemas/api.base.service.ts b/samples/client/others/typescript-angular/builds/composed-schemas/api.base.service.ts index b4e99170329..5800e940ea6 100644 --- a/samples/client/others/typescript-angular/builds/composed-schemas/api.base.service.ts +++ b/samples/client/others/typescript-angular/builds/composed-schemas/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v12-oneOf/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v12-oneOf/builds/default/api.base.service.ts index 14cc2405f03..9ed72856f87 100644 --- a/samples/client/petstore/typescript-angular-v12-oneOf/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v12-oneOf/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v12-provided-in-any/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v12-provided-in-any/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v12-provided-in-any/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v12-provided-in-any/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v12-provided-in-root/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v12-provided-in-root/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v12-provided-in-root/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v12-provided-in-root/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v12-provided-in-root/builds/with-npm/api.base.service.ts b/samples/client/petstore/typescript-angular-v12-provided-in-root/builds/with-npm/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v12-provided-in-root/builds/with-npm/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v12-provided-in-root/builds/with-npm/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v13-oneOf/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v13-oneOf/builds/default/api.base.service.ts index 14cc2405f03..9ed72856f87 100644 --- a/samples/client/petstore/typescript-angular-v13-oneOf/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v13-oneOf/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v13-provided-in-any/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v13-provided-in-any/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v13-provided-in-any/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v13-provided-in-any/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v13-provided-in-root/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v13-provided-in-root/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v13-provided-in-root/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v13-provided-in-root/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v13-provided-in-root/builds/with-npm/api.base.service.ts b/samples/client/petstore/typescript-angular-v13-provided-in-root/builds/with-npm/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v13-provided-in-root/builds/with-npm/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v13-provided-in-root/builds/with-npm/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v14-provided-in-root/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v14-provided-in-root/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v14-provided-in-root/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v14-provided-in-root/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v14-query-param-object-format/api.base.service.ts b/samples/client/petstore/typescript-angular-v14-query-param-object-format/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v14-query-param-object-format/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v14-query-param-object-format/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v15-provided-in-root/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v15-provided-in-root/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v15-provided-in-root/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v15-provided-in-root/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v16-provided-in-root/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v16-provided-in-root/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v16-provided-in-root/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v16-provided-in-root/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v16-provided-in-root/tests/default/src/test/api.spec.ts b/samples/client/petstore/typescript-angular-v16-provided-in-root/tests/default/src/test/api.spec.ts index d1b1583e6f7..75bd04b513f 100644 --- a/samples/client/petstore/typescript-angular-v16-provided-in-root/tests/default/src/test/api.spec.ts +++ b/samples/client/petstore/typescript-angular-v16-provided-in-root/tests/default/src/test/api.spec.ts @@ -142,4 +142,4 @@ describe('API (functionality)', () => { ) })) }) -}) +}) \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular-v17-provided-in-root/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v17-provided-in-root/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v17-provided-in-root/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v17-provided-in-root/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v18-provided-in-root/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v18-provided-in-root/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v18-provided-in-root/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v18-provided-in-root/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v19-with-angular-dependency-params/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v19-with-angular-dependency-params/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v19-with-angular-dependency-params/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v19-with-angular-dependency-params/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/.gitignore b/samples/client/petstore/typescript-angular-v19/builds/deep-object/.gitignore new file mode 100644 index 00000000000..149b5765472 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/.gitignore @@ -0,0 +1,4 @@ +wwwroot/*.js +node_modules +typings +dist diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/.openapi-generator-ignore b/samples/client/petstore/typescript-angular-v19/builds/deep-object/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/.openapi-generator/FILES b/samples/client/petstore/typescript-angular-v19/builds/deep-object/.openapi-generator/FILES new file mode 100644 index 00000000000..ccf56e44302 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/.openapi-generator/FILES @@ -0,0 +1,18 @@ +.gitignore +README.md +api.base.service.ts +api.module.ts +api/api.ts +api/default.service.ts +configuration.ts +encoder.ts +git_push.sh +index.ts +model/car.ts +model/carFilter.ts +model/models.ts +ng-package.json +package.json +param.ts +tsconfig.json +variables.ts diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/.openapi-generator/VERSION b/samples/client/petstore/typescript-angular-v19/builds/deep-object/.openapi-generator/VERSION new file mode 100644 index 00000000000..4c631cf217a --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.14.0-SNAPSHOT diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/README.md b/samples/client/petstore/typescript-angular-v19/builds/deep-object/README.md new file mode 100644 index 00000000000..6ba9dab015b --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/README.md @@ -0,0 +1,236 @@ +# sample-angular-19-0-0-deep-object@1.0.0 + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +The version of the OpenAPI document: 1.0.0 + +## Building + +To install the required dependencies and to build the typescript sources run: + +```console +npm install +npm run build +``` + +## Publishing + +First build the package then run `npm publish dist` (don't forget to specify the `dist` folder!) + +## Consuming + +Navigate to the folder of your consuming project and run one of next commands. + +_published:_ + +```console +npm install sample-angular-19-0-0-deep-object@1.0.0 --save +``` + +_without publishing (not recommended):_ + +```console +npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save +``` + +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + +_using `npm link`:_ + +In PATH_TO_GENERATED_PACKAGE/dist: + +```console +npm link +``` + +In your project: + +```console +npm link sample-angular-19-0-0-deep-object +``` + +__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages. +Please refer to this issue for a solution / workaround. +Published packages are not effected by this issue. + +### General usage + +In your Angular project: + +```typescript +// without configuring providers +import { ApiModule } from 'sample-angular-19-0-0-deep-object'; +import { HttpClientModule } from '@angular/common/http'; + +@NgModule({ + imports: [ + ApiModule, + // make sure to import the HttpClientModule in the AppModule only, + // see https://github.com/angular/angular/issues/20575 + HttpClientModule + ], + declarations: [ AppComponent ], + providers: [], + bootstrap: [ AppComponent ] +}) +export class AppModule {} +``` + +```typescript +// configuring providers +import { ApiModule, Configuration, ConfigurationParameters } from 'sample-angular-19-0-0-deep-object'; + +export function apiConfigFactory (): Configuration { + const params: ConfigurationParameters = { + // set configuration parameters here. + } + return new Configuration(params); +} + +@NgModule({ + imports: [ ApiModule.forRoot(apiConfigFactory) ], + declarations: [ AppComponent ], + providers: [], + bootstrap: [ AppComponent ] +}) +export class AppModule {} +``` + +```typescript +// configuring providers with an authentication service that manages your access tokens +import { ApiModule, Configuration } from 'sample-angular-19-0-0-deep-object'; + +@NgModule({ + imports: [ ApiModule ], + declarations: [ AppComponent ], + providers: [ + { + provide: Configuration, + useFactory: (authService: AuthService) => new Configuration( + { + basePath: environment.apiUrl, + accessToken: authService.getAccessToken.bind(authService) + } + ), + deps: [AuthService], + multi: false + } + ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} +``` + +```typescript +import { DefaultApi } from 'sample-angular-19-0-0-deep-object'; + +export class AppComponent { + constructor(private apiGateway: DefaultApi) { } +} +``` + +Note: The ApiModule is restricted to being instantiated once app wide. +This is to ensure that all services are treated as singletons. + +### Using multiple OpenAPI files / APIs / ApiModules + +In order to use multiple `ApiModules` generated from different OpenAPI files, +you can create an alias name when importing the modules +in order to avoid naming conflicts: + +```typescript +import { ApiModule } from 'my-api-path'; +import { ApiModule as OtherApiModule } from 'my-other-api-path'; +import { HttpClientModule } from '@angular/common/http'; + +@NgModule({ + imports: [ + ApiModule, + OtherApiModule, + // make sure to import the HttpClientModule in the AppModule only, + // see https://github.com/angular/angular/issues/20575 + HttpClientModule + ] +}) +export class AppModule { + +} +``` + +### Set service base path + +If different than the generated base path, during app bootstrap, you can provide the base path to your service. + +```typescript +import { BASE_PATH } from 'sample-angular-19-0-0-deep-object'; + +bootstrap(AppComponent, [ + { provide: BASE_PATH, useValue: 'https://your-web-service.com' }, +]); +``` + +or + +```typescript +import { BASE_PATH } from 'sample-angular-19-0-0-deep-object'; + +@NgModule({ + imports: [], + declarations: [ AppComponent ], + providers: [ provide: BASE_PATH, useValue: 'https://your-web-service.com' ], + bootstrap: [ AppComponent ] +}) +export class AppModule {} +``` + +### Using @angular/cli + +First extend your `src/environments/*.ts` files by adding the corresponding base path: + +```typescript +export const environment = { + production: false, + API_BASE_PATH: 'http://127.0.0.1:8080' +}; +``` + +In the src/app/app.module.ts: + +```typescript +import { BASE_PATH } from 'sample-angular-19-0-0-deep-object'; +import { environment } from '../environments/environment'; + +@NgModule({ + declarations: [ + AppComponent + ], + imports: [ ], + providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }], + bootstrap: [ AppComponent ] +}) +export class AppModule { } +``` + +### Customizing path parameter encoding + +Without further customization, only [path-parameters][parameter-locations-url] of [style][style-values-url] 'simple' +and Dates for format 'date-time' are encoded correctly. + +Other styles (e.g. "matrix") are not that easy to encode +and thus are best delegated to other libraries (e.g.: [@honoluluhenk/http-param-expander]). + +To implement your own parameter encoding (or call another library), +pass an arrow-function or method-reference to the `encodeParam` property of the Configuration-object +(see [General Usage](#general-usage) above). + +Example value for use in your Configuration-Provider: + +```typescript +new Configuration({ + encodeParam: (param: Param) => myFancyParamEncoder(param), +}) +``` + +[parameter-locations-url]: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-locations +[style-values-url]: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values +[@honoluluhenk/http-param-expander]: https://www.npmjs.com/package/@honoluluhenk/http-param-expander diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/api.base.service.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/api.base.service.ts new file mode 100644 index 00000000000..c78251fdde1 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/api.base.service.ts @@ -0,0 +1,83 @@ +/** + * deepobject-query + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { HttpHeaders, HttpParams, HttpParameterCodec } from '@angular/common/http'; +import { CustomHttpParameterCodec } from './encoder'; +import { Configuration } from './configuration'; + +export class BaseService { + protected basePath = 'http://localhost'; + public defaultHeaders = new HttpHeaders(); + public configuration: Configuration; + public encoder: HttpParameterCodec; + + constructor(basePath?: string|string[], configuration?: Configuration) { + this.configuration = configuration || new Configuration(); + if (typeof this.configuration.basePath !== 'string') { + const firstBasePath = Array.isArray(basePath) ? basePath[0] : undefined; + if (firstBasePath != undefined) { + basePath = firstBasePath; + } + + if (typeof basePath !== 'string') { + basePath = this.basePath; + } + this.configuration.basePath = basePath; + } + this.encoder = this.configuration.encoder || new CustomHttpParameterCodec(); + } + + protected canConsumeForm(consumes: string[]): boolean { + return consumes.indexOf('multipart/form-data') !== -1; + } + + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { + // If the value is an object (but not a Date), recursively add its keys. + if (typeof value === 'object' && !(value instanceof Date)) { + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); + } + return this.addToHttpParamsRecursive(httpParams, value, key); + } + + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { + if (value === null || value === undefined) { + return httpParams; + } + if (typeof value === 'object') { + // If JSON format is preferred, key must be provided. + if (key != null) { + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); + } + // Otherwise, if it's an array, add each element. + if (Array.isArray(value)) { + value.forEach(elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key)); + } else if (value instanceof Date) { + if (key != null) { + httpParams = httpParams.append(key, value.toISOString()); + } else { + throw Error("key may not be null if value is Date"); + } + } else { + Object.keys(value).forEach(k => { + const paramKey = key ? `${key}.${k}` : k; + httpParams = this.addToHttpParamsRecursive(httpParams, value[k], paramKey); + }); + } + return httpParams; + } else if (key != null) { + return httpParams.append(key, value); + } + throw Error("key may not be null if value is not object or array"); + } +} diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/api.module.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/api.module.ts new file mode 100644 index 00000000000..58d341fbd2e --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/api.module.ts @@ -0,0 +1,30 @@ +import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core'; +import { Configuration } from './configuration'; +import { HttpClient } from '@angular/common/http'; + + +@NgModule({ + imports: [], + declarations: [], + exports: [], + providers: [] +}) +export class ApiModule { + public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders { + return { + ngModule: ApiModule, + providers: [ { provide: Configuration, useFactory: configurationFactory } ] + }; + } + + constructor( @Optional() @SkipSelf() parentModule: ApiModule, + @Optional() http: HttpClient) { + if (parentModule) { + throw new Error('ApiModule is already loaded. Import in your base AppModule only.'); + } + if (!http) { + throw new Error('You need to import the HttpClientModule in your AppModule! \n' + + 'See also https://github.com/angular/angular/issues/20575'); + } + } +} diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/api/api.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/api/api.ts new file mode 100644 index 00000000000..8e76619647f --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/api/api.ts @@ -0,0 +1,3 @@ +export * from './default.service'; +import { DefaultService } from './default.service'; +export const APIS = [DefaultService]; diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/api/default.service.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/api/default.service.ts new file mode 100644 index 00000000000..0ac4548210b --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/api/default.service.ts @@ -0,0 +1,95 @@ +/** + * deepobject-query + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +/* tslint:disable:no-unused-variable member-ordering */ + +import { Inject, Injectable, Optional } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpParams, + HttpResponse, HttpEvent, HttpParameterCodec, HttpContext + } from '@angular/common/http'; +import { CustomHttpParameterCodec } from '../encoder'; +import { Observable } from 'rxjs'; + +// @ts-ignore +import { Car } from '../model/car'; +// @ts-ignore +import { CarFilter } from '../model/carFilter'; + +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { BaseService } from '../api.base.service'; + + + +@Injectable({ + providedIn: 'root' +}) +export class DefaultService extends BaseService { + + constructor(protected httpClient: HttpClient, @Optional() @Inject(BASE_PATH) basePath: string|string[], @Optional() configuration?: Configuration) { + super(basePath, configuration); + } + + /** + * @param filter + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public getCars(filter?: CarFilter, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'text/plain', context?: HttpContext, transferCache?: boolean}): Observable>; + public getCars(filter?: CarFilter, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'text/plain', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getCars(filter?: CarFilter, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'text/plain', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getCars(filter?: CarFilter, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'text/plain', context?: HttpContext, transferCache?: boolean}): Observable { + + let localVarQueryParameters = new HttpParams({encoder: this.encoder}); + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + filter, 'filter', true); + + let localVarHeaders = this.defaultHeaders; + + const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ + 'text/plain' + ]); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); + + const localVarTransferCache: boolean = options?.transferCache ?? true; + + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/car`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request>('get', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + params: localVarQueryParameters, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + transferCache: localVarTransferCache, + reportProgress: reportProgress + } + ); + } + +} diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/configuration.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/configuration.ts new file mode 100644 index 00000000000..2a128451c08 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/configuration.ts @@ -0,0 +1,184 @@ +import { HttpHeaders, HttpParams, HttpParameterCodec } from '@angular/common/http'; +import { Param } from './param'; + +export interface ConfigurationParameters { + /** + * @deprecated Since 5.0. Use credentials instead + */ + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + /** + * @deprecated Since 5.0. Use credentials instead + */ + accessToken?: string | (() => string); + basePath?: string; + withCredentials?: boolean; + /** + * Takes care of encoding query- and form-parameters. + */ + encoder?: HttpParameterCodec; + /** + * Override the default method for encoding path parameters in various + * styles. + *

+ * See {@link README.md} for more details + *

+ */ + encodeParam?: (param: Param) => string; + /** + * The keys are the names in the securitySchemes section of the OpenAPI + * document. They should map to the value used for authentication + * minus any standard prefixes such as 'Basic' or 'Bearer'. + */ + credentials?: {[ key: string ]: string | (() => string | undefined)}; +} + +export class Configuration { + /** + * @deprecated Since 5.0. Use credentials instead + */ + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + /** + * @deprecated Since 5.0. Use credentials instead + */ + accessToken?: string | (() => string); + basePath?: string; + withCredentials?: boolean; + /** + * Takes care of encoding query- and form-parameters. + */ + encoder?: HttpParameterCodec; + /** + * Encoding of various path parameter + * styles. + *

+ * See {@link README.md} for more details + *

+ */ + encodeParam: (param: Param) => string; + /** + * The keys are the names in the securitySchemes section of the OpenAPI + * document. They should map to the value used for authentication + * minus any standard prefixes such as 'Basic' or 'Bearer'. + */ + credentials: {[ key: string ]: string | (() => string | undefined)}; + +constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: ConfigurationParameters = {}) { + if (apiKeys) { + this.apiKeys = apiKeys; + } + if (username !== undefined) { + this.username = username; + } + if (password !== undefined) { + this.password = password; + } + if (accessToken !== undefined) { + this.accessToken = accessToken; + } + if (basePath !== undefined) { + this.basePath = basePath; + } + if (withCredentials !== undefined) { + this.withCredentials = withCredentials; + } + if (encoder) { + this.encoder = encoder; + } + this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param)); + this.credentials = credentials ?? {}; + } + + /** + * Select the correct content-type to use for a request. + * Uses {@link Configuration#isJsonMime} to determine the correct content-type. + * If no content type is found return the first found type if the contentTypes is not empty + * @param contentTypes - the array of content types that are available for selection + * @returns the selected content-type or undefined if no selection could be made. + */ + public selectHeaderContentType (contentTypes: string[]): string | undefined { + if (contentTypes.length === 0) { + return undefined; + } + + const type = contentTypes.find((x: string) => this.isJsonMime(x)); + if (type === undefined) { + return contentTypes[0]; + } + return type; + } + + /** + * Select the correct accept content-type to use for a request. + * Uses {@link Configuration#isJsonMime} to determine the correct accept content-type. + * If no content type is found return the first found type if the contentTypes is not empty + * @param accepts - the array of content types that are available for selection. + * @returns the selected content-type or undefined if no selection could be made. + */ + public selectHeaderAccept(accepts: string[]): string | undefined { + if (accepts.length === 0) { + return undefined; + } + + const type = accepts.find((x: string) => this.isJsonMime(x)); + if (type === undefined) { + return accepts[0]; + } + return type; + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + public isJsonMime(mime: string): boolean { + const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); + return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); + } + + public lookupCredential(key: string): string | undefined { + const value = this.credentials[key]; + return typeof value === 'function' + ? value() + : value; + } + + public addCredentialToHeaders(credentialKey: string, headerName: string, headers: HttpHeaders, prefix?: string): HttpHeaders { + const value = this.lookupCredential(credentialKey); + return value + ? headers.set(headerName, (prefix ?? '') + value) + : headers; + } + + public addCredentialToQuery(credentialKey: string, paramName: string, query: HttpParams): HttpParams { + const value = this.lookupCredential(credentialKey); + return value + ? query.set(paramName, value) + : query; + } + + private defaultEncodeParam(param: Param): string { + // This implementation exists as fallback for missing configuration + // and for backwards compatibility to older typescript-angular generator versions. + // It only works for the 'simple' parameter style. + // Date-handling only works for the 'date-time' format. + // All other styles and Date-formats are probably handled incorrectly. + // + // But: if that's all you need (i.e.: the most common use-case): no need for customization! + + const value = param.dataFormat === 'date-time' && param.value instanceof Date + ? (param.value as Date).toISOString() + : param.value; + + return encodeURIComponent(String(value)); + } +} diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/encoder.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/encoder.ts new file mode 100644 index 00000000000..138c4d5cf2c --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/encoder.ts @@ -0,0 +1,20 @@ +import { HttpParameterCodec } from '@angular/common/http'; + +/** + * Custom HttpParameterCodec + * Workaround for https://github.com/angular/angular/issues/18261 + */ +export class CustomHttpParameterCodec implements HttpParameterCodec { + encodeKey(k: string): string { + return encodeURIComponent(k); + } + encodeValue(v: string): string { + return encodeURIComponent(v); + } + decodeKey(k: string): string { + return decodeURIComponent(k); + } + decodeValue(v: string): string { + return decodeURIComponent(v); + } +} diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/git_push.sh b/samples/client/petstore/typescript-angular-v19/builds/deep-object/git_push.sh new file mode 100644 index 00000000000..f53a75d4fab --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/git_push.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=$(git remote) +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/index.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/index.ts new file mode 100644 index 00000000000..104dd3d21e3 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/index.ts @@ -0,0 +1,6 @@ +export * from './api/api'; +export * from './model/models'; +export * from './variables'; +export * from './configuration'; +export * from './api.module'; +export * from './param'; diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/model/car.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/model/car.ts new file mode 100644 index 00000000000..fe7337898dc --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/model/car.ts @@ -0,0 +1,17 @@ +/** + * deepobject-query + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface Car { + id?: number; + make?: string; + model?: string; +} + diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/model/carFilter.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/model/carFilter.ts new file mode 100644 index 00000000000..9780e598f00 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/model/carFilter.ts @@ -0,0 +1,16 @@ +/** + * deepobject-query + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface CarFilter { + make?: string; + model?: string; +} + diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/model/models.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/model/models.ts new file mode 100644 index 00000000000..b249b9550ab --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/model/models.ts @@ -0,0 +1,2 @@ +export * from './car'; +export * from './carFilter'; diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/ng-package.json b/samples/client/petstore/typescript-angular-v19/builds/deep-object/ng-package.json new file mode 100644 index 00000000000..3b17900dc9c --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/ng-package.json @@ -0,0 +1,6 @@ +{ + "$schema": "./node_modules/ng-packagr/ng-package.schema.json", + "lib": { + "entryFile": "index.ts" + } +} diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/package.json b/samples/client/petstore/typescript-angular-v19/builds/deep-object/package.json new file mode 100644 index 00000000000..71f619b0dea --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/package.json @@ -0,0 +1,33 @@ +{ + "name": "sample-angular-19-0-0-deep-object", + "version": "1.0.0", + "description": "OpenAPI client for sample-angular-19-0-0-deep-object", + "author": "OpenAPI-Generator Contributors", + "repository": { + "type": "git", + "url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git" + }, + "keywords": [ + "openapi-client", + "openapi-generator" + ], + "license": "Unlicense", + "scripts": { + "build": "ng-packagr -p ng-package.json" + }, + "peerDependencies": { + "@angular/core": "^19.0.0", + "rxjs": "^7.4.0" + }, + "devDependencies": { + "@angular/common": "^19.0.0", + "@angular/compiler": "^19.0.0", + "@angular/compiler-cli": "^19.0.0", + "@angular/core": "^19.0.0", + "@angular/platform-browser": "^19.0.0", + "ng-packagr": "^19.0.0", + "reflect-metadata": "^0.1.3", + "rxjs": "^7.4.0", + "typescript": ">=5.5.0 <5.7.0", + "zone.js": "^0.15.0" + }} diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/param.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/param.ts new file mode 100644 index 00000000000..78a2d20a643 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/param.ts @@ -0,0 +1,69 @@ +/** + * Standard parameter styles defined by OpenAPI spec + */ +export type StandardParamStyle = + | 'matrix' + | 'label' + | 'form' + | 'simple' + | 'spaceDelimited' + | 'pipeDelimited' + | 'deepObject' + ; + +/** + * The OpenAPI standard {@link StandardParamStyle}s may be extended by custom styles by the user. + */ +export type ParamStyle = StandardParamStyle | string; + +/** + * Standard parameter locations defined by OpenAPI spec + */ +export type ParamLocation = 'query' | 'header' | 'path' | 'cookie'; + +/** + * Standard types as defined in OpenAPI Specification: Data Types + */ +export type StandardDataType = + | "integer" + | "number" + | "boolean" + | "string" + | "object" + | "array" + ; + +/** + * Standard {@link DataType}s plus your own types/classes. + */ +export type DataType = StandardDataType | string; + +/** + * Standard formats as defined in OpenAPI Specification: Data Types + */ +export type StandardDataFormat = + | "int32" + | "int64" + | "float" + | "double" + | "byte" + | "binary" + | "date" + | "date-time" + | "password" + ; + +export type DataFormat = StandardDataFormat | string; + +/** + * The parameter to encode. + */ +export interface Param { + name: string; + value: unknown; + in: ParamLocation; + style: ParamStyle, + explode: boolean; + dataType: DataType; + dataFormat: DataFormat | undefined; +} diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/tsconfig.json b/samples/client/petstore/typescript-angular-v19/builds/deep-object/tsconfig.json new file mode 100644 index 00000000000..b3049e9eee6 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, + "target": "es6", + "module": "es6", + "moduleResolution": "node", + "removeComments": true, + "strictNullChecks": true, + "exactOptionalPropertyTypes": true, + "sourceMap": true, + "outDir": "./dist", + "noLib": false, + "declaration": true, + "lib": [ "es6", "dom" ], + "typeRoots": [ + "node_modules/@types" + ] + }, + "exclude": [ + "node_modules", + "dist" + ], + "filesGlob": [ + "./model/*.ts", + "./api/*.ts" + ] +} diff --git a/samples/client/petstore/typescript-angular-v19/builds/deep-object/variables.ts b/samples/client/petstore/typescript-angular-v19/builds/deep-object/variables.ts new file mode 100644 index 00000000000..6fe58549f39 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/builds/deep-object/variables.ts @@ -0,0 +1,9 @@ +import { InjectionToken } from '@angular/core'; + +export const BASE_PATH = new InjectionToken('basePath'); +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} diff --git a/samples/client/petstore/typescript-angular-v19/builds/default/api.base.service.ts b/samples/client/petstore/typescript-angular-v19/builds/default/api.base.service.ts index c81bd085271..e2e57d08322 100644 --- a/samples/client/petstore/typescript-angular-v19/builds/default/api.base.service.ts +++ b/samples/client/petstore/typescript-angular-v19/builds/default/api.base.service.ts @@ -37,22 +37,27 @@ export class BaseService { return consumes.indexOf('multipart/form-data') !== -1; } - protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep: boolean = false): HttpParams { // If the value is an object (but not a Date), recursively add its keys. if (typeof value === 'object' && !(value instanceof Date)) { - return this.addToHttpParamsRecursive(httpParams, value); + return this.addToHttpParamsRecursive(httpParams, value, isDeep ? key : undefined, isDeep); } return this.addToHttpParamsRecursive(httpParams, value, key); } - protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep: boolean = false): HttpParams { if (value === null || value === undefined) { return httpParams; } if (typeof value === 'object') { // If JSON format is preferred, key must be provided. if (key != null) { - return httpParams.append(key, JSON.stringify(value)); + return isDeep + ? Object.keys(value as Record).reduce( + (hp, k) => hp.append(`${key}[${k}]`, value[k]), + httpParams, + ) + : httpParams.append(key, JSON.stringify(value)); } // Otherwise, if it's an array, add each element. if (Array.isArray(value)) { diff --git a/samples/client/petstore/typescript-angular-v19/src/api.spec.ts b/samples/client/petstore/typescript-angular-v19/src/api.spec.ts new file mode 100644 index 00000000000..1b8efe77d76 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v19/src/api.spec.ts @@ -0,0 +1,24 @@ +import { TestBed } from '@angular/core/testing' +import { provideHttpClient } from '@angular/common/http' +import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing' +import { DefaultService } from '@swagger/typescript-angular-deepobject' + +describe('DeepObject Query Param testing', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + providers: [ + provideHttpClient(), + provideHttpClientTesting(), + DefaultService, + ], + }).compileComponents(); + }); + + it('should generate the deepObject query with the correct parameters', async () => { + const httpTesting = TestBed.inject(HttpTestingController); + const carService = TestBed.inject(DefaultService) + carService.getCars({ make: 'bmw', model: '319' }).subscribe() + const req = httpTesting.expectOne('http://localhost/car?filter%5Bmake%5D=bmw&filter%5Bmodel%5D=319') + expect(req.request.method).toEqual('GET') + }); +}); \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular-v19/src/app/app.component.spec.ts b/samples/client/petstore/typescript-angular-v19/src/app/app.component.spec.ts index 18272ecef2a..3098fb8fddb 100644 --- a/samples/client/petstore/typescript-angular-v19/src/app/app.component.spec.ts +++ b/samples/client/petstore/typescript-angular-v19/src/app/app.component.spec.ts @@ -39,4 +39,4 @@ describe('AppComponent', () => { fixture.detectChanges(); expect(fixture.componentInstance.pets![0]).toEqual(pet) }); -}); +}); \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular-v19/tsconfig.json b/samples/client/petstore/typescript-angular-v19/tsconfig.json index 72afd12ed3d..709258e9d55 100644 --- a/samples/client/petstore/typescript-angular-v19/tsconfig.json +++ b/samples/client/petstore/typescript-angular-v19/tsconfig.json @@ -18,7 +18,8 @@ "target": "ES2022", "module": "ES2022", "paths": { - "@swagger/typescript-angular-petstore": ["./builds/default"] + "@swagger/typescript-angular-petstore": ["./builds/default"], + "@swagger/typescript-angular-deepobject": ["./builds/deep-object"] } }, "angularCompilerOptions": {