Skip to content

Commit 276a6cc

Browse files
authored
Update README.md
Add information about model re-use
1 parent 5b6aa4b commit 276a6cc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,39 @@ custom:
222222
type: "string"
223223
```
224224

225+
##### Model re-use
226+
227+
Through the magic of YAML, you can re-use models:
228+
229+
```yml
230+
custom:
231+
documentation:
232+
...
233+
models:
234+
- name: "ErrorResponse"
235+
description: "This is an error"
236+
content:
237+
application/json:
238+
schema: &ErrorItem
239+
type: object
240+
properties:
241+
message:
242+
type: string
243+
code:
244+
type: integer
245+
246+
- name: "PutDocumentResponse"
247+
description: "PUT Document response model (external reference example)"
248+
content:
249+
application/json:
250+
schema:
251+
type: array
252+
items: *ErrorItem
253+
```
254+
255+
`&ErrorItem` in the above example creates a node anchor (&ErrorItem) to the `ErrorResponse` schema which then can be used in the `PutDocumentResponse` schema via the reference (*ErrorItem). The node anchor needs to be declared first before it can be used elsewhere via the reference, swapping the above example around would result in an error.
256+
257+
225258
#### Functions
226259

227260
To define the documentation for a given function event, you need to create a `documentation` attribute for your http event in your `serverless.yml` file.

0 commit comments

Comments
 (0)