Coder Social home page Coder Social logo

Comments (7)

jdesrosiers avatar jdesrosiers commented on July 21, 2024

I'm not able to reproduce this one. The expected result is for it to throw the result of meta-validation. When I attempt to validate that schema I get the following error.

{
  keyword: 'http://json-schema.org/draft-06/schema#validate',
  absoluteKeywordLocation: 'http://json-schema.org/draft-06/schema#',
  instanceLocation: 'http://example.com/test#',
  valid: false,
  errors: [
    {
      keyword: 'http://json-schema.org/draft-06/schema#additionalProperties',
      absoluteKeywordLocation: 'http://json-schema.org/draft-06/schema#',
      instanceLocation: 'http://example.com/test#/properties',
      valid: false,
      errors: [Array]
    },
    {
      keyword: 'http://json-schema.org/draft-06/schema#properties',
      absoluteKeywordLocation: 'http://json-schema.org/draft-06/schema#/properties',
      instanceLocation: 'http://example.com/test#',
      valid: false,
      errors: [Array]
    }
  ]
}

from json-schema-core.

ogoldman avatar ogoldman commented on July 21, 2024

OK--thanks for investigating. I'll take another look at my code, and then provide an update here.

from json-schema-core.

ogoldman avatar ogoldman commented on July 21, 2024

Alright, here's what I got tripped up on. When I call validate:

const output = await JsonSchema.validate(schema, instanceJSON, JsonSchema.VERBOSE);

If the schema fails to validate, then this throws--but it doesn't throw an Error. Instead, it throws an output object for the schema. Is this the intended behavior?

from json-schema-core.

jdesrosiers avatar jdesrosiers commented on July 21, 2024

Yes, that's the expected behavior. I've never been happy with the way meta-validation errors are handled. Throwing the output was intended to be temporary until I came up with something I liked better, but I haven't come up with anything yet, so it's still there. I wanted to avoid having to make a custom error implementation, but at this point I should probably do that or prioritize coming up with an approach I like better.

from json-schema-core.

ogoldman avatar ogoldman commented on July 21, 2024

Got it. As a client, I think the throw seems reasonable, but not extending Error definitely tripped me up. I would have expected a custom error from which I could retrieve the output object.

Do you want me to close this? Or leave it open as a reminder to revisit this? :)

from json-schema-core.

jdesrosiers avatar jdesrosiers commented on July 21, 2024

Thanks for the feedback. You can leave it open. I'm not sure what I'm going to do yet, but I'll figure something out and take care of it soon.

from json-schema-core.

jdesrosiers avatar jdesrosiers commented on July 21, 2024

I added the custom Error class. I'm still not super happy with it. The part I don't like is that you have to know to look for the validation results in custom property output. I'm concerned that people won't know to look for this field. But, it's not good enough the way it is and I didn't come up with a better option, so this will have to do.

from json-schema-core.

Related Issues (8)

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.