Skip to content

Commit ba15159

Browse files
committed
- Testing multiline descripts for params
- Made client and request vars public
1 parent 58ba24e commit ba15159

File tree

6 files changed

+370
-3
lines changed

6 files changed

+370
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [0.18.0] - 2022-01-28
4+
## [0.18.1] - 2022-01-31
5+
### Fixed
6+
- Escaping error description
7+
- Made `Client.request` and `BaseHttpRequest.config` props public
8+
9+
_## [0.18.0] - 2022-01-28
510
### Added
611
- Angular client generation!
712
- Updated documentation with more examples and better descriptions

src/templates/client.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class {{{clientName}}} {
1818
public readonly {{{camelCase name}}}: {{{name}}}{{{@root.postfix}}};
1919
{{/each}}
2020

21-
private readonly request: BaseHttpRequest;
21+
public readonly request: BaseHttpRequest;
2222

2323
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = {{{httpRequest}}}) {
2424
this.request = new HttpRequest({

src/templates/core/BaseHttpRequest.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { OpenAPIConfig } from './OpenAPI';
66

77
export class BaseHttpRequest {
88

9-
constructor(protected readonly config: OpenAPIConfig) {}
9+
constructor(public readonly config: OpenAPIConfig) {}
1010

1111
public request<T>(options: ApiRequestOptions): CancelablePromise<T> {
1212
throw new Error('Not Implemented');

test/__snapshots__/index.spec.ts.snap

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,86 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`v2 should generate: ./test/generated/v2/client.ts 1`] = `
4+
"/* istanbul ignore file */
5+
/* tslint:disable */
6+
/* eslint-disable */
7+
import type { BaseHttpRequest } from './core/BaseHttpRequest';
8+
import type { OpenAPIConfig } from './core/OpenAPI';
9+
import { FetchHttpRequest } from './core/FetchHttpRequest';
10+
11+
import { CollectionFormatService } from './services/CollectionFormatService';
12+
import { ComplexService } from './services/ComplexService';
13+
import { DefaultService } from './services/DefaultService';
14+
import { DefaultsService } from './services/DefaultsService';
15+
import { DescriptionsService } from './services/DescriptionsService';
16+
import { DuplicateService } from './services/DuplicateService';
17+
import { ErrorService } from './services/ErrorService';
18+
import { HeaderService } from './services/HeaderService';
19+
import { MultipleTags1Service } from './services/MultipleTags1Service';
20+
import { MultipleTags2Service } from './services/MultipleTags2Service';
21+
import { MultipleTags3Service } from './services/MultipleTags3Service';
22+
import { NoContentService } from './services/NoContentService';
23+
import { ParametersService } from './services/ParametersService';
24+
import { ResponseService } from './services/ResponseService';
25+
import { SimpleService } from './services/SimpleService';
26+
import { TypesService } from './services/TypesService';
27+
28+
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
29+
30+
export class DemoAppClient {
31+
32+
public readonly collectionFormat: CollectionFormatService;
33+
public readonly complex: ComplexService;
34+
public readonly default: DefaultService;
35+
public readonly defaults: DefaultsService;
36+
public readonly descriptions: DescriptionsService;
37+
public readonly duplicate: DuplicateService;
38+
public readonly error: ErrorService;
39+
public readonly header: HeaderService;
40+
public readonly multipleTags1: MultipleTags1Service;
41+
public readonly multipleTags2: MultipleTags2Service;
42+
public readonly multipleTags3: MultipleTags3Service;
43+
public readonly noContent: NoContentService;
44+
public readonly parameters: ParametersService;
45+
public readonly response: ResponseService;
46+
public readonly simple: SimpleService;
47+
public readonly types: TypesService;
48+
49+
public readonly request: BaseHttpRequest;
50+
51+
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = FetchHttpRequest) {
52+
this.request = new HttpRequest({
53+
BASE: config?.BASE ?? 'http://localhost:3000/base',
54+
VERSION: config?.VERSION ?? '1.0',
55+
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
56+
CREDENTIALS: config?.CREDENTIALS ?? 'include',
57+
TOKEN: config?.TOKEN,
58+
USERNAME: config?.USERNAME,
59+
PASSWORD: config?.PASSWORD,
60+
HEADERS: config?.HEADERS,
61+
ENCODE_PATH: config?.ENCODE_PATH,
62+
});
63+
64+
this.collectionFormat = new CollectionFormatService(this.request);
65+
this.complex = new ComplexService(this.request);
66+
this.default = new DefaultService(this.request);
67+
this.defaults = new DefaultsService(this.request);
68+
this.descriptions = new DescriptionsService(this.request);
69+
this.duplicate = new DuplicateService(this.request);
70+
this.error = new ErrorService(this.request);
71+
this.header = new HeaderService(this.request);
72+
this.multipleTags1 = new MultipleTags1Service(this.request);
73+
this.multipleTags2 = new MultipleTags2Service(this.request);
74+
this.multipleTags3 = new MultipleTags3Service(this.request);
75+
this.noContent = new NoContentService(this.request);
76+
this.parameters = new ParametersService(this.request);
77+
this.response = new ResponseService(this.request);
78+
this.simple = new SimpleService(this.request);
79+
this.types = new TypesService(this.request);
80+
}
81+
}"
82+
`;
83+
384
exports[`v2 should generate: ./test/generated/v2/core/ApiError.ts 1`] = `
485
"/* istanbul ignore file */
586
/* tslint:disable */
@@ -639,6 +720,7 @@ export { CollectionFormatService } from './services/CollectionFormatService';
639720
export { ComplexService } from './services/ComplexService';
640721
export { DefaultService } from './services/DefaultService';
641722
export { DefaultsService } from './services/DefaultsService';
723+
export { DescriptionsService } from './services/DescriptionsService';
642724
export { DuplicateService } from './services/DuplicateService';
643725
export { ErrorService } from './services/ErrorService';
644726
export { HeaderService } from './services/HeaderService';
@@ -2369,6 +2451,53 @@ export class DefaultsService {
23692451
}"
23702452
`;
23712453

2454+
exports[`v2 should generate: ./test/generated/v2/services/DescriptionsService.ts 1`] = `
2455+
"/* istanbul ignore file */
2456+
/* tslint:disable */
2457+
/* eslint-disable */
2458+
import type { CancelablePromise } from '../core/CancelablePromise';
2459+
import { OpenAPI } from '../core/OpenAPI';
2460+
import { request as __request } from '../core/request';
2461+
2462+
export class DescriptionsService {
2463+
2464+
/**
2465+
* @param parameterWithBreaks Testing multiline comments in string: First line
2466+
* Second line
2467+
*
2468+
* Fourth line
2469+
* @param parameterWithBackticks Testing backticks in string: \`backticks\` and \`\`\`multiple backticks\`\`\` should work
2470+
* @param parameterWithSlashes Testing slashes in string: \\\\backwards\\\\\\\\\\\\ and /forwards/// should work
2471+
* @param parameterWithExpressionPlaceholders Testing expression placeholders in string: \${expression} should work
2472+
* @param parameterWithQuotes Testing quotes in string: 'single quote''' and \\"double quotes\\"\\"\\" should work
2473+
* @param parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work
2474+
* @throws ApiError
2475+
*/
2476+
public static callWithDescriptions(
2477+
parameterWithBreaks?: string,
2478+
parameterWithBackticks?: string,
2479+
parameterWithSlashes?: string,
2480+
parameterWithExpressionPlaceholders?: string,
2481+
parameterWithQuotes?: string,
2482+
parameterWithReservedCharacters?: string,
2483+
): CancelablePromise<void> {
2484+
return __request(OpenAPI, {
2485+
method: 'POST',
2486+
url: '/api/v{api-version}/descriptions/',
2487+
query: {
2488+
'parameterWithBreaks': parameterWithBreaks,
2489+
'parameterWithBackticks': parameterWithBackticks,
2490+
'parameterWithSlashes': parameterWithSlashes,
2491+
'parameterWithExpressionPlaceholders': parameterWithExpressionPlaceholders,
2492+
'parameterWithQuotes': parameterWithQuotes,
2493+
'parameterWithReservedCharacters': parameterWithReservedCharacters,
2494+
},
2495+
});
2496+
}
2497+
2498+
}"
2499+
`;
2500+
23722501
exports[`v2 should generate: ./test/generated/v2/services/DuplicateService.ts 1`] = `
23732502
"/* istanbul ignore file */
23742503
/* tslint:disable */
@@ -2901,6 +3030,99 @@ export class TypesService {
29013030
}"
29023031
`;
29033032

3033+
exports[`v3 should generate: ./test/generated/v3/client.ts 1`] = `
3034+
"/* istanbul ignore file */
3035+
/* tslint:disable */
3036+
/* eslint-disable */
3037+
import type { BaseHttpRequest } from './core/BaseHttpRequest';
3038+
import type { OpenAPIConfig } from './core/OpenAPI';
3039+
import { FetchHttpRequest } from './core/FetchHttpRequest';
3040+
3041+
import { CollectionFormatService } from './services/CollectionFormatService';
3042+
import { ComplexService } from './services/ComplexService';
3043+
import { DefaultService } from './services/DefaultService';
3044+
import { DefaultsService } from './services/DefaultsService';
3045+
import { DescriptionsService } from './services/DescriptionsService';
3046+
import { DuplicateService } from './services/DuplicateService';
3047+
import { ErrorService } from './services/ErrorService';
3048+
import { FormDataService } from './services/FormDataService';
3049+
import { HeaderService } from './services/HeaderService';
3050+
import { MultipartService } from './services/MultipartService';
3051+
import { MultipleTags1Service } from './services/MultipleTags1Service';
3052+
import { MultipleTags2Service } from './services/MultipleTags2Service';
3053+
import { MultipleTags3Service } from './services/MultipleTags3Service';
3054+
import { NoContentService } from './services/NoContentService';
3055+
import { ParametersService } from './services/ParametersService';
3056+
import { RequestBodyService } from './services/RequestBodyService';
3057+
import { ResponseService } from './services/ResponseService';
3058+
import { SimpleService } from './services/SimpleService';
3059+
import { TypesService } from './services/TypesService';
3060+
import { UploadService } from './services/UploadService';
3061+
3062+
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
3063+
3064+
export class DemoAppClient {
3065+
3066+
public readonly collectionFormat: CollectionFormatService;
3067+
public readonly complex: ComplexService;
3068+
public readonly default: DefaultService;
3069+
public readonly defaults: DefaultsService;
3070+
public readonly descriptions: DescriptionsService;
3071+
public readonly duplicate: DuplicateService;
3072+
public readonly error: ErrorService;
3073+
public readonly formData: FormDataService;
3074+
public readonly header: HeaderService;
3075+
public readonly multipart: MultipartService;
3076+
public readonly multipleTags1: MultipleTags1Service;
3077+
public readonly multipleTags2: MultipleTags2Service;
3078+
public readonly multipleTags3: MultipleTags3Service;
3079+
public readonly noContent: NoContentService;
3080+
public readonly parameters: ParametersService;
3081+
public readonly requestBody: RequestBodyService;
3082+
public readonly response: ResponseService;
3083+
public readonly simple: SimpleService;
3084+
public readonly types: TypesService;
3085+
public readonly upload: UploadService;
3086+
3087+
public readonly request: BaseHttpRequest;
3088+
3089+
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = FetchHttpRequest) {
3090+
this.request = new HttpRequest({
3091+
BASE: config?.BASE ?? 'http://localhost:3000/base',
3092+
VERSION: config?.VERSION ?? '1.0',
3093+
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
3094+
CREDENTIALS: config?.CREDENTIALS ?? 'include',
3095+
TOKEN: config?.TOKEN,
3096+
USERNAME: config?.USERNAME,
3097+
PASSWORD: config?.PASSWORD,
3098+
HEADERS: config?.HEADERS,
3099+
ENCODE_PATH: config?.ENCODE_PATH,
3100+
});
3101+
3102+
this.collectionFormat = new CollectionFormatService(this.request);
3103+
this.complex = new ComplexService(this.request);
3104+
this.default = new DefaultService(this.request);
3105+
this.defaults = new DefaultsService(this.request);
3106+
this.descriptions = new DescriptionsService(this.request);
3107+
this.duplicate = new DuplicateService(this.request);
3108+
this.error = new ErrorService(this.request);
3109+
this.formData = new FormDataService(this.request);
3110+
this.header = new HeaderService(this.request);
3111+
this.multipart = new MultipartService(this.request);
3112+
this.multipleTags1 = new MultipleTags1Service(this.request);
3113+
this.multipleTags2 = new MultipleTags2Service(this.request);
3114+
this.multipleTags3 = new MultipleTags3Service(this.request);
3115+
this.noContent = new NoContentService(this.request);
3116+
this.parameters = new ParametersService(this.request);
3117+
this.requestBody = new RequestBodyService(this.request);
3118+
this.response = new ResponseService(this.request);
3119+
this.simple = new SimpleService(this.request);
3120+
this.types = new TypesService(this.request);
3121+
this.upload = new UploadService(this.request);
3122+
}
3123+
}"
3124+
`;
3125+
29043126
exports[`v3 should generate: ./test/generated/v3/core/ApiError.ts 1`] = `
29053127
"/* istanbul ignore file */
29063128
/* tslint:disable */
@@ -3564,6 +3786,7 @@ export { CollectionFormatService } from './services/CollectionFormatService';
35643786
export { ComplexService } from './services/ComplexService';
35653787
export { DefaultService } from './services/DefaultService';
35663788
export { DefaultsService } from './services/DefaultsService';
3789+
export { DescriptionsService } from './services/DescriptionsService';
35673790
export { DuplicateService } from './services/DuplicateService';
35683791
export { ErrorService } from './services/ErrorService';
35693792
export { FormDataService } from './services/FormDataService';
@@ -5883,6 +6106,53 @@ export class DefaultsService {
58836106
}"
58846107
`;
58856108

6109+
exports[`v3 should generate: ./test/generated/v3/services/DescriptionsService.ts 1`] = `
6110+
"/* istanbul ignore file */
6111+
/* tslint:disable */
6112+
/* eslint-disable */
6113+
import type { CancelablePromise } from '../core/CancelablePromise';
6114+
import { OpenAPI } from '../core/OpenAPI';
6115+
import { request as __request } from '../core/request';
6116+
6117+
export class DescriptionsService {
6118+
6119+
/**
6120+
* @param parameterWithBreaks Testing multiline comments in string: First line
6121+
* Second line
6122+
*
6123+
* Fourth line
6124+
* @param parameterWithBackticks Testing backticks in string: \`backticks\` and \`\`\`multiple backticks\`\`\` should work
6125+
* @param parameterWithSlashes Testing slashes in string: \\\\backwards\\\\\\\\\\\\ and /forwards/// should work
6126+
* @param parameterWithExpressionPlaceholders Testing expression placeholders in string: \${expression} should work
6127+
* @param parameterWithQuotes Testing quotes in string: 'single quote''' and \\"double quotes\\"\\"\\" should work
6128+
* @param parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work
6129+
* @throws ApiError
6130+
*/
6131+
public static callWithDescriptions(
6132+
parameterWithBreaks?: any,
6133+
parameterWithBackticks?: any,
6134+
parameterWithSlashes?: any,
6135+
parameterWithExpressionPlaceholders?: any,
6136+
parameterWithQuotes?: any,
6137+
parameterWithReservedCharacters?: any,
6138+
): CancelablePromise<void> {
6139+
return __request(OpenAPI, {
6140+
method: 'POST',
6141+
url: '/api/v{api-version}/descriptions/',
6142+
query: {
6143+
'parameterWithBreaks': parameterWithBreaks,
6144+
'parameterWithBackticks': parameterWithBackticks,
6145+
'parameterWithSlashes': parameterWithSlashes,
6146+
'parameterWithExpressionPlaceholders': parameterWithExpressionPlaceholders,
6147+
'parameterWithQuotes': parameterWithQuotes,
6148+
'parameterWithReservedCharacters': parameterWithReservedCharacters,
6149+
},
6150+
});
6151+
}
6152+
6153+
}"
6154+
`;
6155+
58866156
exports[`v3 should generate: ./test/generated/v3/services/DuplicateService.ts 1`] = `
58876157
"/* istanbul ignore file */
58886158
/* tslint:disable */

test/spec/v2.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,52 @@
6060
"operationId": "PatchCallWithoutParametersAndResponse"
6161
}
6262
},
63+
"/api/v{api-version}/descriptions/": {
64+
"post": {
65+
"tags": [
66+
"Descriptions"
67+
],
68+
"operationId": "CallWithDescriptions",
69+
"parameters": [
70+
{
71+
"description": "Testing multiline comments in string: First line\nSecond line\n\nFourth line",
72+
"name": "parameterWithBreaks",
73+
"in": "query",
74+
"type": "string"
75+
},
76+
{
77+
"description": "Testing backticks in string: `backticks` and ```multiple backticks``` should work",
78+
"name": "parameterWithBackticks",
79+
"in": "query",
80+
"type": "string"
81+
},
82+
{
83+
"description": "Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work",
84+
"name": "parameterWithSlashes",
85+
"in": "query",
86+
"type": "string"
87+
},
88+
{
89+
"description": "Testing expression placeholders in string: ${expression} should work",
90+
"name": "parameterWithExpressionPlaceholders",
91+
"in": "query",
92+
"type": "string"
93+
},
94+
{
95+
"description": "Testing quotes in string: 'single quote''' and \"double quotes\"\"\" should work",
96+
"name": "parameterWithQuotes",
97+
"in": "query",
98+
"type": "string"
99+
},
100+
{
101+
"description": "Testing reserved characters in string: /* inline */ and /** inline **/ should work",
102+
"name": "parameterWithReservedCharacters",
103+
"in": "query",
104+
"type": "string"
105+
}
106+
]
107+
}
108+
},
63109
"/api/v{api-version}/parameters/{parameterPath}": {
64110
"post": {
65111
"tags": [

0 commit comments

Comments
 (0)