@trapi/swagger 0.2.3 → 0.2.7

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.
Files changed (39) hide show
  1. package/README.MD +4 -815
  2. package/dist/config/utils/validator.d.ts.map +1 -1
  3. package/dist/config/utils/validator.js +6 -3
  4. package/dist/config/utils/validator.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/metadata.d.ts +4 -0
  10. package/dist/metadata.d.ts.map +1 -0
  11. package/dist/metadata.js +13 -0
  12. package/dist/metadata.js.map +1 -0
  13. package/dist/specification/abstract.js +46 -43
  14. package/dist/specification/abstract.js.map +1 -1
  15. package/dist/specification/type.d.ts +10 -8
  16. package/dist/specification/type.d.ts.map +1 -1
  17. package/dist/specification/type.js +6 -6
  18. package/dist/specification/type.js.map +1 -1
  19. package/dist/specification/utils.d.ts.map +1 -1
  20. package/dist/specification/utils.js +3 -3
  21. package/dist/specification/utils.js.map +1 -1
  22. package/dist/specification/v2/index.js +7 -20
  23. package/dist/specification/v2/index.js.map +1 -1
  24. package/dist/specification/v3/index.js +7 -22
  25. package/dist/specification/v3/index.js.map +1 -1
  26. package/dist/utils.d.ts +9 -0
  27. package/dist/utils.d.ts.map +1 -0
  28. package/dist/utils.js +31 -0
  29. package/dist/utils.js.map +1 -0
  30. package/package.json +9 -6
  31. package/src/config/utils/validator.ts +8 -3
  32. package/src/index.ts +1 -0
  33. package/src/metadata.ts +24 -0
  34. package/src/specification/type.ts +11 -9
  35. package/src/specification/utils.ts +6 -6
  36. package/src/specification/v2/index.ts +2 -2
  37. package/src/specification/v3/index.ts +2 -2
  38. package/src/utils.ts +28 -0
  39. package/test/unit/index.ts +1 -0
package/README.MD CHANGED
@@ -12,27 +12,6 @@ Please read the `CHANGELOG.md` in the repository for breaking changes.
12
12
  **Table of Contents**
13
13
 
