What is Library in RAML | How to include Library in RAML
RAML libraries may be used to modularize any number and combination of data types,
security schemes, resource types, traits, and annotations.
Although usually defined in an external file, which is then referenced as an include, a library may also be defined inline. A library contained in an external file can reference other libraries as well.
Unlike a regular include or typed fragment, a library contained in an external file must declare the top-level element names that are being defined.
In main RAML uses and is tags are used to include libraries.
Let's write our traits and errors section as a library file:
#%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"
}
In our main RAML we have used "is" and "uses" tags to include library raml in main RAML, as shown below:
#%RAML 1.0
title: dbcrud
version: v1
mediaType:
- application/json
protocols: [HTTP,HTTPS]
documentation:
- title: User Details
content: !include documentation/documentation.raml
types:
insertReqSchema: !include schemas/insertReqSchema.json
updateReqSchema: !include schemas/updateReqSchema.json
annotationTypes:
department: string
uses:
files: Library/library.raml
securitySchemes:
basicAuth:
description: It is used for authenticating uses by username & password
type: Basic Authentication
describedBy:
headers:
client_id: string
client_secret: string
/employee:
get:
(department): IT
is: [files.client-id-required,files.client-secret-required,files.errors]
queryParameters:
id:
description: for fetching employee on the basis of id
required: false
minimum: 1
maximum: 100
type: integer
example:
2
responses:
200:
body:
application/json:
example: !include examples/searchRes
post:
is: [files.client-id-required,files.client-secret-required,files.errors]
description: for posting employees data
body:
application/json:
example: !include examples/insertReq
description: Request body for inserting the data
type: !include schemas/insertReqSchema.json
responses:
201:
body:
application/json:
example: !include /examples/insertRes
put:
securedBy:
- basicAuth
is: [files.client-id-required,files.client-secret-required,files.errors]
description: for updating employees data
body:
application/json:
example: !include examples/updateReq
description: Request body for updating the data
type: !include schemas/updateReqSchema.json
responses:
204:
body:
application/json:
example: !include /examples/updateRes
delete:
securedBy:
- basicAuth
is: [files.client-id-required,files.client-secret-required,files.errors]
description: for deleting employees data
responses:
202:
body:
application/json:
example: !include /examples/deleteRes
/{id} :
get:
is: [files.client-id-required,files.client-secret-required,files.errors]
description: for getting data of specific employee
displayName : /employee/id
responses:
200:
body:
application/json:
example: !include examples/searchIdRes
delete:
is: [files.client-id-required,files.client-secret-required,files.errors]
description: for deleting data of specific employee
displayName : /employee/id
responses:
200:
body:
application/json:
example: !include examples/deleteIdRes
No comments:
Post a Comment