-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate scenarios against json schema (#1475)
Closes #1428 Since the authoritative validation of scenario files is actually performed by virtue of `swarm` parsing them, this CI job actually exists to ensure the JSON Schema descriptions are accurate. This is important for two purposes: * Documentation is generated from the JSON Schema files (#1436) * JSON Schema has integration with VS Code and other IDEs # Testing Verified that the schema checker action does indeed work by intentionally pushing an invalid scenario file in f789f81.
- Loading branch information
Showing
20 changed files
with
382 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: JSON schema | ||
on: | ||
push: | ||
paths: | ||
- 'data/scenarios/**.yaml' | ||
branches: | ||
- main | ||
pull_request: | ||
paths: | ||
- 'data/scenarios/**.yaml' | ||
branches: | ||
- main | ||
jobs: | ||
validate-scenario-schema: | ||
name: Validate scenarios against schema | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install check-jsonschema | ||
- run: | | ||
scripts/validate-json-schemas.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ entities: | |
char: 'Y' | ||
description: | ||
- Your scooter | ||
robots: [] | ||
world: | ||
palette: | ||
'x': [grass, null, base] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/attribute.json", | ||
"title": "Scenario-local attributes", | ||
"description": "Local attribute definitions", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Name of attribute" | ||
}, | ||
"fg": { | ||
"type": "string", | ||
"description": "Foreground color" | ||
}, | ||
"bg": { | ||
"type": "string", | ||
"description": "Background color" | ||
}, | ||
"style": { | ||
"description": "Style properties list", | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/cosmic-loc.json", | ||
"title": "Cosmic location", | ||
"description": "Planar location plus subworld", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"subworld": { | ||
"type": "string", | ||
"description": "Name of subworld" | ||
}, | ||
"loc": {"$ref": "./planar-loc.json"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/explicit-waypoint.json", | ||
"title": "Waypoint", | ||
"description": "Explicit waypoint definition", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"name": { | ||
"description": "Waypoint name", | ||
"type": "string" | ||
}, | ||
"loc": {"$ref": "./planar-loc.json"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/objective.json", | ||
"title": "Scenario goals and their prerequisites", | ||
"description": "The top-level objectives field contains a list of objectives that must be completed in sequence. Each objective has a goal description and a condition.", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"goal": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "string" | ||
} | ||
], | ||
"description": "The goal description as a list of paragraphs that the player can read." | ||
}, | ||
"condition": { | ||
"description": "A swarm program that will be hypothetically run each tick to check if the condition is fulfilled.", | ||
"type": "string" | ||
}, | ||
"id": { | ||
"description": "A short identifier for referencing as a prerequisite", | ||
"type": "string" | ||
}, | ||
"optional": { | ||
"description": "Whether completion of this objective is required to achieve a 'Win' of the scenario", | ||
"type": "boolean" | ||
}, | ||
"hidden": { | ||
"description": "Whether this goal should be suppressed from the Goals dialog prior to achieving it", | ||
"type": "boolean" | ||
}, | ||
"teaser": { | ||
"description": "A compact (2-3 word) summary of the goal", | ||
"type": "string" | ||
}, | ||
"prerequisite": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/placement.json", | ||
"title": "Swarm structure placement", | ||
"description": "Structure placement", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"src": { | ||
"type": "string", | ||
"description": "Name of structure definition" | ||
}, | ||
"offset": { | ||
"$ref": "./planar-loc.json" | ||
}, | ||
"orient": { | ||
"description": "Orientation of structure", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"up": { | ||
"type": "string" | ||
}, | ||
"flip": { | ||
"type": "boolean" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/planar-loc.json", | ||
"title": "Planar location", | ||
"description": "x and y coordinates of a location in a particular world", | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"name": "X coordinate", | ||
"type": "number" | ||
}, | ||
{ | ||
"name": "Y coordinate", | ||
"type": "number" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/portal.json", | ||
"title": "Portals", | ||
"description": "Portal definition", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"entrance": { | ||
"type": "string", | ||
"description": "Name of entrance waypoint" | ||
}, | ||
"reorient": { | ||
"description": "Passing through this portal changes a robot's orientation", | ||
"type": "string" | ||
}, | ||
"consistent": { | ||
"description": "Whether this portal is spatially consistent across worlds", | ||
"type": "boolean" | ||
}, | ||
"exitInfo": { | ||
"description": "Exit definition", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"exit": { | ||
"type": "string", | ||
"description": "Name of exit waypoint" | ||
}, | ||
"subworldName": { | ||
"type": "string", | ||
"description": "Name of exit subworld" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.