Skip to content

Commit dcc3341

Browse files
committed
feat(serverless-openapi): add parameters
1 parent 4282d57 commit dcc3341

File tree

5 files changed

+381
-328
lines changed

5 files changed

+381
-328
lines changed

README.md

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -19,90 +19,6 @@ plugins:
1919
- '@nightapes/serverless-openapi'
2020
```
2121
22-
To generate api run
22+
## Documentation
2323
24-
```bash
25-
serverless openapi
26-
```
27-
28-
If you want to change the format (json or yaml) or the file name use
29-
30-
```bash
31-
serverless openapi -o openapi.yaml
32-
```
33-
34-
## Add basic info and tags
35-
36-
Under `custom` add
37-
38-
```yml
39-
custom:
40-
openapi:
41-
title: 'my fancy openapi'
42-
version: '1.0.0'
43-
description: 'My description of the serverless api'
44-
tags:
45-
- name: Settings
46-
description: Description
47-
```
48-
49-
## Example for request and response schema
50-
51-
Works only for aws http events, the request is the default serverless request schema.
52-
53-
```yml
54-
events:
55-
- http:
56-
path: v1/user-settings
57-
method: put
58-
tags:
59-
- Settings
60-
authorizer:
61-
name: authorizer
62-
scopes:
63-
- admin
64-
operationId: setUserSettings
65-
cors: true
66-
request:
67-
schemas:
68-
application/json:
69-
schema: ${file(./your-schema.json)}
70-
name: UserSettings
71-
responseSchemas:
72-
200:
73-
application/json:
74-
schema: ${file(./your-schema.json)}
75-
name: UserSettings
76-
description: 'UserSettings'
77-
204:
78-
application/json:
79-
description: 'OK'
80-
```
81-
82-
## Default respsonse
83-
84-
You can set a default response via
85-
86-
```yml
87-
custom:
88-
openapi:
89-
defaultResponse:
90-
application/json:
91-
schema: ${file(./apiError.type.json)}
92-
description: 'Default api error'
93-
name: ApiError
94-
```
95-
96-
Enable the default response per function via
97-
98-
```yml
99-
events:
100-
- http:
101-
path: v1/user-settings
102-
defaultResponse: true
103-
```
104-
105-
## TODO
106-
107-
- Servers
108-
- Authorizer
24+
A detailed documentation can be found [here](/packages/serverless-openapi/README.md)

packages/serverless-openapi/README.md

Lines changed: 98 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,22 @@ Add plugin into your `serverless.yml` file
1616

1717
```yml
1818
plugins:
19-
- serverless-openapi
19+
- '@nightapes/serverless-openapi'
2020
```
2121
22-
## Add basic info
22+
To generate api run
23+
24+
```bash
25+
serverless openapi
26+
```
27+
28+
If you want to change the format (json or yaml) or the file name use
29+
30+
```bash
31+
serverless openapi -o openapi.yaml
32+
```
33+
34+
### Add basic info and tags
2335

2436
Under `custom` add
2537

@@ -29,37 +41,95 @@ custom:
2941
title: 'my fancy openapi'
3042
version: '1.0.0'
3143
description: 'My description of the serverless api'
44+
tags:
45+
- name: Settings
46+
description: Description
3247
```
3348
34-
## Example for request and response schema
49+
### Example for request and response schema
50+
51+
Works only for aws http events, the request is the default serverless request schema.
52+
53+
```yml
54+
functions:
55+
create:
56+
handler: posts.create
57+
events:
58+
- http:
59+
path: v1/user-settings
60+
method: put
61+
tags:
62+
- Settings
63+
authorizer:
64+
name: authorizer
65+
scopes:
66+
- admin
67+
operationId: setUserSettings
68+
cors: true
69+
request:
70+
schemas:
71+
application/json:
72+
schema: ${file(./your-schema.json)}
73+
name: UserSettings
74+
responseSchemas:
75+
200:
76+
application/json:
77+
schema: ${file(./your-schema.json)}
78+
name: UserSettings
79+
description: 'UserSettings'
80+
204:
81+
application/json:
82+
description: 'OK'
83+
```
84+
85+
### Default respsonse
86+
87+
You can set a default response via
88+
89+
```yml
90+
custom:
91+
openapi:
92+
defaultResponse:
93+
application/json:
94+
schema: ${file(./apiError.type.json)}
95+
description: 'Default api error'
96+
name: ApiError
97+
```
98+
99+
Enable the default response per function via
100+
101+
```yml
102+
functions:
103+
create:
104+
handler: posts.create
105+
events:
106+
- http:
107+
path: v1/user-settings
108+
defaultResponse: true
109+
```
110+
111+
### Parameters
112+
113+
Following format to add paramters is supported. See [SLS Doc](https://www.serverless.com/framework/docs/providers/aws/events/apigateway#request-parameters)
35114
36-
Works only for http events, the request is the default serverless request schema.
115+
All parameters will be interpreted as `string`
37116

38117
```yml
39-
events:
40-
- http:
41-
path: v1/user-settings
42-
method: put
43-
authorizer:
44-
name: authorizer
45-
scopes:
46-
- admin
47-
operationId: setUserSettings
48-
cors: true
49-
request:
50-
schemas:
51-
application/json:
52-
schema: ${file(./your-schema.json)}
53-
name: UserSettings
54-
responseSchemas:
55-
200:
56-
application/json:
57-
schema: ${file(./your-schema.json)}
58-
name: UserSettings
59-
description: 'UserSettings'
60-
204:
61-
application/json:
62-
description: 'OK'
118+
functions:
119+
create:
120+
handler: posts.create
121+
events:
122+
- http:
123+
path: posts/create
124+
method: post
125+
request:
126+
parameters:
127+
querystrings:
128+
url: true
129+
headers:
130+
foo: false
131+
paths:
132+
bar: false
63133
```
64134

65135
## TODO

0 commit comments

Comments
 (0)