Git Product home page Git Product logo

Comments (15)

dmartinezg avatar dmartinezg commented on August 31, 2024

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.

plukevdh avatar plukevdh commented on August 31, 2024

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.

plukevdh avatar plukevdh commented on August 31, 2024

For reference on how the two parsers differ from a test perspective:

https://github.com/raml-org/raml-java-parser/blob/master/src/test/java/org/raml/parser/builder/SchemaBuilderTestCase.java#L73-L74

vs.

https://github.com/raml-org/raml-js-parser/blob/master/test/specs/parser.js#L5723-L5762

from raml-js-parser.

plukevdh avatar plukevdh commented on August 31, 2024

And really, to fix, all you have to not do is this:

@apply_schemas node

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.

dmartinezg avatar dmartinezg commented on August 31, 2024

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.

JaniszM avatar JaniszM commented on August 31, 2024

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.

JaniszM avatar JaniszM commented on August 31, 2024

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.

plukevdh avatar plukevdh commented on August 31, 2024

Going to check out {transform: false} to see if it works for my case as well.

from raml-js-parser.

plukevdh avatar plukevdh commented on August 31, 2024

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.

plukevdh avatar plukevdh commented on August 31, 2024

@dmartinezg any comment on what we might do to make the two parsers work more similarly?

from raml-js-parser.

dmartinezg avatar dmartinezg commented on August 31, 2024

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.

plukevdh avatar plukevdh commented on August 31, 2024

Looks legit, I need to test though.

from raml-js-parser.

dmartinezg avatar dmartinezg commented on August 31, 2024

I just pushed 0.8.15 to npmjs, it should make testing easier.

from raml-js-parser.

plukevdh avatar plukevdh commented on August 31, 2024

πŸ‘ works as required. thanks for this solution. I'd be curious if it solves @JaniszM's problem as well.

from raml-js-parser.

JaniszM avatar JaniszM commented on August 31, 2024

Works perfectly :)

from raml-js-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.