File tree Expand file tree Collapse file tree 5 files changed +38
-21
lines changed
packages/serverless-openapi Expand file tree Collapse file tree 5 files changed +38
-21
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ If you want to change the format (json or yaml) or the file name use
31
31
serverless openapi -o openapi.yaml
32
32
```
33
33
34
+ or set it via serverless yaml
35
+
36
+ ``` yml
37
+ custom :
38
+ openapi :
39
+ out : openapi.yaml
40
+ ` ` `
41
+
34
42
### Add basic info and tags
35
43
36
44
Under ` custom` add
Original file line number Diff line number Diff line change 1
1
import Serverless from 'serverless' ;
2
- import { customProperties } from './lib/custom.properties' ;
2
+ import { CustomProperties , customProperties } from './lib/custom.properties' ;
3
3
import { OpenAPIV3 } from 'openapi-types' ;
4
4
import { writeFileSync } from 'fs' ;
5
5
import { functioneventProperties } from './lib/functionEvent.properties' ;
@@ -47,17 +47,19 @@ export class ServerlessPlugin {
47
47
48
48
this . hooks = {
49
49
'openapi:serverless' : this . generate . bind ( this ) ,
50
+ 'package:initialize' : this . generate . bind ( this ) ,
50
51
} ;
51
52
}
52
53
53
54
private generate ( ) {
54
55
this . serverless . cli . log ( 'Generate open api' ) ;
55
56
const openApi = new Generator ( ) . generate ( this . serverless ) ;
56
- this . saveToFile ( openApi ) ;
57
+ const customOpenApi = this . serverless . service . custom
58
+ . openapi as CustomProperties ;
59
+ this . saveToFile ( openApi , customOpenApi . out ) ;
57
60
}
58
61
59
- private saveToFile ( openApi : OpenAPIV3 . Document ) {
60
- let out = 'openapi.json' ;
62
+ private saveToFile ( openApi : OpenAPIV3 . Document , out = 'openapi.json' ) {
61
63
if ( this . options [ 'out' ] ) {
62
64
out = this . options [ 'out' ] ;
63
65
}
Original file line number Diff line number Diff line change 1
1
import { JSONSchema7 } from 'json-schema' ;
2
+ import { Schema } from './response.types' ;
3
+
4
+ export interface CustomProperties {
5
+ out ?: string ;
6
+ version : string ;
7
+ title : string ;
8
+ description ?: string ;
9
+ tags ?: { name : string ; description ?: string } [ ] ;
10
+ defaultResponse ?: {
11
+ 'application/json' : Schema ;
12
+ } ;
13
+ }
2
14
3
15
export const customProperties : JSONSchema7 = {
4
16
properties : {
5
17
openapi : {
6
18
type : 'object' ,
7
19
additionalProperties : false ,
8
20
properties : {
21
+ out : {
22
+ type : 'string' ,
23
+ } ,
9
24
version : {
10
25
type : 'string' ,
11
26
} ,
Original file line number Diff line number Diff line change 1
1
import Serverless from 'serverless' ;
2
- import { JSONSchema7 } from 'json-schema' ;
3
2
import { OpenAPIV3 } from 'openapi-types' ;
4
3
import { HttpMethod } from 'serverless/plugins/aws/package/compile/events/apiGateway/lib/validate' ;
5
-
6
- interface Schema {
7
- schema ?: JSONSchema7 ;
8
- name : string ;
9
- description ?: string ;
10
- }
11
-
12
- interface CustomProperties {
13
- version : string ;
14
- title : string ;
15
- description ?: string ;
16
- tags ?: { name : string ; description ?: string } [ ] ;
17
- defaultResponse ?: {
18
- 'application/json' : Schema ;
19
- } ;
20
- }
4
+ import { Schema } from './response.types' ;
5
+ import { CustomProperties } from './custom.properties' ;
21
6
22
7
interface HttpEvent {
23
8
path : string ;
Original file line number Diff line number Diff line change
1
+ import { JSONSchema7 } from 'json-schema' ;
2
+
3
+ export interface Schema {
4
+ schema ?: JSONSchema7 ;
5
+ name : string ;
6
+ description ?: string ;
7
+ }
You can’t perform that action at this time.
0 commit comments