Skip to content

Commit 91452f5

Browse files
authored
Merge branch 'master' into feature/stream-file-param-decorator
2 parents cb45ed9 + 67663ea commit 91452f5

26 files changed

+2816
-3587
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ node_modules
77
coverage
88
*.log
99
npm-debug.log*
10+
.idea

README.MD

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ This is a tool to generate swagger files from a [typescript-rest](https://github
88

99
**Table of Contents**
1010

11-
- [Swagger for Typescript-Rest](#)
11+
- [Swagger for Typescript-rest](#swagger-for-typescript-rest)
1212
- [Installation](#installation)
1313
- [Usage](#usage)
1414
- [Swagger Decorators](#swagger-decorators)
1515
- [@Response](#response)
1616
- [@Example](#example)
1717
- [@Tags](#tags)
18-
- [@Security](#security)
1918
- [@Produces](#produces)
19+
- [@IsInt, @IsLong, @IsFloat, @IsDouble](#isint-islong-isfloat-isdouble)
2020
- [SwaggerConfig.json](#swaggerconfigjson)
2121

2222
## Installation
@@ -29,6 +29,8 @@ npm install typescript-rest-swagger -g
2929

3030
```bash
3131
swaggerGen -c ./swaggerConfig.json
32+
swaggerGen -c ./swaggerConfig.json -t # load {cwd}/tsconfig.json
33+
swaggerGen -c ./swaggerConfig.json -p ./tsconfig.json # load custom tsconfig.json
3234
```
3335

3436
Where the [swaggerConfig.json](#swaggerconfigjson) file, contains settings about the swagger generation. For example:
@@ -42,6 +44,21 @@ Where the [swaggerConfig.json](#swaggerconfigjson) file, contains settings about
4244
}
4345
```
4446

47+
Where the [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file contains compilerOptions. For example:
48+
49+
```json
50+
{
51+
"compilerOptions": {
52+
"baseUrl": ".",
53+
"paths": {
54+
"@/*": ["src/*"]
55+
}
56+
}
57+
}
58+
```
59+
60+
For example above options are required for `swaggerGen` to understand relative imports like `import something from '@/something'`.
61+
4562
### Swagger Decorators
4663

4764
The documentation will be generated consulting all [typescript-rest](https://github.com/thiagobustamante/typescript-rest) decorators present on your code.
@@ -145,23 +162,6 @@ class PeopleService {
145162
}
146163
```
147164

148-
#### @Security
149-
150-
Add a security constraint to method generated docs, referencing the security name from securityDefinitions.
151-
`@Security` can be used at the controller and method level; if defined on both, method security overwrites controller security.
152-
Multiple security schemes may be specified to require all of them.
153-
154-
```typescript
155-
@Path('people')
156-
class PeopleService {
157-
@Security('api_key')
158-
@GET
159-
getPeople(@Param('name') name: string) {
160-
// ...
161-
}
162-
}
163-
```
164-
165165

166166
#### @Produces
167167

@@ -223,7 +223,8 @@ Property | Type | Description
223223
basePath | string | Base API path; e.g. the 'v1' in https://myapi.com/v1
224224
consumes | [string] | Default consumes property for the entire API
225225
description | string | API description; defaults to npm package description
226-
entryFile | string | The entry point to your API
226+
entryFile | string or string[] | The entry point to your API (it is possible to use glob patters)
227+
outputFormat | 'Swagger_2' or 'OpenApi_3' | Inform if the generated spec will be in swagger 2.0 format or i open api 3.0
227228
host | string | The hostname to be informed in the generated swagger file
228229
license | string | API license number; defaults to npm package license
229230
name | string | API name; defaults to npm package name
@@ -256,7 +257,8 @@ See an example:
256257
{
257258
"swagger": {
258259
"outputDirectory": "./dist",
259-
"entryFile": "./tests/data/apis.ts",
260+
"entryFile": "./controllers/*.ts",
261+
"outputFormat": "openapi_3",
260262
"host": "localhost:3000",
261263
"version": "1.0",
262264
"name": "Typescript-rest Test API",
@@ -269,7 +271,34 @@ See an example:
269271
"name": "access_token",
270272
"in": "query"
271273
}
272-
}
274+
},
275+
"ignore": [
276+
"**/node_modules/**"
277+
]
273278
}
274279
}
275280
```
281+
282+
or in yaml format:
283+
See an example:
284+
285+
```yaml
286+
swagger:
287+
outputDirectory: ./dist
288+
entryFile:
289+
- ./controllers/*.ts
290+
outputFormat: openapi_3
291+
host: localhost:3000
292+
version: 1.0
293+
name: Typescript-rest Test API
294+
description: A description
295+
license: MIT
296+
basePath: /v1
297+
securityDefinitions:
298+
api_key:
299+
type: apiKey
300+
name: access_token
301+
in: query
302+
ignore:
303+
- /node_modules/**
304+
```

0 commit comments

Comments
 (0)