Comments (6)
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.
I believe a reference "$ref": "links/embeddedlinksarray.json"
would work too.
from spec.
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.
Looking at how references are used for the meta schemas:
- The root schema ID is https://json-schema.org/draft/2020-12/schema
- The references can be fetched at https://json-schema.org/draft/2020-12/meta/
- References are relative, like
{"$ref": "meta/<section>"},
So one level is stripped from the root schema ID and then the relative path applied
If we followed the same approach for CDEvents:
- The root schema ID is https://cdevents.dev/0.4.0/schema/--event
- The links schema can be fetched at https://cdevents.dev/0.4.0/schema/links/embeddedlinkend.json
- If we used relative references, they should look like
{"$ref": "links/embeddedlinkend.json"},
- If we want to keep absolute references instead, they should look like
{"$ref": "/0.4.0/schema/links/embeddedlinksarray.json"},
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.
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.
@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)
- type of `url` fields is inconsistent into jsonschema HOT 2
- Removed and upgraded predicates for service, removal consideration? HOT 3
- We are missing the version part in some of our event examples
- Consider adding artifact.quarantined
- The 'deleted' predicate is not mentioned in the lineup for artifact events
- Ensure consistency amont camel case vs snake case
- Shall we remove the `Run` part from pipeline, task and run events? HOT 2
- Validate schemas towards the JSON metaschema HOT 1
- Link's schema looks to be missing property field HOT 1
- Links not added for new testcase and ticket events in v0.4.0 HOT 2
- Links not added in spec/examples HOT 3
- Instructions on how to use links(external and embedded) for different SDKs HOT 2
- Replace absolute path by relative path in $ref HOT 1
- remove confusing type `Enum or String` HOT 24
- Links are missing in the custom schema
- Rename the "examples" folder so that it's clear it's for validation purposes
- Improvements on automated release
- Linters are only ran on main HOT 2
- How to integrate custom schemaUri for SDKs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spec.