Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using package with embedded references in go 1.16? #100

Open
b5 opened this issue May 6, 2021 · 3 comments
Open

Using package with embedded references in go 1.16? #100

b5 opened this issue May 6, 2021 · 3 comments

Comments

@b5
Copy link
Member

b5 commented May 6, 2021

A question asked in our discord

I have a question, not sure if this is the place to ask. But how do you do references using the embed directive recently introduced in Go 16?
Example, I have a JSON schema that references another definition in another file, how do we do that with the package?

@Arqu
Copy link
Contributor

Arqu commented May 7, 2021

Veeeery interesting question. Just looked into the embed functionality, and while technically there are not restrictions to pull in the schema from anywhere you like (it consumes just a []byte anyways) having external references does break the flow a bit as it doesn't know how to resolve those. Typically we would handle those by fetching with the appropriate schema ie file:// and http:// however for embed it's up to the user to figure out the resolution mechanics for their embedded files.

The best entry point I currently see to kind of hack this together is to manually register external schemas (and adjust the references accordingly) by manually adding schemas to the SchemaRegistry. If this approach sounds remotely reasonable, I'd be happy to expand the Validate path on Schema to work off of a user supplied state instead of self generating one.

Also posting back on discord just to continue the feedback loop here.

@neumachen
Copy link

@Arqu so I guess essentially we can use this by loading all the reference schemas and then the referencing schema. Is that what you're saying?

@Arqu
Copy link
Contributor

Arqu commented Jun 2, 2021

In theory yes, but as said needs some work to be usable.
However, a PR got recently merged which would allow you to implement your own resolver, which should open a way for you to actually do this: 36b0071

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants