Giter Club home page Giter Club logo

Comments (6)

afrittoli avatar afrittoli commented on June 30, 2024

Thanks, I also realised that while working on the golang SDK.
I'm just waiting to see if there is any more issue, and then I'll make a PR.

from spec.

afrittoli avatar afrittoli commented on June 30, 2024

I believe a reference "$ref": "links/embeddedlinksarray.json" would work too.

from spec.

afrittoli avatar afrittoli commented on June 30, 2024

According to the jsonschema docs, schema references are relative to the schema baseURI.

In our case, the schema id looks like https://cdevents.dev/0.4.0/schema/artifact-deleted-event, the baseURI would be https://cdevents.dev/ and the $ref for the embedded schema should be /0.4.0/schema/links/embeddedlinksarray.json.

I tried with check-jsonschema and the format /0.4.0/schema/links/embeddedlinksarray.json works with it - the tool fetches the schema from the internet:

➜ check-jsonschema examples/artifact_deleted.json --schemafile schemas/artifactdeleted.json
ok -- validation done

If I used the --base-uri option instead, it works as long as $ref does not start with a / and the combination baseUri + $ref points to a valid location on my local disk. For instance, with $ref == schemas/links/embeddedlinksarray.json, this works:

➜ check-jsonschema examples/artifact_deleted.json --schemafile schemas/artifactdeleted.json --base-uri /git/github.com/cdevents/spec/
ok -- validation done

In CI we need to use local files (not fetched from the internet) because the schemas from PRs have not been published yet.
In the SDK the schemas can be embedded in the code, so they don't have to be fetched every time. The code that generates the actual SDK code should rely on the local versions from disk too.

In the jsonschema docs it even says that the URIs do not necessarily need to be network addressable, they're only identifiers, and that typically the schemas are embedded in the tool that does the validation.

I lean slightly towards having the internet based resolution working (i.e. using a $ref like /0.4.0/schema/links/embeddedlinksarray.json) and have tools like CI and code generation do some magic (like rewrite the refs) to be able to resolve all the references from local disk.

@xibz @e-backmark-ericsson @rjalander WDYT?

from spec.

afrittoli avatar afrittoli commented on June 30, 2024

Looking at how references are used for the meta schemas:

So one level is stripped from the root schema ID and then the relative path applied

If we followed the same approach for CDEvents:

I think the relative references option would be better because, to use the absolute one, we would include the spec version in the reference, so every new release would require updating all references, even if it wasn't changed.

from spec.

rjalander avatar rjalander commented on June 30, 2024

As per the jsonschema docs, the $ref is a URI-reference that is resolved against the schema's Base URI.
So we can not use ref pointing from a classpath or local system path, it always resolved against root schema ID URL,
In this case the schema fails to load without internet,

[main] ERROR com.networknt.schema.JsonSchemaFactory - Failed to load json schema from https://cdevents.dev/0.4.0/schema/links/embeddedlinksarray.json
java.net.UnknownHostException: cdevents.dev

from spec.

afrittoli avatar afrittoli commented on June 30, 2024

@rjalander what I found is that you need to load the schemas from the local disk into your validator, so that it will use its local database of schemas instead of going out to the internet.

from spec.

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.