Skip to content
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

Validate scenarios against json schema #1475

Merged
merged 16 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/scenario-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Validate scenarios against schema
on:
push:
paths:
- 'data/scenarios/**.yaml'
branches:
- main
pull_request:
paths:
- 'data/scenarios/**.yaml'
branches:
- main
jobs:
validate-scenario-schema:
name: Validate scenarios 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: |
kostmo marked this conversation as resolved.
Show resolved Hide resolved
find data/scenarios -name "*.yaml" -type f -print0 | xargs -0 check-jsonschema --base-uri $(git rev-parse --show-toplevel)/data/schema/scenario.json --schemafile data/schema/scenario.json
kostmo marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions data/scenarios/Challenges/Ranching/gated-paddock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ robots:
- [0, gate]
- [10, hinge]
- name: sheep
description:
- meandering livestock
description: |
meandering livestock
display:
invisible: false
char: '@'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ entities:
char: 'Y'
description:
- Your scooter
robots: []
world:
palette:
'x': [grass, null, base]
Expand Down
2 changes: 1 addition & 1 deletion data/schema/combustion.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"product": {
"default": "ash",
"type": "string",
"type": ["string", "null"],
"description": "What entity, if any, is left over after combustion"
}
}
Expand Down
14 changes: 14 additions & 0 deletions data/schema/cosmicloc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/cosmicloc.json",
"title": "Cosmic location",
"description": "Planar location plus subworld",
"type": "object",
"properties": {
"subworld": {
"type": "string",
"description": "Name of subworld"
},
"loc": {"$ref": "./planarloc.json"}
}
}
4 changes: 2 additions & 2 deletions data/schema/entities.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"display": {
"type": "object",
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/display.json",
"$ref": "./display.json",
"description": "Display information for the entity."
},
"plural": {
Expand Down Expand Up @@ -63,7 +63,7 @@
},
"combustion": {
"type": "object",
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/combustion.json",
"$ref": "./combustion.json",
"description": "Properties of combustion."
},
"yields": {
Expand Down
17 changes: 17 additions & 0 deletions data/schema/planarloc.json
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/planarloc.json",
"title": "Cosmic location",
kostmo marked this conversation as resolved.
Show resolved Hide resolved
"description": "Planar location",
kostmo marked this conversation as resolved.
Show resolved Hide resolved
"type": "array",
"items": [
{
"name": "X coordinate",
"type": "number"
},
{
"name": "Y coordinate",
"type": "number"
}
]
}
6 changes: 3 additions & 3 deletions data/schema/recipes.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
],
"properties": {
"in": {
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/inventory.json",
"$ref": "./inventory.json",
"description": "A list of ingredients consumed by the recipe. Each ingredient is a tuple consisting of an integer and an entity name, indicating the number of copies of the given entity that are needed."
},
"out": {
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/inventory.json",
"$ref": "./inventory.json",
"description": "A list of outputs produced by the recipe. It is a list of [count, entity name] tuples just like in."
},
"required": {
"default": [],
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/inventory.json",
"$ref": "./inventory.json",
kostmo marked this conversation as resolved.
Show resolved Hide resolved
"description": "A list of catalysts required by the recipe. They are neither consumed nor produced, but must be present in order for the recipe to be carried out. It is a list of [count, entity name] tuples just like in and out."
},
"time": {
Expand Down
22 changes: 7 additions & 15 deletions data/schema/robot.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@
"description": "A description of the robot, given as a list of paragraphs. This is currently not used for much (perhaps not at all?)."
},
"loc": {
"default": null,
"type": "array",
"items": [
{
"name": "X coordinate",
"type": "number"
},
{
"name": "Y coordinate",
"type": "number"
}
],
"description": "An optional (x,y) starting location for the robot. If the loc field is specified, then a concrete robot will be created at the given location. If this field is omitted, then this robot record exists only as a template which can be referenced from a cell in the world palette. Concrete robots will then be created wherever the corresponding palette character is used in the world map."
"description": "An optional (x,y) starting location for the robot. If the loc field is specified, then a concrete robot will be created at the given location. If this field is omitted, then this robot record exists only as a template which can be referenced from a cell in the world palette. Concrete robots will then be created wherever the corresponding palette character is used in the world map.",
kostmo marked this conversation as resolved.
Show resolved Hide resolved
"oneOf": [
{"$ref": "./cosmicloc.json"},
{"$ref": "./planarloc.json"}
]
},
"dir": {
"type": "array",
Expand All @@ -46,7 +38,7 @@
},
"display": {
"default": "default",
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/display.json",
"$ref": "./display.json",
"description": "Display information for the robot. If this field is omitted, the default robot display will be used."
},
"program": {
Expand All @@ -64,7 +56,7 @@
},
"inventory": {
"default": [],
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/inventory.json",
"$ref": "./inventory.json",
"description": "A list of [count, entity name] pairs, specifying the entities in the robot's starting inventory, and the number of each."
},
"system": {
Expand Down
3 changes: 3 additions & 0 deletions data/schema/samples/combustion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignition: 1
duration: [8, 8]
product: null
8 changes: 4 additions & 4 deletions data/schema/scenario.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
"entities": {
"description": "An optional list of custom entities, to be used in addition to the built-in entities. See description of Entities.",
"default": [],
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/entities.json"
"$ref": "./entities.json"
},
"recipes": {
"description": "An optional list of custom recipes, to be used in addition to the built-in recipes. They can refer to built-in entities as well as custom entities. See description of Recipes.",
"default": [],
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/recipes.json"
"$ref": "./recipes.json"
},
"known": {
"description": "A list of names of standard or custom entities which should have the Known property added to them; that is, robots should know what they are without having to scan them.",
Expand All @@ -52,13 +52,13 @@
]
},
"world": {
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/world.json"
"$ref": "./world.json"
},
"robots": {
"description": "A list of robots that will inhabit the world. See the description of Robots.",
"type": "array",
"items": {
"$ref": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/robot.json"
"$ref": "./robot.json"
}
},
"objectives": {
Expand Down