Skip to content

Fix schema validation failures resulting from added references #286

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

Merged
merged 2 commits into from
Nov 7, 2022
Merged

Fix schema validation failures resulting from added references #286

merged 2 commits into from
Nov 7, 2022

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Nov 7, 2022

In order to avoid duplication of content, JSON schemas may reference other schemas via the $ref keyword. The ajv schema validator tool used by the asset does not automatically follow external references. For this reason, the addition of external references to the schemas used results in a spurious validation failure:

https://github.com/arduino/tooling-project-assets/actions/runs/3367815680/jobs/5585665098#step:5:74

schema /home/runner/work/_temp/json-schema/package-json-schema.json is invalid
error: can't resolve reference https://json.schemastore.org/npm-badges.json from id #

https://github.com/arduino/tooling-project-assets/actions/runs/3367828391/jobs/5585693418#step:6:17

schema /home/runner/work/_temp/taskfile-schema/taskfile.json is invalid
error: can't resolve reference https://taskfile.dev/schema.json from id #

To resolve this, the referenced schemas must be downloaded and the local path to the file specified in the ajv-cli command.

The "Check npm" GitHub Actions workflow validates the repository's `package.json` npm manifest file against its JSON
schema to catch any problems with its data format.

In order to avoid duplication of content, JSON schemas may reference other schemas via the `$ref` keyword. The
`package.json` schema was recently updated to share resources with the npm-badges configuration schema, which caused the
validation to start failing:

schema /home/runner/work/_temp/json-schema/package-json-schema.json is invalid
error: can't resolve reference https://json.schemastore.org/npm-badges.json from id #

The solution is to configure the workflow to download that schema as well and also to provide its path to the avj-cli
validator via an `-r` flag.
The "Check Taskfiles" template workflow validates the project's taskfiles against the official JSON schema.

The contents of that schema was recently moved from the previous location in the Schema Store to the Task project
repository:

go-task/task#910

An attempt was made to mitigate the impact of that move by replacing the content in the original schema with an external
reference to the new one. However, the schema validator used by the workflow does not automatically follow external
references, which caused the workflow to fail:

schema /home/runner/work/_temp/taskfile-schema/taskfile.json is invalid
error: can't resolve reference https://taskfile.dev/schema.json from id #

Although this could be resolved by also downloading the referenced schema, since the original schema intentionally does
not contain anything of value, the better fix is to simply use the real schema directly in the workflow.
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Nov 7, 2022
@per1234 per1234 self-assigned this Nov 7, 2022
Copy link
Contributor

@MatteoPologruto MatteoPologruto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Per!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants