davishmcclurg / json_schemer

JSON Schema validator. Supports drafts 4, 6, 7, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1.
MIT License
399 stars 64 forks source link

Failure to validate documents against SchemaStore's github-workflow schema #172

Closed mpalmer closed 7 months ago

mpalmer commented 7 months ago

I'm trying to use json_schemer to validate documents (github workflow files) against the [SchemaStore project]'s github-workflow schema. However, no matter what (valid-seeming) document I validate, I'm getting very odd errors. Here's a minimal example script that exhibits the problem:

require "yaml"
require "net/http"
require "json_schemer"

SCHEMA_URL = "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-workflow.json"
DOCUMENT_URL = "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/test/github-workflow/1162.yaml"

schema = JSONSchemer.schema(JSON.parse(Net::HTTP.get(URI(SCHEMA_URL))))

document = YAML.load(Net::HTTP.get(URI(DOCUMENT_URL)))

pp schema.validate(document, output_format: 'detailed').fetch('errors').to_a

I would expect the document to validate, but instead the script prints out these errors:

[{"valid"=>false,
  "keywordLocation"=>"/additionalProperties",
  "absoluteKeywordLocation"=>
   "https://json.schemastore.org/github-workflow.json#/additionalProperties",
  "instanceLocation"=>"/true",
  "error"=>
   "object property at `/true` is not defined and schema does not allow additional properties"},
 {"valid"=>false,
  "keywordLocation"=>"/required",
  "absoluteKeywordLocation"=>
   "https://json.schemastore.org/github-workflow.json#/required",
  "instanceLocation"=>"",
  "error"=>"object at root is missing required properties: on"}]

I feel like the schema is probably OK (it works in SchemaStore's testsuite, which I believe uses AJV, and it works in the valico Rust crate), but I can't imagine that json_schemer has any huge showstopper bugs either, so I feel like it must be PEBKAC, but for the life of me I can't see what I'm doing wrong. Am I just really (un)lucky, and I've stumbled across a deeply-hidden bug somewhere, or have I made a really embarrassing clanger in my usage of json_schemer?

davishmcclurg commented 7 months ago

I think your problem is that YAML parses "on" into true:

repos/json_schemer main % bin/console -r yaml --simple-prompt
>> document_url = "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/test/github-workflow/1162.yaml"
>> YAML.load(Net::HTTP.get(URI(document_url))).keys
=> ["name", true, "jobs"]
mpalmer commented 7 months ago

8f3jyz

mpalmer commented 7 months ago

(Thank you, BTW)