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

JSON schema Draft hint not being respected #66

Open

Description

@bloche

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?

Activity

  1. postatum commented on Dec 20, 2019

    @postatum
    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.

  2. added
    amfRelated to AMF issue, bug or specific behavior
    on Dec 20, 2019
  3. bloche commented on Dec 20, 2019

    @bloche
    Author

    Thanks @postatum

  4. postatum commented on Jun 19, 2020

    @postatum
    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.

  5. bloche commented on Jun 20, 2020

    @bloche
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    amfRelated to AMF issue, bug or specific behaviorbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions