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

NJsonSchema.Validation.Error : PropertyRequired: #/__referencePath #1186

Closed
HelmutSchleicher opened this issue Jun 8, 2020 · 3 comments
Closed

Comments

@HelmutSchleicher
Copy link

In my C# program I try to validate a serialized json string with a json schema via NJsonSchema validator.

Expected behavior: Json string should be validated as correct and not throw an exception.
I tried different online schema validator which showed me that my json string was correct.

Actual behavior: Following exception is thrown: NJsonSchema.Validation.Error : PropertyRequired: #/__referencePath
I don't understand why the $ref isn't recognized as the required porperty anymore and how to fix this.

The C# code as well as the json file and schema are described below. Thanks a lot in advance for your help!

The json schema is summarized in the schema file "schema.txt":

{
    "$schema": "http://json-schema.org/draft-07/schema",  
    "$ref": "#/definitions/reference_to_other_object",
    "definitions": {
        "reference_to_other_object": {
            "type": "object",
            "required": [
                "$ref"
            ],
            "additionalProperties": false,
            "properties": {
                "$ref": {
                    "type": "string",
                    "allOf": [
                        {
                            "format": "uri-reference"
                        },
                        {
                            "pattern": "^.*#/datatypes/.*$"
                        }
                    ]
                }
            }
        }
    }
} 

schema.txt

The json string that has to be validated is summarized in "data.txt":

{
  "$ref": "#/datatypes/MyCustomDataType"
}

data.txt

The short code snippet which should illustrate the problem is shown here:

using System;
using System.Text;
using System.Threading.Tasks;
using NJsonSchema;
using NJsonSchema.Validation;
using System.Resources;
    
class Program
    {

           static async Task Main(string[] args)
            {
                // Read json
                var jsonContent = Encoding.ASCII.GetString(Properties.Resources.data);
                var jsonSchema = Encoding.ASCII.GetString(Properties.Resources.schema);

                var validator = new JsonSchemaValidator();
                var schema = await JsonSchema.FromJsonAsync(jsonSchema);
                var result = validator.Validate(jsonContent, schema);

                Console.WriteLine(result);
            }
        
    } 
@RicoSuter
Copy link
Owner

Using $ref as a property name and not a reference propably messes up quite some things (edge case).

@HelmutSchleicher
Copy link
Author

Using $ref as a property name and not a reference propably messes up quite some things (edge case).

Yes it seems like it. But I think it is defined in the JSON Schema standards.
Do you think that this bug can be fixed within the next weeks or do you think it will take longer?

@RicoSuter
Copy link
Owner

Do you think that this bug can be fixed within the next weeks or do you think it will take longer?

Who will fix it? Please create a PR - otherwise it probably takes longer.

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

No branches or pull requests

2 participants