raml-java-parser icon indicating copy to clipboard operation
raml-java-parser copied to clipboard

How to include common schema file in RAML

Open dviru opened this issue 9 years ago • 3 comments

Hi,

In raml we have defined set of schema which is related to particular raml, and we have some other common schema defined in "common-schema.raml". how can i define the include common-schema.raml in my RAML file, So RAML parser can pick both schema definition. My Current RAML looks like below and RAML parser only shows the current file schema definition. if defined include common-schema.raml file(schemas: !include common-schema.raml) after raml file schema definition section, then only i am seeing included raml file schema not raml file schema

#%RAML 0.8
title: Example API
baseUri: https://www.example.com/
protocols: [HTTPS]

schemas: !include common-schema.raml
schemas:
  - person: |
      {
         ....
      }
  - asset: |
      {
         ...
      }

traits: !include common-traits.raml
/example:
  is: [secured]
  description: Collection endpoint for example[Since:1.0]
  get:
    is: [getSearchResponse,pagableRequest]
    description: Search example based on the given filter parameters.
    headers:
      Accept:
        description: Media type.
        example: application/json
        type: string
        required: true    
    responses:
      200:
        description: All examples were successfully retrieved (response collection may be empty).
        body:
          application/json:
            schema: asset

common-schema.raml

schemas:
  - getSearchResponse: |
       {
          ...
       }

Aha! Link: https://mulesoft-roadmap.aha.io/features/APIRAML-132

dviru avatar Jul 10 '16 07:07 dviru

Remove schemas node from common-schema.raml. The RAML !include tag basically appends the content of the included file on the node that you specified the !include.

sichvoge avatar Jul 12 '16 10:07 sichvoge

Just i need to remove "schemas:" node from "common-schema.raml" file? no need to change anything in main raml(file i am including the "common-schema.raml")? just i removed the "schemas:" from "common-schema.raml" file and tested. included file schema is over-written by main file schema

dviru avatar Jul 13 '16 09:07 dviru

Sorry you are using composition :D Missed that bit ;) Do the following:

common-schema.raml

getSearchResponse: |
       {
          ...
       }
getOtherResponse: |
      {
         ...
      }

api.raml

#%RAML 0.8
title: Example API
baseUri: https://www.example.com/
protocols: [HTTPS]

schemas:
  - !include common-schema.raml
  - person: |
      {
         ....
      }
  - asset: |
      {
         ...
      }

I did not tried that, but sequences in RAML 0.8 (sequences being the ones that start with dash) and composition (composition being you compose to sequences together) work like that.

sichvoge avatar Jul 13 '16 20:07 sichvoge