Create Fragments In RAML 1.0
In this tutorial we will demonstrate how can we Create Fragments In RAML 1.0
API fragments are reusable component of RAML to make the design and build of a reusable API even quicker and easier.
Another advantage of building an API spec out of reusable API fragments is that consistency of definitions reduces the effort of implementing APIs.
In this tutorial I will demonstrate how to create the RAML fragments
Login in to Anypoint platform -> Go to design Center
Click on Create new-> Create fragment
Provide the fragment name
We can create separate folders to create the different fragments like DataType/Traits/Example etc.
Create commonHeaders Trait as Fragment
#%RAML 1.0 Trait displayName: Header Trait headers: transaction-id: type: string required: false transaction-type: type: string required: false
Create genericError Data Type as fragment
Add the details
#%RAML 1.0 DataType displayName: Generic Error Type description: Common error fields for across apis properties: errorResponse: type: object properties: transactionId: description: TransactionId of the request that failed type: string required: false errorimeStamp: description: timestamp at which the error occurred type: string required: false errors: description: description of the error/exception type: array required: false items: type: object properties: errorCode: string errorMessage: string
Create basicAuth Security Scheme as Fragment Type
Add the details
#%RAML 1.0 SecurityScheme type: Basic Authentication displayName: BasicAuth description: This security scheme validates requests to the API using client ID and client Secret as basic auth
Publish the created fragments on Exchange so that it can be reusable across all the API’s across organization
Click publish button on top right corner
Provide the asset version
Fragments published to exchange can be reused in RAML, I will demonstrate how can we reuse fragments in RAML in next tutorial