Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CI/circle_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increased Node version as tests were failing due to Angular refusing to compile on NodeJS versions <18. Node 18 is required for all currently supported Angular versions (docs).

node --version

# Each step uses the same `$BASH_ENV`, so need to modify it
Expand All @@ -91,6 +91,7 @@ elif [ "$NODE_INDEX" = "3" ]; then
(cd samples/client/petstore/typescript-angular-v17-provided-in-root && mvn integration-test)
(cd samples/client/petstore/typescript-angular-v18-provided-in-root && mvn integration-test)
(cd samples/client/petstore/typescript-angular-v19-provided-in-root && mvn integration-test)
(cd samples/client/others/typescript-angular-deep-object && mvn integration-test)
(cd samples/openapi3/client/petstore/typescript/builds/default && mvn integration-test)
(cd samples/openapi3/client/petstore/typescript/tests/default && mvn integration-test)
(cd samples/openapi3/client/petstore/typescript/builds/jquery && mvn integration-test)
Expand Down
11 changes: 11 additions & 0 deletions bin/configs/typescript-angular-deep-object.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: typescript-angular
outputDir: samples/client/others/typescript-angular-deep-object/builds/default
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.1
supportsES6: true
tsVersion: 5.6.3
zonejsVersion: 0.15.0
ngPackagrVersion: 19.0.1
rxjsVersion: 6.5.3
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,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.entries(value as Record<string, any>).reduce(
(hp, [k, v]) => hp.append(`${key}[${k}]`, v),
httpParams,
)
: httpParams.append(key, JSON.stringify(value));
}
// Otherwise, if it's an array, add each element.
if (Array.isArray(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class {{classname}} extends BaseService {
{{/isArray}}
{{^isArray}}
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
<any>{{paramName}}, '{{baseName}}');
<any>{{paramName}}, '{{baseName}}'{{#isDeepObject}}, true{{/isDeepObject}});
{{/isArray}}
{{/queryParams}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,29 @@ public void testEnumAsConst() throws IOException {
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("<any>options, 'options', true);");
Comment thread
filiptc marked this conversation as resolved.
assertThat(fileContents).containsOnlyOnce("<any>inputOptions, 'inputOptions', true);");
}
}
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions samples/client/others/typescript-angular-deep-object/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.

# Compiled output
/dist
/tmp
/out-tsc
/bazel-out

# Node
/node_modules
npm-debug.log
yarn-error.log

# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# Miscellaneous
/.angular/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings

# System files
.DS_Store
Thumbs.db
96 changes: 96 additions & 0 deletions samples/client/others/typescript-angular-deep-object/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"typescript-angular-deep-object-tests": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/typescript-angular-deep-object-tests",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kB",
"maximumError": "1MB"
},
{
"type": "anyComponentStyle",
"maximumWarning": "4kB",
"maximumError": "8kB"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "typescript-angular-deep-object-tests:build:production"
},
"development": {
"buildTarget": "typescript-angular-deep-object-tests:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": [
"src/styles.css"
],
"scripts": []
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wwwroot/*.js
node_modules
typings
dist
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.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
param.ts
variables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.13.0-SNAPSHOT
Loading
Loading