API for RAML modularization article

This commit is contained in:
Kevin Gilmore
2016-02-06 11:32:12 -06:00
parent 9815254083
commit 0d45b71098
25 changed files with 568 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
#%RAML 1.0 Library
# This is the file /libraries/dataTypes.raml
usage: This library defines the data types for the API
types:
Foo:
properties:
id: integer
name: string
ownerName?: string
Bar:
properties:
id: integer
name: string
city?: string
fooId: integer
Error:
properties:
code: integer
message: string

View File

@@ -0,0 +1,32 @@
#%RAML 1.0 Library
# This is the file /libraries/resourceTypes.raml
usage: This library defines the resource types for the API
uses:
myTraits: !include traits.raml
resourceTypes:
collection:
usage: Use this resourceType to represent a collection of items
description: A collection of <<resourcePathName|!uppercamelcase>>
get:
description: |
Get all <<resourcePathName|!uppercamelcase>>,
optionally filtered
is: [ myTraits.hasResponseCollection ]
post:
description: |
Create a new <<resourcePathName|!uppercamelcase|!singularize>>
is: [ myTraits.hasRequestItem ]
item:
usage: Use this resourceType to represent any single item
description: A single <<typeName>>
get:
description: Get a <<typeName>> by <<resourcePathName>>
is: [ myTraits.hasResponseItem, myTraits.hasNotFound ]
put:
description: Update a <<typeName>> by <<resourcePathName>>
is: [ myTraits.hasRequestItem, myTraits.hasResponseItem, myTraits.hasNotFound ]
delete:
description: Delete a <<typeName>> by <<resourcePathName>>
is: [ myTraits.hasNotFound ]
responses:
204:

View File

@@ -0,0 +1,20 @@
#%RAML 1.0 Library
# This is the file /libraries/securitySchemes.raml
securitySchemes:
- basicAuth:
description: Each request must contain the headers necessary for
basic authentication
type: Basic Authentication
describedBy:
headers:
Authorization:
description: |
Used to send the Base64 encoded "username:password"
credentials
type: string
responses:
401:
description: |
Unauthorized. Either the provided username and password
combination is invalid, or the user is not allowed to
access the content provided by the requested URL.

View File

@@ -0,0 +1,33 @@
#%RAML 1.0 Library
# This is the file /libraries/traits.raml
usage: This library defines some basic traits
traits:
hasRequestItem:
usage: Use this trait for resources whose request body is a single item
body:
application/json:
type: <<typeName>>
hasResponseItem:
usage: Use this trait for resources whose response body is a single item
responses:
200:
body:
application/json:
type: <<typeName>>
example: !include /examples/<<typeName>>.json
hasResponseCollection:
usage: Use this trait for resources whose response body is a collection of items
responses:
200:
body:
application/json:
type: <<typeName>>[]
example: !include /examples/<<typeName|!pluralize>>.json
hasNotFound:
usage: Use this trait for resources that could respond with a 404 status
responses:
404:
body:
application/json:
type: Error
example: !include /examples/Error.json