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
3131serverless openapi -o openapi.yaml
3232```
3333
34+ or set it via serverless yaml
35+
36+ ``` yml
37+ custom :
38+ openapi :
39+ out : openapi.yaml
40+ ` ` `
41+
3442### Add basic info and tags
3543
3644Under ` custom` add
Original file line number Diff line number Diff line change 11import Serverless from 'serverless' ;
2- import { customProperties } from './lib/custom.properties' ;
2+ import { CustomProperties , customProperties } from './lib/custom.properties' ;
33import { OpenAPIV3 } from 'openapi-types' ;
44import { writeFileSync } from 'fs' ;
55import { functioneventProperties } from './lib/functionEvent.properties' ;
@@ -47,17 +47,19 @@ export class ServerlessPlugin {
4747
4848 this . hooks = {
4949 'openapi:serverless' : this . generate . bind ( this ) ,
50+ 'package:initialize' : this . generate . bind ( this ) ,
5051 } ;
5152 }
5253
5354 private generate ( ) {
5455 this . serverless . cli . log ( 'Generate open api' ) ;
5556 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 ) ;
5760 }
5861
59- private saveToFile ( openApi : OpenAPIV3 . Document ) {
60- let out = 'openapi.json' ;
62+ private saveToFile ( openApi : OpenAPIV3 . Document , out = 'openapi.json' ) {
6163 if ( this . options [ 'out' ] ) {
6264 out = this . options [ 'out' ] ;
6365 }
Original file line number Diff line number Diff line change 11import { 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+ }
214
315export const customProperties : JSONSchema7 = {
416 properties : {
517 openapi : {
618 type : 'object' ,
719 additionalProperties : false ,
820 properties : {
21+ out : {
22+ type : 'string' ,
23+ } ,
924 version : {
1025 type : 'string' ,
1126 } ,
Original file line number Diff line number Diff line change 11import Serverless from 'serverless' ;
2- import { JSONSchema7 } from 'json-schema' ;
32import { OpenAPIV3 } from 'openapi-types' ;
43import { 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' ;
216
227interface HttpEvent {
238 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