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
Unique Keys Validation not Working? #181
Comments
Looks like my example is wrong. The docs day that the correct URI for the vocab is |
Still no dice... I had a look at the Unit Tests in the project and found this line in the test setup If I add that to my code I get the following error during Schema Load
|
What versions of JsonSchema.Net and JsonPointer.Net are you using? |
JsonSchema.Net - 1.11.5 |
I may need to release a new version of unique-keys to reference 2.0 on pointers. I can do that tonight. |
Ok great thanks! I tried downgrading to 1.11.4 which references Now I get a different error: So I am not sure if that will fix it or something else is going on. |
@sacvalleytech your example works fine on https://json-everything.net/json-schema, which is using the latest of all of the packages and running .net 5. Without the vocabulary registration, I get the same you did at first. With the registration, I get: {
"valid": true,
"keywordLocation": "#",
"instanceLocation": "#",
"annotations": [
{
"valid": true,
"keywordLocation": "#/$schema",
"instanceLocation": "#"
},
{
"valid": true,
"keywordLocation": "#/type",
"instanceLocation": "#"
},
{
"valid": true,
"keywordLocation": "#/items",
"instanceLocation": "#",
"annotation": true
}
]
} Here's my attempt to replicate your issue. Let me know how it runs for you. |
Interesting... its fails/succeeds based on the order of the line Works var schema = JsonSchema.FromText(schemaText);
var instance = JsonDocument.Parse(instanceText).RootElement;
Json.Schema.UniqueKeys.Vocabularies.Register();
ValidationOptions.Default.OutputFormat = OutputFormat.Verbose; Fails Json.Schema.UniqueKeys.Vocabularies.Register();
ValidationOptions.Default.OutputFormat = OutputFormat.Verbose;
var schema = JsonSchema.FromText(schemaText);
var instance = JsonDocument.Parse(instanceText).RootElement; |
Well that is a peculiar result. Good find. I'll play with it and release a fix when I can. Are you unblocked for now? |
Yes I can work around that... thanks for the help! |
I tried cloning the repo and created the same test console app... but referenced the projects directly (instead of NuGet). The error is gone now... so it does seem to be some sort of dependency issue with the NuGet packages. Update So it really does look like the UniqueKeys NuGet package is the culprit. ConsoleApp.csproj <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JsonSchema.Net" Version="1.11.5" />
<!--<PackageReference Include="JsonSchema.Net.UniqueKeys" Version="1.0.0" />-->
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniqueKeys\UniqueKeys.csproj" />
</ItemGroup>
UniqueKeys.csproj <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Json.More.Net" Version="1.4.4" />
<PackageReference Include="JsonSchema.Net" Version="1.11.5" />
</ItemGroup>
</Project> |
I did an update of the nuget package and imported from a local nuget repo (just a folder on my disk). That seemed to fix the problem. I'm releasing new versions of all of the dependent packges (which is basically all of them). A long time ago, I had done some work playing around with the different versions and how they interoperate with nuget packaging. I wrote a blog post about it. To my surprise, this became the general approach for most people after Jon Skeet found it and referenced it in a blog post of his own when he was updating NodaTime to v2. (In fact, MS now highlights this approach in their docs, but they don't reference my post.) According to that approach, I should have released new major versions of everything. A few months ago, I discovered that starting with .Net Core 3.1, it seemed that the framework didn't care anymore about the version attributes in the assembly file because I was able to reference new major versions without having to rebuild dependent assemblies. As a result, when I updated JsonPointer.Net, I figured I'd be fine by just releasing a patch version update of the direct dependencies. It seems that there's still an issue with downstream dependencies, though. I guess I should just stick with the approach I laid out before. |
Environment
How can I help you today?
The JSON schema validation for unique keys does not seem to work (or I am missing something)
Following example: https://gregsdennis.github.io/json-everything/usage/vocabs-unique-keys.html
Additional context
Schema
Input
Example
Output
{"valid":false,"keywordLocation":"#","instanceLocation":"#"}
The text was updated successfully, but these errors were encountered: