-
Notifications
You must be signed in to change notification settings - Fork 22
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
Integrate with the JSON Schema CLI for formatting and linting on CI #150
base: main
Are you sure you want to change the base?
Conversation
Most of the changes are the |
BTW, I also added this repo to my https://github.com/sourcemeta/awesome-jsonschema |
@lpsinger Glad you like it!
Yeah, I can certainly make that happen! I'll let you know when its up :) |
Also on this: the JSON Schema team discourages the use of AJV, as despite being popular, it is not spec compliant and its use can lead to interoperability issues with other JSON Schema consumers. The JSON Schema team maintains Bowtie (https://bowtie.report), which is a real-time dashboard for spec compliance for a wide range of implementations. There, you can see that AJV is actually one of the worst scorers for JSON Schema 2020-12 with 24% of official tests failing: https://bowtie.report/#/implementations/js-ajv There are other good JavaScript ones you can use (like https://github.com/hyperjump-io/json-schema, by another TSC member) and our CLI will support the test runner on 2020-12 soon! |
@lpsinger Done! I believe this should work fine now: npm install --global @intelligence-ai/jsonschema Do you want me to add it to the dev dependencies and tweak the GitHub Actions workflow to use it from there? |
@lpsinger Friendly ping! Let me know if the NPM integration is working on your end and if you have any other requirement for making the tool useful to you. We are rapidly adding more linting rules and other niceties. |
Done! @lpsinger v0.5.0 should work on macOS Intel. Let me know if you need anything else :) |
Hey there! This is a PR to mainly start a conversation. I'm a member of JSON Schema organization involved in maintaining various JSON Schema related tooling (like https://alterschema.sourcemeta.com) and documentation (like https://www.learnjsonschema.com), plus co-author of the recently published O'Reilly book touching on JSON Schema (https://www.oreilly.com/library/view/unifying-business-data/9781098144999/). Based on our experience working with organizations maintaining repositories of schemas (like you!), we've been working on an open-source CLI tool that aims to simplify development and CI/CD when dealing with schemas. This CLI supports a growing amount of commands, but I'm proposing two for this repository to start with: - Formatting: making sure your schemas following a consistent style (i.e. indentation) plus a consistent ordering of keywords that was designed to make schemas easier to read - Linting: we are collecting common rules to highlight anti-patterns, common pitfalls, etc when using JSON Schema. There are not that many implement out there, but the linter already caught a little anti-pattern in `Reporter`: setting `enum` alongside `type` I would love to hear your feedback, feature requests, etc to help you make better use of JSON Schema with this CLI! We also have other things on the way, like a proper JSON Schema test runner that could eventually simplify your AJV scripts. Signed-off-by: Juan Cruz Viotti <[email protected]>
I tried out your tool locally on one of our files, but it could not find one of the referenced schemas:
In Alert.schema.json, we refer to Reporter.schema.json using a relative path: {
"$ref": "../core/Reporter.schema.json",
"description": "mission=GLOWBUG"
} and we like that Ajv resolves that file using its relative path on the filesystem, because we want to validate against the local copy rather than actually fetching it from the Web on the main branch. However, I get the same error even if I add the
|
Hi @lpsinger , which version of the tool are you using? I'm getting a different output with v0.5.1 (the latest at the time of this writing). Maybe you kept an old one? In any case, while the CLI supports Draft 0 to 2020-12 in most of the commands, it does not support 2020-12 on the With v0.5.1, you should be getting a nicer error that 2020-12 vocabularies are not supported yet. i.e.: $ jsonschema validate gcn/notices/glowbug/Alert.schema.json
Error: Cannot compile unsupported vocabulary: https://json-schema.org/draft/2020-12/vocab/applicator
With this CLI, you do it with the |
One cool thing you could try on 2020-12 right now is bundling (inline remote references into a schema). For example, as you pointed out, jsonschema bundle gcn/notices/burstcube/alert.schema.json --resolve gcn/notices/core --extension .schema.json In comparison to some other tools that attempt to do this, the CLI does it following the standardised bundling procedure: https://json-schema.org/blog/posts/bundling-json-schema-compound-documents We are working super hard to get coverage for every dialect, including 2020-12, on |
As a tiny update, we definitely didn't forget about this. We are working hard to get 2020-12 working, and we are pretty close! Expect an update to this PR hopefully soon. |
Hey there! This is a PR to mainly start a conversation. I'm a member of JSON Schema organization involved in maintaining various JSON Schema related tooling (like https://alterschema.sourcemeta.com) and documentation (like https://www.learnjsonschema.com), plus co-author of the recently published O'Reilly book touching on JSON Schema (https://www.oreilly.com/library/view/unifying-business-data/9781098144999/).
Based on our experience working with organizations maintaining repositories of schemas (like you!), we've been working on an open-source CLI tool (https://github.com/Intelligence-AI/jsonschema) that aims to simplify development and CI/CD when dealing with schemas. This CLI supports a growing amount of commands, but I'm proposing two for this repository to start with:
Formatting: making sure your schemas following a consistent style (i.e. indentation) plus a consistent ordering of keywords that was designed to make schemas easier to read
Linting: we are collecting common rules to highlight anti-patterns, common pitfalls, etc when using JSON Schema. There are not that many implemented yet (thought we are rapidly adding them!), but the linter already caught a little anti-pattern in
Reporter
: settingenum
alongsidetype
I would love to hear your feedback, feature requests, etc to help you make better use of JSON Schema with this CLI! We also have other things on the way, like a proper JSON Schema test runner that could eventually simplify your AJV scripts!