Skip to content

Commit 5876723

Browse files
typescript-angular: Add query param JSON test
1 parent fc0c5ab commit 5876723

File tree

28 files changed

+1105
-0
lines changed

28 files changed

+1105
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: typescript-angular
2+
outputDir: samples/client/others/typescript-angular-v20/builds/query-param-json
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/query-param-json.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/typescript-angular
5+
additionalProperties:
6+
ngVersion: 20.0.0
7+
npmName: sample-angular-20-0-0-query-param-json
8+
supportsES6: true
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
openapi: 3.0.3
2+
info:
3+
title: query-param-json-test
4+
version: 1.0.0
5+
paths:
6+
/search:
7+
get:
8+
operationId: search
9+
parameters:
10+
- in: query
11+
name: filter
12+
description: Filter
13+
required: false
14+
content:
15+
application/json:
16+
schema:
17+
$ref: '#/components/schemas/Filter'
18+
19+
responses:
20+
'200':
21+
description: Ok
22+
content:
23+
application/json:
24+
schema:
25+
$ref: '#/components/schemas/Response'
26+
27+
components:
28+
schemas:
29+
Item:
30+
type: object
31+
required:
32+
- name
33+
- age
34+
properties:
35+
name:
36+
type: string
37+
description: The name
38+
age:
39+
type: integer
40+
minimum: 0
41+
default: 5
42+
nullable: false
43+
description: The age
44+
45+
Response:
46+
type: object
47+
required:
48+
- items
49+
properties:
50+
items:
51+
type: array
52+
description: Array of items.
53+
nullable: false
54+
items:
55+
$ref: '#/components/schemas/Item'
56+
57+
Filter:
58+
type: object
59+
properties:
60+
ids:
61+
type: array
62+
items:
63+
type: number
64+
name:
65+
type: string
66+
description: The name
67+
age:
68+
type: integer
69+
minimum: 0
70+
default: 5
71+
nullable: false
72+
description: The age
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
wwwroot/*.js
2+
node_modules
3+
typings
4+
dist
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.gitignore
2+
README.md
3+
api.base.service.ts
4+
api.module.ts
5+
api/api.ts
6+
api/default.service.ts
7+
configuration.ts
8+
encoder.ts
9+
git_push.sh
10+
index.ts
11+
model/filter.ts
12+
model/item.ts
13+
model/models.ts
14+
model/response.ts
15+
ng-package.json
16+
package.json
17+
param.ts
18+
provide-api.ts
19+
tsconfig.json
20+
variables.ts
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.16.0-SNAPSHOT
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
2+
3+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4+
5+
The version of the OpenAPI document: 1.0.0
6+
7+
## Building
8+
9+
To install the required dependencies and to build the typescript sources run:
10+
11+
```console
12+
npm install
13+
npm run build
14+
```
15+
16+
## Publishing
17+
18+
First build the package then run `npm publish dist` (don't forget to specify the `dist` folder!)
19+
20+
## Consuming
21+
22+
Navigate to the folder of your consuming project and run one of next commands.
23+
24+
_published:_
25+
26+
```console
27+
npm install [email protected] --save
28+
```
29+
30+
_without publishing (not recommended):_
31+
32+
```console
33+
npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save
34+
```
35+
36+
_It's important to take the tgz file, otherwise you'll get trouble with links on windows_
37+
38+
_using `npm link`:_
39+
40+
In PATH_TO_GENERATED_PACKAGE/dist:
41+
42+
```console
43+
npm link
44+
```
45+
46+
In your project:
47+
48+
```console
49+
npm link sample-angular-20-0-0-query-param-json
50+
```
51+
52+
__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
53+
Please refer to this issue <https://github.com/angular/angular-cli/issues/8284> for a solution / workaround.
54+
Published packages are not effected by this issue.
55+
56+
### General usage
57+
58+
In your Angular project:
59+
60+
```typescript
61+
62+
import { ApplicationConfig } from '@angular/core';
63+
import { provideHttpClient } from '@angular/common/http';
64+
import { provideApi } from 'sample-angular-20-0-0-query-param-json';
65+
66+
export const appConfig: ApplicationConfig = {
67+
providers: [
68+
// ...
69+
provideHttpClient(),
70+
provideApi()
71+
],
72+
};
73+
```
74+
75+
**NOTE**
76+
If you're still using `AppModule` and haven't [migrated](https://angular.dev/reference/migrations/standalone) yet, you can still import an Angular module:
77+
```typescript
78+
import { ApiModule } from 'sample-angular-20-0-0-query-param-json';
79+
```
80+
81+
If different from the generated base path, during app bootstrap, you can provide the base path to your service.
82+
83+
```typescript
84+
import { ApplicationConfig } from '@angular/core';
85+
import { provideHttpClient } from '@angular/common/http';
86+
import { provideApi } from 'sample-angular-20-0-0-query-param-json';
87+
88+
export const appConfig: ApplicationConfig = {
89+
providers: [
90+
// ...
91+
provideHttpClient(),
92+
provideApi('http://localhost:9999')
93+
],
94+
};
95+
```
96+
97+
```typescript
98+
// with a custom configuration
99+
import { ApplicationConfig } from '@angular/core';
100+
import { provideHttpClient } from '@angular/common/http';
101+
import { provideApi } from 'sample-angular-20-0-0-query-param-json';
102+
103+
export const appConfig: ApplicationConfig = {
104+
providers: [
105+
// ...
106+
provideHttpClient(),
107+
provideApi({
108+
withCredentials: true,
109+
username: 'user',
110+
password: 'password'
111+
})
112+
],
113+
};
114+
```
115+
116+
```typescript
117+
// with factory building a custom configuration
118+
import { ApplicationConfig } from '@angular/core';
119+
import { provideHttpClient } from '@angular/common/http';
120+
import { provideApi, Configuration } from 'sample-angular-20-0-0-query-param-json';
121+
122+
export const appConfig: ApplicationConfig = {
123+
providers: [
124+
// ...
125+
provideHttpClient(),
126+
{
127+
provide: Configuration,
128+
useFactory: (authService: AuthService) => new Configuration({
129+
basePath: 'http://localhost:9999',
130+
withCredentials: true,
131+
username: authService.getUsername(),
132+
password: authService.getPassword(),
133+
}),
134+
deps: [AuthService],
135+
multi: false
136+
}
137+
],
138+
};
139+
```
140+
141+
### Using multiple OpenAPI files / APIs
142+
143+
In order to use multiple APIs generated from different OpenAPI files,
144+
you can create an alias name when importing the modules
145+
in order to avoid naming conflicts:
146+
147+
```typescript
148+
import { provideApi as provideUserApi } from 'my-user-api-path';
149+
import { provideApi as provideAdminApi } from 'my-admin-api-path';
150+
import { HttpClientModule } from '@angular/common/http';
151+
import { environment } from '../environments/environment';
152+
153+
export const appConfig: ApplicationConfig = {
154+
providers: [
155+
// ...
156+
provideHttpClient(),
157+
provideUserApi(environment.basePath),
158+
provideAdminApi(environment.basePath),
159+
],
160+
};
161+
```
162+
163+
### Customizing path parameter encoding
164+
165+
Without further customization, only [path-parameters][parameter-locations-url] of [style][style-values-url] 'simple'
166+
and Dates for format 'date-time' are encoded correctly.
167+
168+
Other styles (e.g. "matrix") are not that easy to encode
169+
and thus are best delegated to other libraries (e.g.: [@honoluluhenk/http-param-expander]).
170+
171+
To implement your own parameter encoding (or call another library),
172+
pass an arrow-function or method-reference to the `encodeParam` property of the Configuration-object
173+
(see [General Usage](#general-usage) above).
174+
175+
Example value for use in your Configuration-Provider:
176+
177+
```typescript
178+
new Configuration({
179+
encodeParam: (param: Param) => myFancyParamEncoder(param),
180+
})
181+
```
182+
183+
[parameter-locations-url]: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-locations
184+
[style-values-url]: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
185+
[@honoluluhenk/http-param-expander]: https://www.npmjs.com/package/@honoluluhenk/http-param-expander

0 commit comments

Comments
 (0)