@trapi/swagger 0.2.12 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -7
- package/src/config/index.ts +0 -8
- package/src/config/utils/index.ts +0 -8
- package/src/config/utils/validator.ts +0 -94
- package/src/index.ts +0 -12
- package/src/metadata.ts +0 -58
- package/src/specification/abstract.ts +0 -250
- package/src/specification/index.ts +0 -11
- package/src/specification/type.ts +0 -328
- package/src/specification/utils.ts +0 -47
- package/src/specification/v2/index.ts +0 -463
- package/src/specification/v2/type.ts +0 -92
- package/src/specification/v3/index.ts +0 -448
- package/src/specification/v3/type.ts +0 -129
- package/src/type.ts +0 -14
- package/src/utils.ts +0 -28
- package/test/data/metadata.json +0 -1
- package/test/jest.config.js +0 -43
- package/test/tsconfig.json +0 -28
- package/test/unit/index.ts +0 -425
- package/tsconfig.build.json +0 -11
- package/tsconfig.json +0 -9
- package/writable/.gitignore +0 -3
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export namespace Specification {
|
|
9
|
-
export type DataType = 'void' | 'integer' | 'number' | 'boolean' | 'string' | 'array' | 'object' | 'file';
|
|
10
|
-
|
|
11
|
-
export type DataFormat = 'int32' | 'int64' | 'float' | 'double' | 'byte' | 'binary' | 'date' | 'date-time' | 'password';
|
|
12
|
-
|
|
13
|
-
export type Protocol = 'http' | 'https' | 'ws' | 'wss';
|
|
14
|
-
|
|
15
|
-
export interface BaseSpec {
|
|
16
|
-
info: Info;
|
|
17
|
-
tags?: Tag[];
|
|
18
|
-
externalDocs?: ExternalDocs;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface Info {
|
|
22
|
-
title: string;
|
|
23
|
-
version: string;
|
|
24
|
-
description?: string;
|
|
25
|
-
termsOfService?: string;
|
|
26
|
-
contact?: Contact;
|
|
27
|
-
license?: License;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface Contact {
|
|
31
|
-
name?: string;
|
|
32
|
-
email?: string;
|
|
33
|
-
url?: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface License {
|
|
37
|
-
name: string;
|
|
38
|
-
url?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface ExternalDocs {
|
|
42
|
-
url: string;
|
|
43
|
-
description?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface Tag {
|
|
47
|
-
name: string;
|
|
48
|
-
description?: string;
|
|
49
|
-
externalDocs?: ExternalDocs;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface Examples {
|
|
53
|
-
examples?: Record<string, Example>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface Example {
|
|
57
|
-
value: unknown | unknown[];
|
|
58
|
-
summary?: string;
|
|
59
|
-
description?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface BaseParameter<T> {
|
|
63
|
-
name: string;
|
|
64
|
-
in: ParameterInType;
|
|
65
|
-
required?: boolean;
|
|
66
|
-
description?: string;
|
|
67
|
-
example?: unknown;
|
|
68
|
-
examples?: Record<string, Example | string>;
|
|
69
|
-
schema: BaseSchema<T>;
|
|
70
|
-
type?: DataType;
|
|
71
|
-
format?: DataFormat;
|
|
72
|
-
deprecated?: boolean;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface BodyParameter<T> extends BaseParameter<T> {
|
|
76
|
-
in: 'body';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface QueryParameter<T> extends BaseParameter<T> {
|
|
80
|
-
in: 'query';
|
|
81
|
-
allowEmptyValue?: boolean;
|
|
82
|
-
collectionFormat?: CollectionFormat;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface PathParameter<T> extends BaseParameter<T> {
|
|
86
|
-
in: 'path';
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface HeaderParameter<T> extends BaseParameter<T> {
|
|
90
|
-
in: 'header';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface FormDataParameter<T> extends BaseParameter<T> {
|
|
94
|
-
in: 'formData';
|
|
95
|
-
collectionFormat?: CollectionFormat;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export type CollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi';
|
|
99
|
-
|
|
100
|
-
export type ParameterInType = 'query' | 'header' | 'path' | 'formData' | 'body';
|
|
101
|
-
|
|
102
|
-
export type Parameter<T> =
|
|
103
|
-
BodyParameter<T> |
|
|
104
|
-
FormDataParameter<T> |
|
|
105
|
-
QueryParameter<T> |
|
|
106
|
-
PathParameter<T> |
|
|
107
|
-
HeaderParameter<T>;
|
|
108
|
-
|
|
109
|
-
export interface BaseOperation<P, R, S> {
|
|
110
|
-
responses: { [name: string]: R };
|
|
111
|
-
summary?: string;
|
|
112
|
-
description?: string;
|
|
113
|
-
externalDocs?: ExternalDocs;
|
|
114
|
-
operationId?: string;
|
|
115
|
-
consumes?: string[];
|
|
116
|
-
parameters?: P[];
|
|
117
|
-
schemes?: string[];
|
|
118
|
-
deprecated?: boolean;
|
|
119
|
-
security?: S[];
|
|
120
|
-
tags?: string[];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export interface BaseResponse {
|
|
124
|
-
description: string;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export interface BaseSchema<T> {
|
|
128
|
-
type?: DataType | any;
|
|
129
|
-
format?: DataFormat;
|
|
130
|
-
title?: string;
|
|
131
|
-
description?: string;
|
|
132
|
-
default?: string | boolean | number | any;
|
|
133
|
-
multipleOf?: number;
|
|
134
|
-
maximum?: number;
|
|
135
|
-
exclusiveMaximum?: number;
|
|
136
|
-
minimum?: number;
|
|
137
|
-
exclusiveMinimum?: number;
|
|
138
|
-
maxLength?: number;
|
|
139
|
-
minLength?: number;
|
|
140
|
-
pattern?: string;
|
|
141
|
-
maxItems?: number;
|
|
142
|
-
minItems?: number;
|
|
143
|
-
uniqueItems?: boolean;
|
|
144
|
-
maxProperties?: number;
|
|
145
|
-
minProperties?: number;
|
|
146
|
-
enum?: Array<string | number>;
|
|
147
|
-
'x-enum-varnames'?: string[];
|
|
148
|
-
items?: T | BaseSchema<T> | any;
|
|
149
|
-
additionalProperties?: boolean | { [ref: string]: string } | T;
|
|
150
|
-
properties?: { [propertyName: string]: T };
|
|
151
|
-
discriminator?: string;
|
|
152
|
-
readOnly?: boolean;
|
|
153
|
-
xml?: XML;
|
|
154
|
-
externalDocs?: ExternalDocs;
|
|
155
|
-
example?: { [exampleName: string]: Example } | unknown;
|
|
156
|
-
required?: string[];
|
|
157
|
-
$ref?: string;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export interface XML {
|
|
161
|
-
type?: string;
|
|
162
|
-
namespace?: string;
|
|
163
|
-
prefix?: string;
|
|
164
|
-
attribute?: string;
|
|
165
|
-
wrapped?: boolean;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export interface BaseSecurity {
|
|
169
|
-
description?: string;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// tslint:disable-next-line:no-shadowed-variable
|
|
173
|
-
export interface Path<Operation, Parameter> {
|
|
174
|
-
$ref?: string;
|
|
175
|
-
get?: Operation;
|
|
176
|
-
put?: Operation;
|
|
177
|
-
post?: Operation;
|
|
178
|
-
delete?: Operation;
|
|
179
|
-
options?: Operation;
|
|
180
|
-
head?: Operation;
|
|
181
|
-
patch?: Operation;
|
|
182
|
-
parameters?: Parameter[];
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export interface Config {
|
|
186
|
-
/**
|
|
187
|
-
* Support the output to be an yaml file
|
|
188
|
-
*/
|
|
189
|
-
yaml?: boolean;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Generated swagger.{json|yaml} will output here
|
|
193
|
-
*/
|
|
194
|
-
outputDirectory?: string;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Generated documentation base file name. Default: swagger
|
|
198
|
-
*/
|
|
199
|
-
outputFileName?: string;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* API host, expressTemplate.g. localhost:3000 or https://myapi.com
|
|
203
|
-
*/
|
|
204
|
-
host?: string;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* API version number; defaults to npm package version
|
|
208
|
-
*/
|
|
209
|
-
version?: string;
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* API name; defaults to npm package name
|
|
213
|
-
*/
|
|
214
|
-
name?: string;
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* 'API description; defaults to npm package description
|
|
218
|
-
*/
|
|
219
|
-
description?: string;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* API license; defaults to npm package license
|
|
223
|
-
*/
|
|
224
|
-
license?: string;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Base API path; e.g. the 'v1' in https://myapi.com/v1
|
|
228
|
-
*/
|
|
229
|
-
basePath?: string;
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Inform if the generated spec will be in swagger 2.0 format or regarding the open api 3.0 specification.
|
|
233
|
-
*
|
|
234
|
-
* Default: V2
|
|
235
|
-
*/
|
|
236
|
-
specification?: SpecificationOption;
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Extend generated swagger spec with this object
|
|
240
|
-
* Note that generated properties will always take precedence over what get specified here
|
|
241
|
-
*/
|
|
242
|
-
specificationExtra?: Record<string, any>;
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Security Definitions Object
|
|
246
|
-
* A declaration of the security schemes available to be used in the
|
|
247
|
-
* specification. This does not enforce the security schemes on the operations
|
|
248
|
-
* and only serves to provide the relevant details for each scheme.
|
|
249
|
-
*/
|
|
250
|
-
securityDefinitions?: SecurityDefinitions;
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Default consumes property for the entire API
|
|
254
|
-
*/
|
|
255
|
-
consumes?: string[];
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Default produces property for the entire API
|
|
259
|
-
*/
|
|
260
|
-
produces?: string[];
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Default collectionFormat property for query parameters of array type.
|
|
264
|
-
* Possible values are `csv`, `ssv`, `tsv`, `pipes`, `multi`. If not specified, Swagger defaults to `csv`.
|
|
265
|
-
*/
|
|
266
|
-
collectionFormat?: string;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export enum SpecificationOption {
|
|
270
|
-
V2 = "V2",
|
|
271
|
-
V3 = "V3"
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export interface SecurityDefinitions {
|
|
275
|
-
[key: string]: SecurityDefinition;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export type SecurityDefinition = ApiKeySecurity | BasicSecurity | OAuth2Security;
|
|
279
|
-
|
|
280
|
-
export type SecurityType = 'apiKey' | 'http' | 'oauth2';
|
|
281
|
-
|
|
282
|
-
export interface BaseSecurity {
|
|
283
|
-
description?: string;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export interface ApiKeySecurity extends BaseSecurity {
|
|
287
|
-
type: 'apiKey';
|
|
288
|
-
name: string;
|
|
289
|
-
in: 'query' | 'header';
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export interface BasicSecurity extends BaseSecurity {
|
|
293
|
-
type: 'http';
|
|
294
|
-
schema: 'basic';
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export interface OAuth2Security extends BaseSecurity {
|
|
298
|
-
type: 'oauth2';
|
|
299
|
-
flows: {
|
|
300
|
-
implicit?: OAuth2ImplicitFlow,
|
|
301
|
-
password?: OAuth2PasswordFlow,
|
|
302
|
-
authorizationCode?: OAuth2AuthorizationCodeFlow,
|
|
303
|
-
clientCredentials?: OAuth2ClientCredentialsFlow
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export interface Oauth2BaseFlow {
|
|
308
|
-
scopes?: Record<string, string>;
|
|
309
|
-
refreshUrl?: string;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export interface OAuth2ImplicitFlow extends Oauth2BaseFlow {
|
|
313
|
-
authorizationUrl: string;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export interface OAuth2PasswordFlow extends Oauth2BaseFlow {
|
|
317
|
-
tokenUrl: string;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
export interface OAuth2AuthorizationCodeFlow extends Oauth2BaseFlow {
|
|
321
|
-
authorizationUrl: string;
|
|
322
|
-
tokenUrl: string;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export interface OAuth2ClientCredentialsFlow extends Oauth2BaseFlow {
|
|
326
|
-
tokenUrl: string;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// todo: implement character in regex matching
|
|
9
|
-
import {GeneratorOutput, MetadataGenerator} from "@trapi/metadata";
|
|
10
|
-
import {Specification} from "./type";
|
|
11
|
-
import {AbstractSpecGenerator} from "./abstract";
|
|
12
|
-
import {Version2SpecGenerator} from "./v2";
|
|
13
|
-
import {Version3SpecGenerator} from "./v3";
|
|
14
|
-
|
|
15
|
-
export function removeRepeatingCharacter(str: string, character: string) : string {
|
|
16
|
-
return str.replace('/([^:]\$)\/+/g', "$1");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function removeFinalCharacter(str: string, character: string) {
|
|
20
|
-
while(str.charAt(str.length - 1) === character && str.length > 0) {
|
|
21
|
-
str = str.slice(0, -1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return str;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function createSpecGenerator(
|
|
28
|
-
metadata: GeneratorOutput | MetadataGenerator,
|
|
29
|
-
config: Specification.Config = {}
|
|
30
|
-
) {
|
|
31
|
-
const data: GeneratorOutput = metadata instanceof MetadataGenerator ? metadata.generate() : metadata;
|
|
32
|
-
|
|
33
|
-
const outputFormat: Specification.SpecificationOption = config.specification || Specification.SpecificationOption.V2;
|
|
34
|
-
|
|
35
|
-
let specGenerator: AbstractSpecGenerator<any, any>;
|
|
36
|
-
|
|
37
|
-
switch (outputFormat) {
|
|
38
|
-
case Specification.SpecificationOption.V2:
|
|
39
|
-
specGenerator = new Version2SpecGenerator(data, config);
|
|
40
|
-
break;
|
|
41
|
-
case Specification.SpecificationOption.V3:
|
|
42
|
-
specGenerator = new Version3SpecGenerator(data, config);
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return specGenerator;
|
|
47
|
-
}
|