Skip to content

Commit 392e368

Browse files
committed
Integrate with the JSON Schema CLI for formatting and linting
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 <jv@jviotti.com>
1 parent ed28ed2 commit 392e368

28 files changed

Lines changed: 738 additions & 488 deletions

.github/workflows/validate.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v4
10+
- uses: intelligence-ai/jsonschema@v0.5.0
11+
- run: jsonschema lint gcn --extension .schema.json --verbose
12+
- run: jsonschema fmt gcn --extension .schema.json --check --verbose
1013
- name: Install Node.js
1114
uses: actions/setup-node@v4
1215
with:

gcn/notices/burstcube/alert.schema.json

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11
{
2-
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/burstcube/alert.schema.json",
32
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/burstcube/alert.schema.json",
44
"title": "Alert",
55
"description": "BurstCube Trigger Alert",
66
"type": "object",
77
"allOf": [
8-
{ "$ref": "../core/Alert.schema.json" },
9-
{ "$ref": "../core/Reporter.schema.json" },
10-
{ "$ref": "../core/DateTime.schema.json" },
11-
{ "$ref": "../core/Event.schema.json" },
12-
{ "$ref": "../core/Localization.schema.json" },
13-
{ "$ref": "../core/Statistics.schema.json" },
14-
{ "$ref": "../core/Duration.schema.json" }
8+
{
9+
"$ref": "../core/Alert.schema.json"
10+
},
11+
{
12+
"$ref": "../core/Reporter.schema.json"
13+
},
14+
{
15+
"$ref": "../core/DateTime.schema.json"
16+
},
17+
{
18+
"$ref": "../core/Event.schema.json"
19+
},
20+
{
21+
"$ref": "../core/Localization.schema.json"
22+
},
23+
{
24+
"$ref": "../core/Statistics.schema.json"
25+
},
26+
{
27+
"$ref": "../core/Duration.schema.json"
28+
}
1529
],
1630
"properties": {
1731
"detector_status": {
1832
"type": "object",
1933
"properties": {
20-
"CsI0": { "$ref": "../core/DetectorStatus.schema.json" },
21-
"CsI1": { "$ref": "../core/DetectorStatus.schema.json" },
22-
"CsI2": { "$ref": "../core/DetectorStatus.schema.json" },
23-
"CsI3": { "$ref": "../core/DetectorStatus.schema.json" }
34+
"CsI0": {
35+
"$ref": "../core/DetectorStatus.schema.json"
36+
},
37+
"CsI1": {
38+
"$ref": "../core/DetectorStatus.schema.json"
39+
},
40+
"CsI2": {
41+
"$ref": "../core/DetectorStatus.schema.json"
42+
},
43+
"CsI3": {
44+
"$ref": "../core/DetectorStatus.schema.json"
45+
}
2446
}
2547
}
2648
}

gcn/notices/burstcube/test.schema.json

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11
{
2-
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/burstcube/test.schema.json",
32
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/burstcube/test.schema.json",
44
"title": "Alert",
55
"description": "BurstCube Trigger Alert",
66
"type": "object",
77
"allOf": [
8-
{ "$ref": "../core/Alert.schema.json" },
9-
{ "$ref": "../core/Reporter.schema.json" },
10-
{ "$ref": "../core/DateTime.schema.json" },
11-
{ "$ref": "../core/Event.schema.json" },
12-
{ "$ref": "../core/Localization.schema.json" },
13-
{ "$ref": "../core/Statistics.schema.json" },
14-
{ "$ref": "../core/Duration.schema.json" }
8+
{
9+
"$ref": "../core/Alert.schema.json"
10+
},
11+
{
12+
"$ref": "../core/Reporter.schema.json"
13+
},
14+
{
15+
"$ref": "../core/DateTime.schema.json"
16+
},
17+
{
18+
"$ref": "../core/Event.schema.json"
19+
},
20+
{
21+
"$ref": "../core/Localization.schema.json"
22+
},
23+
{
24+
"$ref": "../core/Statistics.schema.json"
25+
},
26+
{
27+
"$ref": "../core/Duration.schema.json"
28+
}
1529
],
1630
"properties": {
1731
"detector_status": {
1832
"type": "object",
1933
"properties": {
20-
"CsI0": { "$ref": "../core/DetectorStatus.schema.json" },
21-
"CsI1": { "$ref": "../core/DetectorStatus.schema.json" },
22-
"CsI2": { "$ref": "../core/DetectorStatus.schema.json" },
23-
"CsI3": { "$ref": "../core/DetectorStatus.schema.json" }
34+
"CsI0": {
35+
"$ref": "../core/DetectorStatus.schema.json"
36+
},
37+
"CsI1": {
38+
"$ref": "../core/DetectorStatus.schema.json"
39+
},
40+
"CsI2": {
41+
"$ref": "../core/DetectorStatus.schema.json"
42+
},
43+
"CsI3": {
44+
"$ref": "../core/DetectorStatus.schema.json"
45+
}
2446
}
2547
}
2648
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/AdditionalInfo.schema.json",
32
"$schema": "https://json-schema.org/draft/2020-12/schema",
4-
"type": "object",
3+
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/AdditionalInfo.schema.json",
54
"title": "Comments",
65
"description": "Comments that are not summarized elsewhere in schema",
6+
"type": "object",
77
"properties": {
88
"additional_info": {
9-
"type": "string",
10-
"description": "Additional information about the event"
9+
"description": "Additional information about the event",
10+
"type": "string"
1111
}
1212
}
1313
}

gcn/notices/core/Alert.schema.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
{
2-
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/Alert.schema.json",
32
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/Alert.schema.json",
44
"title": "Alert",
55
"description": "Alert Information description properties of this notice",
66
"type": "object",
77
"properties": {
88
"alert_datetime": {
9-
"type": "string",
10-
"description": "Date and time of notice creation [UTC, ISO 8601], ex YYYY-MM-DDTHH:MM:SS.ssssssZ"
9+
"description": "Date and time of notice creation [UTC, ISO 8601], ex YYYY-MM-DDTHH:MM:SS.ssssssZ",
10+
"type": "string"
1111
},
1212
"alert_tense": {
13+
"description": "Indication of whether this alert refers to a recent observation (current), re-analysis of archival data (archival), a planned observation in the future (planned), a signal injection (injection), commanded trigger (commanded) or a test trigger (test).",
1314
"enum": [
1415
"current",
1516
"archival",
1617
"planned",
1718
"injection",
1819
"commanded",
1920
"test"
20-
],
21-
"description": "Indication of whether this alert refers to a recent observation (current), re-analysis of archival data (archival), a planned observation in the future (planned), a signal injection (injection), commanded trigger (commanded) or a test trigger (test)."
21+
]
2222
},
2323
"alert_type": {
24-
"enum": ["initial", "update", "retraction"],
25-
"description": "Indication of alert sequence if multiple of same type sent"
24+
"description": "Indication of alert sequence if multiple of same type sent",
25+
"enum": [
26+
"initial",
27+
"update",
28+
"retraction"
29+
]
2630
}
2731
}
2832
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
2-
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/DateTime.schema.json",
32
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/DateTime.schema.json",
44
"title": "DateTime",
55
"description": "Time descriptions of transient event and observation",
66
"type": "object",
77
"properties": {
8-
"trigger_time": {
9-
"type": "string",
10-
"description": "Time of the trigger [ISO 8601], ex YYYY-MM-DDTHH:MM:SS.ssssssZ"
8+
"observation_livetime": {
9+
"description": "Livetime of the observation [s]",
10+
"type": "number"
1111
},
1212
"observation_start": {
13-
"type": "string",
14-
"description": "Start time of the observation [ISO 8601]"
13+
"description": "Start time of the observation [ISO 8601]",
14+
"type": "string"
1515
},
1616
"observation_stop": {
17-
"type": "string",
18-
"description": "Stop time of the observation [ISO 8601]"
17+
"description": "Stop time of the observation [ISO 8601]",
18+
"type": "string"
1919
},
20-
"observation_livetime": {
21-
"type": "number",
22-
"description": "Livetime of the observation [s]"
20+
"trigger_time": {
21+
"description": "Time of the trigger [ISO 8601], ex YYYY-MM-DDTHH:MM:SS.ssssssZ",
22+
"type": "string"
2323
}
2424
}
2525
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/DetectorStatus.schema.json",
32
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/DetectorStatus.schema.json",
44
"title": "DetectorStatus",
5-
"enum": ["on", "off", "triggered"],
6-
"description": "Status of a specified detector at the time of the alert"
5+
"description": "Status of a specified detector at the time of the alert",
6+
"enum": [
7+
"on",
8+
"off",
9+
"triggered"
10+
]
711
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
{
2-
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/Distance.schema.json",
32
"$schema": "https://json-schema.org/draft/2020-12/schema",
4-
"type": "object",
3+
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/Distance.schema.json",
54
"title": "Distance",
65
"description": "Luminosity Distance",
6+
"type": "object",
77
"properties": {
88
"luminosity_distance": {
9-
"type": "number",
10-
"description": "Luminosity distance [Mpc]"
9+
"description": "Luminosity distance [Mpc]",
10+
"type": "number"
1111
},
1212
"luminosity_distance_error": {
13+
"description": "Luminosity distance uncertainty [Mpc, 1-sigma], with optional asymmetric uncertainty",
1314
"type": "array",
14-
"items": { "type": "number" },
1515
"maxItems": 2,
16-
"description": "Luminosity distance uncertainty [Mpc, 1-sigma], with optional asymmetric uncertainty"
16+
"items": {
17+
"type": "number"
18+
}
1719
}
1820
}
1921
}
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
{
2-
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/Duration.schema.json",
32
"$schema": "https://json-schema.org/draft/2020-12/schema",
4-
"type": "object",
3+
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/Duration.schema.json",
54
"title": "Duration",
5+
"type": "object",
66
"properties": {
7-
"t90": {
8-
"type": "number",
9-
"description": "Time duration of central 90% of integrated fluence [s]"
7+
"t50": {
8+
"description": "Time duration of central 50% of integrated fluence [s]",
9+
"type": "number"
1010
},
11-
"t90_error": {
11+
"t50_error": {
12+
"description": "1-sigma uncertainty of the T50 duration [s], with asymmetric statistical errors taken into account",
1213
"type": "array",
13-
"items": { "type": "number" },
1414
"maxItems": 2,
15-
"description": "1-sigma uncertainty of the T90 duration [s], with asymmetric statistical errors taken into account"
15+
"items": {
16+
"type": "number"
17+
}
1618
},
17-
"t50": {
18-
"type": "number",
19-
"description": "Time duration of central 50% of integrated fluence [s]"
19+
"t90": {
20+
"description": "Time duration of central 90% of integrated fluence [s]",
21+
"type": "number"
2022
},
21-
"t50_error": {
23+
"t90_error": {
24+
"description": "1-sigma uncertainty of the T90 duration [s], with asymmetric statistical errors taken into account",
2225
"type": "array",
23-
"items": { "type": "number" },
2426
"maxItems": 2,
25-
"description": "1-sigma uncertainty of the T50 duration [s], with asymmetric statistical errors taken into account"
27+
"items": {
28+
"type": "number"
29+
}
2630
}
2731
}
2832
}

gcn/notices/core/Event.schema.json

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
{
2-
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/Event.schema.json",
32
"$schema": "https://json-schema.org/draft/2020-12/schema",
4-
"type": "object",
3+
"$id": "https://gcn.nasa.gov/schema/main/gcn/notices/core/Event.schema.json",
54
"title": "Event Information",
65
"description": "Name or names of the event",
6+
"type": "object",
77
"properties": {
8-
"event_name": {
9-
"type": "array",
10-
"items": { "type": "string" },
11-
"description": "Name of the event (ex: GRB 170817A, GW170817, AT2017gfo, SSS 17a)"
12-
},
138
"id": {
9+
"description": "Instrument-specific trigger ID (ex: bn230313485 (Fermi), 1159327 (Swift)) or alternate ID",
1410
"type": "array",
15-
"items": { "oneOf": [{ "type": "string" }, { "type": "number" }] },
16-
"description": "Instrument-specific trigger ID (ex: bn230313485 (Fermi), 1159327 (Swift)) or alternate ID"
11+
"items": {
12+
"oneOf": [
13+
{
14+
"type": "string"
15+
},
16+
{
17+
"type": "number"
18+
}
19+
]
20+
}
1721
},
1822
"data_archive_page": {
19-
"type": "string",
20-
"description": "URL of archived data files"
23+
"description": "URL of archived data files",
24+
"type": "string"
25+
},
26+
"event_name": {
27+
"description": "Name of the event (ex: GRB 170817A, GW170817, AT2017gfo, SSS 17a)",
28+
"type": "array",
29+
"items": {
30+
"type": "string"
31+
}
2132
}
2233
}
2334
}

0 commit comments

Comments
 (0)