Comments (15)
Hi @JaniszM, it looks like you want the un-transformed output from the parser, that can be done, simply by asking the parser not to transform
the input via a feature flag like this:
https://github.com/raml-org/raml-js-parser/blob/master/test/specs/parser.js#L90
Although in that case, the RAML parser is hardly much better than a YAML parser which follows the !include
tag.
from raml-js-parser.
The Java RAML Parser (v0.8) parses this differently with the result I believe @JaniszM is desiring. Rather than replacing the schema with the definition import, it leaves the schema name in place. Example RAML:
schemas:
- SessionRequest: !include schemas/requests/session.json
/session:
post:
description:
User Login.
body:
application/json:
schema: SessionRequest
example: !include examples/requests/session.json
From my Intellij debugger, when read via the Java RAML parser, the result looks like the following:
Note the "Schema" field reads "SessionRequest".
However, when this gets parsed by the JS RAML parser, the following is output (truncated for brevity):
{
"relativeUri": "/session",
"methods": [
{
"description": "User Login.",
"body": {
"application/x-www-form-urlencoded": {
"formParameters": {
"email": {
"description": "Email Address.",
"type": "string",
"displayName": "email"
},
"password": {
"description": "Password.",
"type": "string",
"displayName": "password"
}
}
},
"application/json": {
"schema": "{\n \"title\": \"Session Request Schema\",\n \"type\": \"object\",\n \"properties\": {\n \"email\": {\n \"type\": \"string\"\n },\n \"password\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\"email\", \"password\"]\n}\n",
"example": "{\n \"email\": \"[email protected]\",\n \"password\": \"test1234\"\n}\n"
}
},
"protocols": [
"HTTPS"
],
"method": "post"
}
],
"relativeUriPathSegments": [
"session"
]
},
In this case, the schema is dropped in place of the contents of the schema being referred to. In my case this a) duplicates data b) makes it harder to understand which previously defined schema is being referred to.
@JaniszM please correct me if I'm misinterpreting the original issue here. Either way, this is an issue for me. The behavior of the Java parser seems More Correctβ’ or at least is the behavior I'd like to see for the reasons stated above.
from raml-js-parser.
For reference on how the two parsers differ from a test perspective:
vs.
https://github.com/raml-org/raml-js-parser/blob/master/test/specs/parser.js#L5723-L5762
from raml-js-parser.
And really, to fix, all you have to not do is this:
raml-js-parser/src/composer.coffee
Line 61 in c8edf03
Seems to me we don't want to apply the value of the schema here unless using a separate !include
here. Thoughts @dmartinezg?
from raml-js-parser.
Hi @plukevdh, you are right that is where we are transforming the output.
As I mentioned above, the way to avoid this transformation is by calling the parser with the flag transform
to off.
raml.load(definition, 'filename.yml', {transform: false})
.then(function(output){
//do something with output here
});
from raml-js-parser.
Sorry for late answer, I was on vacation :)
@plukevdh you got it well I think.
@dmartinezg I checked flag {transform: false}
. Looks this is exactly what I need :) Thanks.
from raml-js-parser.
Ok, after checking it again I got serious problem. disabling transform makes whole structure of object like this visible in raml file. This mean that raml-object-to-raml lib cannot parse it anymore :( Is it possible any other way to use schemas like in transform disabled mode but still keep the structure of trasformed object?
from raml-js-parser.
Going to check out {transform: false}
to see if it works for my case as well.
from raml-js-parser.
This does not follow the Java parser convention either as it doesn't perform any of the transformations. It doesn't collect the endpoints (/session
) under the endpoints
property. This seems like a very unfortunate divergence of the two parsers.
from raml-js-parser.
@dmartinezg any comment on what we might do to make the two parsers work more similarly?
from raml-js-parser.
Hi @plukevdh and @JaniszM, I just pushed a branch, adding a specific flag for this, you can check 4d49f90#diff-51b64dc80fa386af7ffcd496680224fdR124 to see how to disable the behaviour.
would this be enough for you?
from raml-js-parser.
Looks legit, I need to test though.
from raml-js-parser.
I just pushed 0.8.15 to npmjs, it should make testing easier.
from raml-js-parser.
π works as required. thanks for this solution. I'd be curious if it solves @JaniszM's problem as well.
from raml-js-parser.
Works perfectly :)
from raml-js-parser.
Related Issues (20)
- extending with yaml anchors HOT 2
- securedBY: [null] produces error HOT 3
- Please push updated package to npm HOT 1
- RAML v1.0 HOT 2
- Can't parse valid yaml definition because of apostrophe character HOT 3
- object2raml HOT 2
- oauth_2_0 is not inherited at endpoint level HOT 2
- Restricting the compilation of Includes in RAML HOT 3
- Parsing resourcetypes with optional methods do not inherit in the resources HOT 4
- CORS: implement setting to perform XHR requests with withCredentials=true HOT 1
- Error parsing: while validating trait properties resource type cannot define child resources HOT 1
- Circular $ref dependencies are not allowed with dereferencing
- Browser distribution is bit heavy for browsers HOT 1
- SyntaxError: Unexpected token < in JSON at position 0 HOT 5
- Schema references in resource methods aren't code generation friendly
- Cannot read included files with directory containing spaces on Windows HOT 1
- loadFileSync
- Parser does not include description of high-level uri parameter.
- `Types` is not an alias of `schemas` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raml-js-parser.