14
14
  - [Installation](#installation)
15
- - [Build](#build)
16
- - [CLI](#cli)
17
- - [Runtime](#runtime)
18
- - [Limitations](#limitations)
19
- - [Usage](#usage)
20
- - [General](#general)
21
- - [Build-In](#buildin)
22
- - [@ResponseDescription](#responsedescription)
23
- - [@ResponseExample](#responseexample)
24
- - [@ResponseProduces](#responseproduces)
25
- - [@RequestConsumes](#requestconsumes)
26
- - [@SwaggerTags](#swaggertags)
27
- - [@SwaggerHidden](#swaggerhidden)
28
- - [@IsInt, @IsLong, @IsFloat, @IsDouble](#isint-islong-isfloat-isdouble)
29
- - [SwaggerConfig (swagger-config.json)](#swagger-configjson)
30
- - [DecoratorConfig](#decoratorconfig)
31
- - [SecurityDefinition](#securitydefinition)
32
- - [Decorator(s)](#decorators)
33
- - [TypeRepresentationMapping](#typerepresentationmapping-trm)
34
- - [Specification](#specification)
35
- - [Credits](#credits)
36
15
 
37
16
  ## Installation
38
17
 
@@ -40,799 +19,9 @@ Please read the `CHANGELOG.md` in the repository for breaking changes.
40
19
  npm install --save @trapi/swagger
41
20
  ```
42
21
 
43
- ## Build
22
+ ---
23
+ **Important NOTE**
44
24
 
45
- You can either build the `swagger.yml` and `swagger.json` file by command line or on runtime of your application.
46
- The files will be generated in the `outputDirectory` specified in the `SwaggerConfig`.
25
+ The `Readme.md` is under construction at the moment. So please stay patient, till it is available ⭐.
47
26
 
48
- The [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file contains the compilerOptions, which
49
- are required for this library to work. The compilerOptions could look lke the following example:
50
-
51
- ```json
52
- {
53
- "compilerOptions": {
54
- "baseUrl": ".",
55
- "paths": {
56
- "@/*": ["src/*"]
57
- }
58
- }
59
- }
60
- ```
61
- In case of the above configuration, the library can understand relative imports like `import something from '@/something'`.
62
-
63
- ### CLI
64
-
65
- ```bash
66
- swagger-generate -c ./swagger-config.json
67
- swagger-generate -c ./swagger-config.js #.js files are also allowed as config files
68
- swagger-generate -c ./swagger-config.json -t true # load {cwd}/tsconfig.json
69
- swagger-generate -c ./swagger-config.json -t false # don't load tsconfig.json
70
- swagger-generate -c ./swagger-config.json -t ./tsconfig.json # load custom tsconfig.json
71
- ```
72
-
73
- Where the [swagger-config.json](#swagger-configjson) file, contains settings about the swagger generation. For example:
74
-
75
- ```json
76
- {
77
- "decorator": {
78
- "useBuildIn": true,
79
- "useLibrary": ["typescript-rest", "@decorators/express"]
80
- },
81
- "swagger": {
82
- "outputDirectory": "./dist",
83
- "entryFile": "./tests/data/apis.ts"
84
- }
85
- }
86
- ```
87
-
88
- ### Runtime
89
-
90
- ```typescript
91
- import {Config, generateDocumentation} from "typescript-swagger";
92
-
93
- const packageJson = require('package.json');
94
- const tsConfig = require('tsconfig.json');
95
-
96
- export const config: Config = {
97
- decorator: {
98
- useBuildIn: true,
99
- useLibrary: ["typescript-rest", "@decorators/express"],
100
- },
101
- swagger: {
102
- yaml: true,
103
- name: 'API - Documentation',
104
- description: packageJson.description,
105
- basePath: '/',
106
- version: packageJson.version,
107
- outputDirectory: 'public',
108
- entryFile: path.join('src', 'controllers', '**', '*.ts'),
109
- ignore: ['**/node_modules/**'],
110
- consumes: ['application/json'],
111
- produces: ['application/json']
112
- }
113
- }
114
-
115
- export async function generateSwaggerDocumentation(): Promise<void> {
116
- await generateDocumentation(config, tsConfig);
117
- }
118
- ```
119
-
120
- ### Limitations
121
-
122
- You can use pretty any type you have declared in your code. The only restriction are types form third party modules.
123
-
124
- Also the following built in typescript utility types are supported:
125
- * NonNullable
126
- * Omit
127
- * Partial
128
- * Readonly
129
- * Record
130
- * Required
131
- * Pick
132
-
133
- ## Usage
134
-
135
- ### General
136
-
137
- The documentation will be generated consulting all decorators present on your code.
138
-
139
- Which decorator will be used, depends on your [swagger-config.json](#swagger-configjson).
140
- However, there are some additional information that only can be provided, through some third party decorator or your own defined representations.
141
-
142
- To cover all functions the following decorators packs are supported by default:
143
- * build-in
144
- * [typescript-rest](https://github.com/thiagobustamante/typescript-rest)
145
- * [@decorators/express](https://github.com/serhiisol/node-decorators)
146
-
147
- You can override the used decorator packs in you [swagger-config.json](#swagger-configjson).
148
-
149
- In the following there are two specific examples in combination with the third party libraries: typescript-rest and @decorators/express.
150
-
151
- #### typescript-rest
152
- ```typescript
153
- import {Path, Accept, GET} from 'typescript-rest';
154
- import {SwaggerTags} from 'typescript-swagger';
155
-
156
- interface Person {
157
- id: number;
158
- name: string;
159
- avatar: string;
160
- password: string;
161
- }
162
-
163
- @Path('mypath')
164
- export class MyService {
165
- @GET
166
- @SwaggerTags('adminMethod', 'otherTag')
167
- @Accept('text/html')
168
- test( ): string {
169
- return 'OK';
170
- }
171
-
172
- @GET
173
- @Path('secondpath')
174
- test2( @QueryParam('testParam')test?: string ): Pick<Person, 'name' | 'avatar'> {
175
- return {name: 'OK'};
176
- }
177
- }
178
- ```
179
-
180
- #### @decorators/express
181
- ```typescript
182
- import {Controller, Get, Query} from '@decorators/express';
183
- import {SwaggerTags} from 'typescript-swagger';
184
-
185
- interface Person {
186
- id: number;
187
- name: string;
188
- avatar: string;
189
- password: string;
190
- }
191
-
192
- @Controller('mypath')
193
- export class MyService {
194
- @Get('')
195
- @SwaggerTags('adminMethod', 'otherTag')
196
- test( ): string {
197
- return res.send('Ok');
198
- }
199
-
200
- @Get('secondpath')
201
- test2( @Query('testParam')test?: string ): Pick<Person, 'name' | 'avatar'> {
202
- return res.json({name: 'OK'});
203
- }
204
- }
205
- ```
206
-
207
- It is also important to notice that all JsDoc (Comments, Tags, ...) provided on your methods, classes, and parameters have influence on the generated swagger file:
208
-
209
- ```typescript
210
- @Accept('text/plain')
211
- @Path('mypath')
212
- export class MyService {
213
- /**
214
- * This description will be used to describe the get operation of path '/mypath' on the generated swagger
215
- * @param test And this will describe the parameter test of this same operation
216
- */
217
- @GET
218
- @Path('secondpath')
219
- test2( @QueryParam('testParam')test?: string ): Person {
220
- return {name: 'OK'};
221
- }
222
- }
223
- ```
224
- ### BuildIn
225
-
226
- The provided swagger decorator representations by this library, are listed in the following sections.
227
-
228
- #### @ResponseDescription
229
-
230
- A decorator to document the responses that a given service method can return. It is used to generate documentation for the REST service.
231
-
232
- ```typescript
233
- interface MyError {
234
- message: string
235
- }
236
-
237
- @Path('people')
238
- class PeopleService {
239
- @ResponseDescription<string>(200, 'Retrieve a list of people.')
240
- @ResponseDescription<MyError>(401, 'The user is unauthorized.', {message: 'The user is not authorized to access this operation.'})
241
- @GET
242
- getPeople(@Param('name') name: string) {
243
- // ...
244
- }
245
- }
246
- ```
247
-
248
- A Default response is already created in swagger documentation from the method return analisys. So any response declared
249
- through this decorator is an additional response created.
250
-
251
- #### @ResponseExample
252
-
253
- Used to provide an example of method return to be added into the method response section of the generated documentation for this method.
254
-
255
- ```typescript
256
- @Path('people')
257
- class PeopleService {
258
- @ResponseExample<Array<Person>>([{
259
- name: 'Joe'
260
- }])
261
- @GET
262
- getPeople(@Param('name') name: string): Person[] {
263
- // ...
264
- }
265
- }
266
- ```
267
-
268
- #### @ResponseProduces
269
-
270
- Document the produces property in generated swagger docs
271
-
272
- ```typescript
273
- @Path('people')
274
- @ResponseProduces('text/html')
275
- class PeopleService {
276
- @GET
277
- getPeople(@Param('name') name: string) {
278
- // ...
279
- }
280
- }
281
- ```
282
-
283
- A Default produces is already created in swagger documentation from the method return analisys.
284
- You can use this decorator to override this default produces.
285
-
286
- #### @RequestConsumes
287
-
288
- Document the consumes property in generated swagger docs
289
-
290
- ```typescript
291
- @Path('people')
292
- @RequestConsumes('text/html')
293
- class PeopleService {
294
- @PUT
295
- createPeople(@Param('name') name: string, people: People) {
296
- // ...
297
- }
298
- }
299
- ```
300
-
301
- #### @SwaggerTags
302
-
303
- Add tags for a given method on generated swagger documentation.
304
-
305
- ```typescript
306
- @Path('people')
307
- class PeopleService {
308
- @SwaggerTags('adiministrative', 'department1')
309
- @GET
310
- getPeople(@Param('name') name: string) {
311
- // ...
312
- }
313
- }
314
- ```
315
-
316
- #### @SwaggerHidden
317
-
318
- Allow to hide some APIs from swagger docs (ex: test or dev APIs, etc ...).
319
- This decorator can be applied for the whole class or only a single method
320
-
321
- ```typescript
322
- @Path('people')
323
- @SwaggerHidden()
324
- class PeopleService {
325
- @GET
326
- getPeople(@Param('name') name: string) {
327
- // ...
328
- }
329
- }
330
- ```
331
-
332
- #### @IsInt, @IsLong, @IsFloat, @IsDouble
333
-
334
- Document the type of a `number` property or parameter in generated swagger docs.
335
- If no decorator is present, the `number` type defaults to `double` format.
336
-
337
- ```typescript
338
- class Person {
339
- @IsInt id: number;
340
- }
341
-
342
- @Path('people')
343
- class PeopleService {
344
- @Path(':id')
345
- @GET
346
- getById(@PathParam('id') @IsLong id: number) {
347
- // ...
348
- }
349
- }
350
- ```
351
-
352
- Because decorators don't work on type and interface properties, this can also be specified as a JSDoc tag.
353
-
354
- ```typescript
355
- interface Person {
356
- /**
357
- * The person's id
358
- * @IsInt
359
- */
360
- id: number;
361
- }
362
- ```
363
-
364
-
365
- ### Swagger-config.json
366
-
367
- The `decorator` property object of the config file can have the following properties:
368
-
369
- ```typescript
370
- import {Decorator} from 'typescript-swagger';
371
-
372
- export namespace Decorator {
373
- // ...
374
- export type Config = {
375
- useLibrary? : Decorator.Library | Array<Decorator.Library> | Record<Library, ID> | Record<Decorator.Library, Decorator.Representation>;
376
- useBuildIn? : boolean | Array<Decorator.ID> | Record<Decorator.ID, boolean> | Decorator.ID;
377
- override? : Decorator.Representation;
378
- };
379
- // ...
380
- }
381
- ```
382
-
383
- Please read the [TypeRepresentationMapping (TRM)](#typerepresentationmapping-trm) section for further information to provide
384
- valid values to override or extend library or build-in TRMs.
385
-
386
- The `swagger` property object of the config file on the other hand supports the following properties:
387
-
388
- Property | Type | Default | Description
389
- -------- | ---- | ----- | -----------
390
- basePath | string | `"/"` | Base API path; e.g. the 'v1' in https://myapi.com/v1
391
- collectionFormat | string | `"csv"` | Default collectionFormat property for the entire API. Possible values are `csv`, `ssv`, `tsv`, `pipes`, `multi`. If not specified, Swagger defaults to `csv`.
392
- consumes | [string] | `[]` | Default consumes property for the entire API
393
- description | string | | API description; defaults to npm package description
394
- entryFile | string or string[] | `[]` | The entry point to your API (it is possible to use glob patters)
395
- host | string | | The hostname to be informed in the generated swagger file
396
- license | string | | API license number; defaults to npm package license
397
- name | string | | API name; defaults to npm package name
398
- outputDirectory | string | | Where to write the generated swagger file
399
- outputFormat | 'Swagger_2' or 'OpenApi_3' | `"Swagger_2"` | Inform if the generated spec will be in swagger 2.0 format or i open api 3.0
400
- produces | [string] | | Default produces property for the entire API
401
- spec | any | | Extend generated swagger spec with this object. Note that generated properties will always take precedence over what get specified here
402
- securityDefinitions | *SecurityDefinition | | Security Definitions Object. A declaration of the security schemes available to be used in the specification. This does not enforce the security schemes on the operations and only serves to provide the relevant details for each scheme.
403
- version | string | `0.0.1` | API version number; defaults to npm package version
404
- yaml | boolean | `true` | Generates the output also as a yaml file
405
-
406
-
407
- #### SecurityDefinition
408
- Where the SecurityDefinition contract is defined as:
409
- ```typescript
410
- export type SecureDefinition = {
411
- [name: string]: {
412
- type: string;
413
- name?: string;
414
- authorizationUrl?: string;
415
- tokenUrl?: string;
416
- flow?: string;
417
- in?: string;
418
- scopes?: { [scopeName: string]: string; }
419
- }
420
- }
421
- ```
422
-
423
- #### Example
424
-
425
- See an example:
426
- ```json
427
- {
428
- "decorator": {
429
- "useBuildIn": true,
430
- "useLibrary": [
431
- "typescript-rest",
432
- "@decorators/express"
433
- ]
434
- },
435
- "swagger": {
436
- "outputDirectory": "./dist",
437
- "entryFile": "./controllers/*.ts",
438
- "outputFormat": "openapi_3",
439
- "host": "localhost:3000",
440
- "version": "1.0",
441
- "name": "Typescript-rest Test API",
442
- "description": "a description",
443
- "license": "MIT",
444
- "basePath": "/v1",
445
- "securityDefinitions": {
446
- "api_key": {
447
- "type": "apiKey",
448
- "name": "access_token",
449
- "in": "query"
450
- }
451
- },
452
- "ignore": [
453
- "**/node_modules/**"
454
- ]
455
- }
456
- }
457
- ```
458
-
459
- or in yaml format:
460
- See an example:
461
-
462
- ```yaml
463
- decorator:
464
- useBuildIn: true
465
- useLibrary:
466
- - @decorators/express
467
- - typescript-rest
468
- swagger:
469
- outputDirectory: ./dist
470
- entryFile:
471
- - ./controllers/*.ts
472
- outputFormat: openapi_3
473
- host: localhost:3000
474
- version: 1.0
475
- name: Typescript-rest Test API
476
- description: A description
477
- license: MIT
478
- basePath: /v1
479
- securityDefinitions:
480
- api_key:
481
- type: apiKey
482
- name: access_token
483
- in: query
484
- ignore:
485
- - /node_modules/**
486
- ```
487
-
488
- ## Decorator(s)
489
-
490
- The information which are required to generate swagger documentations are collected by consulting decorators present on your code.
491
- Few decorator `Type-Representation-Mappings` ([TRMs](#typerepresentationmapping-trm)) are already provided by this library and can also be disabled.
492
- `TRMs` by third party libraries (f.e @decorators/express or typescript-rest) can be extended/replaced as well.
493
- You can also deposit your own DTRMs.
494
-
495
- In the following sections, the decorator which can be represented is called: `Type`.
496
- The decorator the configuration (name/text, properties, ...) is called: `Representation`.
497
- DTRMs must be declared and implemented according the requirements ([Specification](#specification)) for the respective decorator.
498
-
499
- ### TypeRepresentationMapping (TRM)
500
-
501
- The following snippet, shows how the mapping between decorator `Type`s and the respective `Representation`s should look like.
502
-
503
- ```typescript
504
- type TypeRepresentationMapping = Record<Type, Representation | Representation[]>;
505
- ```
506
-
507
- The `Type` can have one of the following values: SWAGGER_TAGS, CLASS_PATH, ... [see more]().
508
-
509
- The `Representation` is defined as described in the following:
510
- ```typescript
511
- interface Representation {
512
- id: string;
513
- properties?: Property[]
514
- }
515
- ```
516
- The `id` attribute is representative for the actual decorator text/name.
517
-
518
- For a few decorators the library expects different properties. How these properties/information
519
- are available, should be provided by the `properties` attribute of the representation config.
520
-
521
- ```typescript
522
- export type PropertyType = 'PAYLOAD' | 'STATUS_CODE' | 'DESCRIPTION' | 'OPTIONS' | 'SIMPLE' | 'TYPE';
523
- export interface Property {
524
- /**
525
- * Default: 'SIMPLE'
526
- */
527
- type?: PropertyType;
528
- /**
529
- * Default: 'argument'
530
- */
531
- declaredAs?: 'argument' | 'typeArgument';
532
- /**
533
- * Default: one
534
- */
535
- amount?: 'one' | 'all';
536
- /**
537
- * Default: 0
538
- */
539
- position?: number;
540
- }
541
- ```
542
-
543
- If an attribute (type, declaredAs, amount, position) is not defined the default value(s) will be applied.
544
-
545
- Which `PropertyType(s)` are available for a given decorator is described in the ([Specification](#specification)) section.
546
- In case for the build-in decorators the representation is defined as follows:
547
- ```typescript
548
- import {Decorator} from 'typescript-swagger';
549
-
550
- const representation: Decorator.TypeRepresentationMapping = {
551
- /**
552
- * ID: SWAGGER_TAGS
553
- * RepresentationConfig: {
554
- * name: 'SwaggerTags',
555
- * properties: [...]
556
- * }
557
- */
558
- SWAGGER_TAGS: {
559
- name: 'SwaggerTags',
560
- properties: [{amount: 'all', declaredAs: "argument"}]
561
- },
562
-
563
- // Class + Method
564
- RESPONSE_EXAMPLE: {
565
- name: 'ResponseExample',
566
- properties: [
567
- {type: "TYPE", declaredAs: "typeArgument"},
568
- {type: "PAYLOAD", declaredAs: "argument"}
569
- ]
570
- },
571
- RESPONSE_DESCRIPTION: {
572
- name: 'ResponseDescription',
573
- properties: [
574
- {type: "TYPE", declaredAs: "typeArgument"},
575
- {type: "STATUS_CODE", declaredAs: "argument", position: 0},
576
- {type: "DESCRIPTION", declaredAs: "argument", position: 1},
577
- {type: "PAYLOAD", declaredAs: "argument", position: 2}
578
- ]
579
- },
580
- REQUEST_CONSUMES: {
581
- name: 'RequestConsumes',
582
- properties: [{amount: 'all', declaredAs: "argument"}]
583
- },
584
- RESPONSE_PRODUCES: {
585
- name: 'ResponseProduces',
586
- properties: [{amount: 'all', declaredAs: "argument"}]
587
- },
588
- SWAGGER_HIDDEN: {
589
- name: 'SwaggerHidden',
590
- properties: []
591
- },
592
-
593
- IS_INT: {
594
- name: 'IsInt',
595
- properties: []
596
- },
597
- IS_LONG: {
598
- name: 'IsLong',
599
- properties: []
600
- },
601
- IS_FlOAT: {
602
- name: 'IsFloat',
603
- properties: []
604
- },
605
- IS_DOUBLE: {
606
- name: 'IsDouble',
607
- properties: []
608
- },
609
- SERVER_FILES_PARAM: {
610
- name: 'RequestFileParam',
611
- properties: [{}]
612
- },
613
- SERVER_FILE_PARAM: {
614
- name: 'RequestFileParam',
615
- properties: [{}]
616
- },
617
- };
618
-
619
- export default representation;
620
- ```
621
- ### Specification
622
-
623
- How you can reference decorators, is described in the following.
624
-
625
- #### SWAGGER_HIDDEN
626
- Target:
627
- - Class
628
- - Method
629
-
630
- Properties:
631
-
632
- Example:
633
- - Decorator: `@SwaggerHidden()`
634
- - Representation:
635
- ```json
636
- {
637
- "SWAGGER_HIDDEN": {
638
- "name": "SwaggerHidden",
639
- "properties": []
640
- }
641
- }
642
- ```
643
-
644
- #### SWAGGER_TAGS
645
- Target:
646
- - Class
647
- - Method
648
-
649
- Properties:
650
- - SIMPLE:
651
- - Type: string | Array<string>
652
- - Description: assign the endpoint to one or more swagger tags.
653
-
654
- Example:
655
- - Decorator: `@SwaggerTags('tag-one')`, `@SwaggerTags('tag-one', 'tag-two')`
656
- - Representation:
657
- ```json
658
- {
659
- "SWAGGER_TAGS": {
660
- "name": "SwaggerTags",
661
- "properties": [
662
- {"amount": "all", "declaredAs": "argument"}
663
- ]
664
- }
665
- }
666
- ```
667
-
668
- #### CLASS_PATH
669
- Target:
670
- - Class
671
-
672
- Properties:
673
- - SIMPLE:
674
- - Type: string
675
- - Description: base path for methods in class
676
-
677
- Example:
678
- - Decorator: `@Path('/path')`
679
- - Representation:
680
- ```json
681
- {
682
- "CLASS_PATH": {
683
- "name": "Path",
684
- "properties": [
685
- {"amount": "one", "declaredAs": "argument"}
686
- ]
687
- }
688
- }
689
- ```
690
-
691
- #### REQUEST_CONSUMES
692
- Target:
693
- - Class
694
- - Method
695
-
696
- Properties:
697
- - SIMPLE:
698
- - Type: string | Array<string>
699
- - Description: supported media type(s) for request.
700
-
701
- Example:
702
- - Decorator: `@RequestConsumes('application/json')`, `@RequestConsumes('application/json', 'text/html')`
703
- - Representation:
704
- ```json
705
- {
706
- "REQUEST_CONSUMES": {
707
- "name": "RequestConsumes",
708
- "properties": [
709
- {"amount": "all", "declaredAs": "argument"}
710
- ]
711
- }
712
- }
713
- ```
714
-
715
- #### RESPONSE_DESCRIPTION
716
- Target:
717
- - Class
718
- - Method
719
-
720
- Properties:
721
- - TYPE:
722
- - Type: any
723
- - Description: (typescript) type of the example
724
- - STATUS_CODE:
725
- - Type: number
726
- - Description: response status code (f.e 200)
727
- - DESCRIPTION:
728
- - Type: string
729
- - Description: response description
730
- - PAYLOAD:
731
- - Type: any
732
- - Description: example value or error of the description
733
-
734
- Example:
735
- - Decorator: `@ResponseDescription<{name: string}>(200, 'Return object with name attribute.', '{name: 'Peter'})`
736
- - Representation
737
- ```json
738
- {
739
- "RESPONSE_DESCRIPTION": {
740
- "name": "ResponseDescription",
741
- "properties": [
742
- {"type": "TYPE", "declaredAs": "typeArgument"},
743
- {"type": "STATUS_CODE", "declaredAs": "argument", "position": 0},
744
- {"type": "DESCRIPTION", "declaredAs": "argument", "position": 1},
745
- {"type": "PAYLOAD", "declaredAs": "argument", "position": 2}
746
- ]
747
- }
748
- }
749
- ```
750
-
751
- #### RESPONSE_EXAMPLE
752
- Target:
753
- - Class
754
- - Method
755
-
756
- Properties:
757
- - TYPE:
758
- - Type: any
759
- - Description: (typescript) type of the example
760
- - PAYLOAD:
761
- - Type: any
762
- - Description: value of the example
763
-
764
- Example:
765
- - Decorator: `@ResponseExample<{name: string}>({name: 'Peter'})`
766
- - Representation:
767
- ```json
768
- {
769
- "RESPONSE_EXAMPLE": {
770
- "name": "Path",
771
- "properties": [
772
- {"type": "TYPE", "declaredAs": "typeArgument"},
773
- {"type": "PAYLOAD", "declaredAs": "argument"}
774
- ]
775
- }
776
- }
777
- ```
778
-
779
- #### RESPONSE_PRODUCES
780
- Target:
781
- - Class
782
- - Method
783
-
784
- Properties:
785
- - SIMPLE:
786
- - Type: string | Array<string>
787
- - Description: media type(s) available for a response message
788
-
789
- Example:
790
- - Decorator: `@ResponseProduces('application/json')`, `@ResponseProduces('application/json', 'text/html')`
791
- - Representation:
792
- ```json
793
- {
794
- "RESPONSE_PRODUCES": {
795
- "name": "ResponseProduces",
796
- "properties": [
797
- {"amount": "all", "declaredAs": "argument"}
798
- ]
799
- }
800
- }
801
- ```
802
-
803
- #### METHOD_PATH
804
- Target:
805
- - Method
806
-
807
- Properties:
808
- - SIMPLE:
809
- - Type: string
810
- - Description: additional path specification to class path.
811
-
812
- Example:
813
- - Decorator: `@Path('/path')`
814
- - Representation:
815
- ```json
816
- {
817
- "METHOD_PATH": {
818
- "name": "Path",
819
- "properties": [
820
- {"amount": "one", "declaredAs": "argument"}
821
- ]
822
- }
823
- }
824
- ```
825
- According to this schema you can:
826
- - provide your own decorators used for route generation.
827
- - override representations for a third party library
828
- (f.e [typescript-rest](https://github.com/thiagobustamante/typescript-rest)
829
- or
830
- [@decorators/express](https://github.com/serhiisol/node-decorators))
831
-
832
- How to provide the representation for decorators is described in the section of the [swagger-config.json](#swagger-configjson).
833
-
834
- ### Credits
835
-
836
- Parts of this package **@trapi/swagger** code rest on a continued fork repository ([typescript-swagger](https://github.com/Tada5hi/typescript-swagger)) of the
837
- [typescript-rest-swagger](https://github.com/thiagobustamante/typescript-rest-swagger) library of [thiagobustamante](https://github.com/thiagobustamante)
838
- and was also inspired by the [tsoa](https://github.com/lukeautry/tsoa) library of [lukeatury](https://github.com/lukeautry).
27
+ ---