How to use $ref relative to the root? #164
-
Thank you for your awesome work. I am looking to bump up the version to 4.0 for cdevents for sdk-go. When I pull the new version and run generator: Generating SDK files from templates: tools/templates/*.tmpl and schemas: ./pkg/api/spec/schemas into ./pkg/api
generator: Ignoring folder ./pkg/api/spec/schemas
generator: jsonschema file:///path-to-repo/cdevents/sdk-go/pkg/api/spec/schemas/artifactdeleted.json compilation failed: https://cdevents.dev/schema/links/embeddedlinksarray.json returned status code 404
exit status 1 On close inspection, version 4 has addition How to go about circumventing the aforementioned error. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can use say you have cloned the schemas git repo into
now you can compile schema as follows: prefix := "https://cdevents.dev/0.4.0/schema/"
c := jsonschema.NewCompiler()
c.LoadURL = func(s string) (io.ReadCloser, error) {
suffix, ok := strings.CutPrefix(s, prefix)
if !ok {
return nil, fmt.Errorf("%s not found", s)
}
return os.Open("/tmp/"+suffix)
}
sch, err := c.Compile(prefix+"artifact-deleted-event") |
Beta Was this translation helpful? Give feedback.
You can use
Compiler.LoadURL
to handle this situation.say you have cloned the schemas git repo into
/tmp
:now you can compile schema as follows: