Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

JSON schema Draft hint not being respected #66

Open
bloche opened this issue Dec 19, 2019 · 4 comments
Open

JSON schema Draft hint not being respected #66

bloche opened this issue Dec 19, 2019 · 4 comments
Labels
amf Related to AMF issue, bug or specific behavior bug Something isn't working

Comments

@bloche
Copy link

bloche commented Dec 19, 2019

Overview

When using JSON schema in RAML types the $schema property doesn't appear to be respected. Back in JSON schema Draft 4 the exclusiveMaximum property was a boolean, it was updated to be an integer in later draft revisions (see: https://json-schema.org/understanding-json-schema/reference/numeric.html#range). However when I run the webapi-parser's validate function on my RAML I get an error that says exclusiveMaximum should be of type boolean, not integer.

Versions

Node: v12.6.0
Npm: 6.9.0
webapi-parser (+ dependencies):

...
`-- webapi-parser@0.4.0
  `-- ajv@6.5.2
    +-- fast-deep-equal@2.0.1
    +-- fast-json-stable-stringify@2.1.0
    +-- json-schema-traverse@0.4.1
    `-- uri-js@4.2.2
      `-- punycode@2.1.1

Repro

const wap = require('webapi-parser').WebApiParser;

const raml = `#%RAML 1.0
---
title: Test
baseUri: /
mediaType: application/json

/test:
  get:
    responses:
      200:
        body:
          application/json:
            type: |
              {
                "$schema": "http://json-schema.org/draft-07/schema#",
                "$id": "test.schema.json",
                "type": "array",
                "items": {
                  "type": "integer",
                  "exclusiveMaximum": 10
                }
              }
            example: [1, 2, 3, 4, 5]
`;

const validate = async (raml) => {
  const model = await wap.raml10.parse(raml);
  const report = await wap.raml10.validate(model);

  console.log(report.conforms ? 'Valid' : 'Invalid');
  // output errors
  report.results.forEach(r => {
    const pos = `(line: ${r.position.start.line}, column: ${r.position.start.column})`;
    console.log(`${pos} [${r.level}]`);
    console.log(r.message);
  });
}

validate(raml).then(e => e).catch(e => console.error(e));

When I run this I get:

Invalid
(line: 20, column: 41) [Violation]
Expecting !!bool and !!int provided

Question

Is this a bug with the parser, or is there a way I can force the parser to either respect the $schema property or specify what draft I want it to validate with?

@postatum
Copy link
Contributor

Hi @bloche.

It's a limitation of our dependency lib AMF. I've created a gh issue and requested more drafts to be supported.

I'll let you know when we release a new version of webapi-parser with newer json schema versions supported.

@postatum postatum added the amf Related to AMF issue, bug or specific behavior label Dec 20, 2019
@bloche
Copy link
Author

bloche commented Dec 20, 2019

Thanks @postatum

@postatum postatum reopened this Dec 23, 2019
@postatum
Copy link
Contributor

Hi @bloche.

Looks like our dependency lib now supports JSON Schemas up to draft 7. We are currently working on updating our lib as well. I'll let you know when the new version is available.

@postatum postatum added the bug Something isn't working label Jun 19, 2020
@bloche
Copy link
Author

bloche commented Jun 20, 2020

@postatum That's great to hear, thanks for keeping me informed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
amf Related to AMF issue, bug or specific behavior bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants