raml-org / raml-js-parser

(deprecated) A RAML parser based on PyYAML written in CoffeScript and available for use as NodeJs module or in-browser.
195 stars 53 forks source link

Restricting the compilation of Includes in RAML #173

Closed priyavivek1 closed 8 years ago

priyavivek1 commented 8 years ago

Currently, when any RAML file containing Includes is parsed, the resulting object contains the includes in compiled form. Is there any way to avoid it. For eg, in below RAML

schemas:

/av/avcd: is: ["aaaa", responses] get: is: [ABC] description: | A search will return a list of external application party identifiers. queryParameters: primaryPartyKey: description: | Primary party identifier. type: string required: true ABCTypeCd: description: | Alternate party type code. type: string required: false repeat: true responses: 200: body: application/json: schema: ABC example: !include samples/ABC.json

When this RAML file is loaded as below: raml.loadFile(source).then(function(data) { console.log(data.resources) }

The data object contains the resolved reference for RetrievePartyAlternatePartyKeyListRs (means whatever is written is the file is printed. I just need to retrive "schema name", how can i do it.

dmartinezg commented 8 years ago

Hi @priyavivek1, the parser processes a lot of the content, and resolves schemas names to schema content.

There is a feature flag not to resolve schema names, you can disable schema transformation like this: https://github.com/raml-org/raml-js-parser/blob/master/test/specs/schemas.js#L124

priyavivek1 commented 8 years ago

Thanks @dmartinezg, it worked for me in latest version : Is there any feature to restrict the schema compilation at root level also. For eg

schemas: RetrievePartyAlternatePartyKeyListRs: !include jsd/RetrievePartyAlternatePartyKeyListRs.1.schema.json

raml.loadFile(source, {applySchemas: false}).then(function(data) { console.log(data.schemas) }

when i print data.schemas, it gives me compiled schemas as below {"RetrievePartyAlternatePartyKeyListRs" : "compiled schemas"}

dmartinezg commented 8 years ago

No, there is no way to disable resolution of !include tags, and I wonder if it is legal RAML 0.8, the spec says:

When RAML or YAML files are included, RAML parsers MUST not only read the content,
but parse it and add the content to the declaring structure as if the content were declared inline.