RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.41k stars 538 forks source link

JsonSchema.Validate throws exception with valid Json/OpenApi3 schema #1225

Open tstoian opened 4 years ago

tstoian commented 4 years ago

When I try to validate my simple OpenAPI 3 definition (embedded below) against the OpenAPI 3 definition

$json = @'
{
    "openapi": "3.0.0",
    "info": {
        "title": "myTitle",
        "version": "1.0"
    },
    "paths": {
        "/resource": {
            "get": {
                "responses": {
                    "200": {
                        "description": "myDescription"
                    }
                }
            }
        }
    }
}
'@
$schema = [NJsonSchema.JsonSchema]::FromUrlAsync('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json').GetAwaiter().GetResult()
$schema.Validate($json)

the Validate method generates the following error:

MethodInvocationException: C:\Git\APIM\APIM-Service\apim-pipeline-scripts\parse-openapi3.ps1:22:1
Line |
  22 |  $schema.Validate($json)
     |  ~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "Validate" with "1" argument(s): "Invalid pattern '^\__referencePath$' at offset 3. Unrecognized
     | escape sequence \\_."

I validated my OpenApi 3 json against the OpenAPI 3 schema in several online validators and it is valid.

RicoSuter commented 4 years ago

Probably fixed: https://github.com/RicoSuter/NJsonSchema/issues/1186