Coder Social home page Coder Social logo

Integers as Discriminators about ajv HOT 7 CLOSED

b-wils avatar b-wils commented on June 19, 2024
Integers as Discriminators

from ajv.

Comments (7)

b-wils avatar b-wils commented on June 19, 2024 1

https://runkit.com/b-wils/ajv-number-discriminator

from ajv.

jasoniangreen avatar jasoniangreen commented on June 19, 2024 1

Thanks for that. So after reviewing things I can see that it is indeed a deliberate restriction and there was actually a PR a while back to add support for other scalar data types.

I am just in the process of preparing a release (the first in a long time) but I can look into this afterwards and follow up with @epoberezkin.

from ajv.

jasoniangreen avatar jasoniangreen commented on June 19, 2024

Hi there, could you put together a runkit exhibiting the issue? Try and keep the example as simple as possible.

from ajv.

jasoniangreen avatar jasoniangreen commented on June 19, 2024

Judging by the example here https://ajv.js.org/json-schema.html#discriminator your schema is not quite right.

Looks like you are missing propertyName in discriminator: {propertyName: "foo"}.

from ajv.

b-wils avatar b-wils commented on June 19, 2024

Ah yes, my apologies. https://runkit.com/b-wils/ajv-number-discriminator is updated with the correct discriminator declaration and now should demonstrate the issue with numbers as discriminators.

from ajv.

jasoniangreen avatar jasoniangreen commented on June 19, 2024

Hi @b-wils, I have spoken to EP and this is not a change we're open to exploring at this time. I don't have all the context but there are reasons it should be a string and my interpretation of the spec is that it should be a string too. It should be pretty trivial to work around too.

from ajv.

b-wils avatar b-wils commented on June 19, 2024

Thanks for looking into it, if this is isn't part of the spec then that makes sense to not extend it in ajv.

By workaround, you mean change the fields from numbers to strings? Unfortunately our data is already in use and won't be feasible to change existing users. Replacing oneOf with if/then is a (slightly awkward) workaround to reduce error noise, or we may just live with the noise.

from ajv.

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.