Code Monkey home page Code Monkey logo

Comments (6)

OptimumCode avatar OptimumCode commented on July 25, 2024 1

Hi, @jrhok.

This is actually really interesting question. It seems like the library indeed have a problem when the root $id is not an absolute uri. I tried to load your schemes and the uri for foo.json was resolved as /myproject/enums/myproject/enums/foo that is definitely incorrect. I will create an issue to resolve this. I will try to fix it as soon as I can. Thank you for bringing this to my attention!

In the mean time, I could suggest use something like this instead (until I fix this)

foo.json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://myproject/enums/foo",
  "type": "integer",
  "enum": [
    0,
    1,
    2
  ]
}
request.json
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://myproject/data/request",
    "type": "object",
    "properties": {
        "foo": {
            "type": "array",
            "items": {
                "$ref": "/enums/foo"
            }
        },
        "foobar": {
            "$ref": "/enums/foo"
        }
    }
}

from json-schema-validator.

jrhok avatar jrhok commented on July 25, 2024 1

Thank you for your quick feedbacks !
We came up with the same workaround, thanks !

from json-schema-validator.

OptimumCode avatar OptimumCode commented on July 25, 2024 1

Hi, @jrhok. I will merge the fix today - I hope you can use the snapshot version until the release is published.

Small note about the references:

In your example:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "myproject/data/request",
    "type": "object",
    "properties": {
        "foo": {
            "type": "array",
            "items": {
                "$ref": "enums/foo"
            }
        },
        "foobar": {
            "$ref": "/myproject/enums/foo"
        }
    }
}

you tried to use the relative reference enums/foo. You want it to be resolved into myproject/enums/foo however, this will not happen. This will be resolved into myproject/data/enums/foo.

This happens because when you use the reference that does not start with / the resolution logic is the following:

  1. Find the closest $id to the place where you use the reference;
  2. Drop the last part segment;
  3. Append the value from $ref to the URI we have on step 2.

So, the only option here would be to use the absolute reference in the main JSON schema.

from json-schema-validator.

OptimumCode avatar OptimumCode commented on July 25, 2024 1

Fixed in release 0.0.11

from json-schema-validator.

OptimumCode avatar OptimumCode commented on July 25, 2024

I have merged changes. Once snapshot (and later release) is published I will leave a comment here. Kindly, reopen the issue if you still have the same problem after updating to the newer version

from json-schema-validator.

OptimumCode avatar OptimumCode commented on July 25, 2024

Snapshot has been published

from json-schema-validator.

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.