Traits in RAML | Traits in RAML Mule
A trait, like a method, can provide method-level nodes such as description, headers, query string parameters, and responses. Methods that use one or more traits inherit nodes of those traits. A resource and resource type can also use, and thus inherit from, one or more traits, which then apply to all methods of the resource and resource type. Traits are related to methods through a mixing pattern.
Below is the example of RAML containing traits. A library is a collection of traits where traits are defined under "traits" keyword, as shown in example below. Here there are 3 traits are defined that are mentioned below:
1. client-id-required
2. client-secret-required
3. errors
#%RAML 1.0 Library
usage: collection of traits
traits:
client-id-required:
headers:
client_id:
type: string
minLength: 4
maxLength: 12
required: true
description: client id & client secret is required for authentication purpose.
client-secret-required:
headers:
client_secret:
type: string
minLength: 4
maxLength: 12
required: true
description: client id & client secret is required for authentication purpose.
errors:
responses:
401:
body:
application/json:
example: {
"error" : "unauthorized access"
}
404:
body:
application/json:
example: {
"error" : "URL not found"
}
405:
body:
application/json:
example: {
"error" : "Method not allowed"
}
502:
body:
application/json:
example: {
"error" : "Bad API Gateway"
}
We can include library in our main RAML by using "uses" tag.
No comments:
Post a Comment