Skip to content

Commit

Permalink
Integrate with the JSON Schema CLI for formatting and linting
Browse files Browse the repository at this point in the history
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
automatically validate the examples in the repo.

Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Jun 5, 2024
1 parent 9bc65a4 commit 779f60f
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 315 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Test

on: [ push, pull_request ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: intelligence-ai/[email protected]
- run: jsonschema lint *.schema.json --verbose
- run: jsonschema fmt *.schema.json --check --verbose
50 changes: 30 additions & 20 deletions channeldata-1.schema.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://schemas.conda.io/channeldata-1.schema.json",
"type": "object",
"title": "channeldata.json",
"description": "The channeldata file contains information that is common to the channel as a whole. Split out by package name, the information for each package name should be the latest available and consistent across all subdirs.",
"type": "object",
"required": [
"schema_version"
],
"properties": {
"$schema": {
"type": "string",
"const": "https://schemas.conda.io/channeldata-1.schema.json",
"format": "uri"
},
"schema_version": {
"type": "integer",
"description": "The API version or schema version of the channeldata file.",
"const": 1
},
"packages": {
"description": "The value for each key is a package name contained within the channel.",
"patternProperties": {
Expand All @@ -27,17 +21,23 @@
},
"additionalProperties": false
},
"schema_version": {
"description": "The API version or schema version of the channeldata file.",
"const": 1
},
"subdirs": {
"description": "All subdirs contained within the channel.",
"type": "array",
"items": {"$ref": "common-1.schema.json#/definitions/subdir"},
"description": "All subdirs contained within the channel."
"items": {
"$ref": "common-1.schema.json#/definitions/subdir"
}
}
},
"definitions": {
"channeldata_record": {
"$id": "#/definitions/channeldata_record",
"type": "object",
"description": "Information about the latest version of each package name contained within the channel.",
"type": "object",
"required": [
"reference_package",
"version"
Expand Down Expand Up @@ -81,30 +81,40 @@
"license": {
"type": "string"
},
"license_family": {"$ref": "common-1.schema.json#/definitions/license_family"},
"spdx_license": {"$ref": "common-1.schema.json#/definitions/spdx_license"},
"source_git_url": {
"type": "string",
"format": "uri"
"license_family": {
"$ref": "common-1.schema.json#/definitions/license_family"
},
"reference_package": {
"description": "The {subdir}/{fn} that was used to create the entry in channeldata.",
"type": "string"
},
"source_git_url": {
"type": "string",
"description": "The {subdir}/{fn} that was used to create the entry in channeldata."
"format": "uri"
},
"source_url": {
"type": "string",
"format": "uri"
},
"spdx_license": {
"$ref": "common-1.schema.json#/definitions/spdx_license"
},
"subdirs": {
"type": "array",
"items": {"$ref": "common-1.schema.json#/definitions/subdir"}
"items": {
"$ref": "common-1.schema.json#/definitions/subdir"
}
},
"summary": {
"type": "string"
},
"timestamp": {"$ref": "common-1.schema.json#/definitions/timestamp"},
"version": {"$ref": "common-1.schema.json#/definitions/package_version"}
"timestamp": {
"$ref": "common-1.schema.json#/definitions/timestamp"
},
"version": {
"$ref": "common-1.schema.json#/definitions/package_version"
}
}
}
}
}
}
Loading

0 comments on commit 779f60f

Please sign in to comment.