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

Incorrect YAML validation: when is a string a map? #11

Open
setjmp opened this issue Jan 19, 2023 · 1 comment
Open

Incorrect YAML validation: when is a string a map? #11

setjmp opened this issue Jan 19, 2023 · 1 comment

Comments

@setjmp
Copy link

setjmp commented Jan 19, 2023

In the example below, the pajv certifies that the YAML file contains a list of strings. However, the Python yaml module parses the data into a map.

The schema (example_schema.json):

{
	"description": "Test case",
	"title": "Stuff",
	"type": "array",
	"additionalProperties": false,
	"items": {
		"type": "array",
		"properties": {
		  "items": {
			"type": "string"
		  }
		}
	}
}

The data file (example.yaml):

---
- [this is a test]
- [this:{foo,bar}]

The validation:

$ pajv -s ./example_schema.json -d example.yaml
example.yaml valid

Python test code (example.py):

import yaml

with open("example.yaml") as f:
    yaml_list = yaml.safe_load(f.read())
for item in yaml_list:
    print(item)

The outcome from the Python code:

$ python example.py 
['this is a test']
[{'this': {'foo': None, 'bar': None}}]

Either Python's built in YAML parser is wrong about this or pajv is. I am not an expert, but....

@setjmp
Copy link
Author

setjmp commented Jan 20, 2023

It looks like the schema had a problem where the "properties" portion needs to be eliminated. I discovered this by testing the example using ajv which told me that the schema had problems worth digging into:

$ ajv  -s ./example_schema.json -d example.yaml 
strict mode: missing type "object" for keyword "additionalProperties" at "#" (strictTypes)
strict mode: missing type "object" for keyword "properties" at "#/items" (strictTypes)
example.yaml valid

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

No branches or pull requests

1 participant