raml-org / raml-java-parser

(deprecated) A RAML parser based on SnakeYAML written in Java
Other
174 stars 121 forks source link

How to include common schema file in RAML #154

Open dviru opened 8 years ago

dviru commented 8 years ago

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

sichvoge commented 8 years ago

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.

dviru commented 8 years ago

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

sichvoge commented 8 years ago

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.