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

Pointer in a referenced schema does not seem to work right. #481

Closed
nvkgbr opened this issue Jun 29, 2023 · 4 comments
Closed

Pointer in a referenced schema does not seem to work right. #481

nvkgbr opened this issue Jun 29, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@nvkgbr
Copy link

nvkgbr commented Jun 29, 2023

Environment

  • Nuget Package: JsonSchema.Net
  • Nuget Version: 4.1.5
  • OS: Windows 10
  • .Net Target: .NET 6

Describe the bug
Getting an exception when trying to evaluate a basic local file with a schema which has a reference to another schema which has a pointer in it.

Json.Schema.JsonSchemaException: 'Cannot resolve base schema from 'file:///.../json-everythingValidationTest/bin/Debug/net6.0/files/schemas/%23/definitions/values''

In the URI # gets replaced with %23

To Reproduce
I created a really small example project for it: repo

Expected behavior
The file gets validated.

I am not sure if I am doing something wrong, or is it a bug in the package.

@nvkgbr nvkgbr added the bug Something isn't working label Jun 29, 2023
@gregsdennis
Copy link
Collaborator

gregsdennis commented Jun 30, 2023

Short answer

No, the change wasn't reverted. You need to update

SchemaRegistry.Global.Register(new Uri(path), schema);

to

SchemaRegistry.Global.Register(schema);

Long answer

The way you're registering the schemas is causing the .net root cause to surface again.

This

new Uri(path)

is the exact problem. If you want to rebuild the URI, you need to include the file:/// URI scheme yourself. JsonSchema.FromFile() (see below) does this for you and automatically sets the base URI on the schema, so when you register it, you only need to pass the schema; the registration will grab the URI from the schema.

https://github.com/gregsdennis/json-everything/blob/2f13ec60841d3c7333ed71134c162465ed678b93/JsonSchema/JsonSchema.cs#L95-L107


Secondarily, You shouldn't need to reload the schema in your ValidateFileAsync() method. If you can rebuild the URI, you can grab it from the registry.

(That's actually not a bad idea to build into the schema loading methods...)

@gregsdennis
Copy link
Collaborator

(I love your profile pic, BTW. Is that the one that was generated for you, or did you do that on purpose?)

@nvkgbr
Copy link
Author

nvkgbr commented Jul 1, 2023

Thank you kindly for the detailed answer! :)
Unfortunately, I will only be able to try it on Monday, but I will give you an update about it.

( Haha, yes, this profile pic was generated :D It is so good that I did not change it since )

@nvkgbr
Copy link
Author

nvkgbr commented Jul 4, 2023

It is working fine now!
Thank you kindly! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants