Skip to content

Commit

Permalink
Validate schemas and fix them accordingly
Browse files Browse the repository at this point in the history
Add validation of jsonschemas to our CI.
The links and embeddedlinks schemas where invalid,
as well as the references to them from the event
schemas, so fixing all those to let CI pass.

Switch to ajv for example validation, which allows for
validation of both JSON documents as well as schemas.

ajv let users load references schemas from files into
the tool offline databases, which enables offline
validation of unpublished schemas.

Since ajv is javascript, update the GitHub action
workflow to javascript.

Fixes: #208
Fixes: #211

Signed-off-by: Andrea Frittoli <andrea.frittoli@gmail.com>
  • Loading branch information
afrittoli committed May 10, 2024
1 parent b462f84 commit 3c0100b
Show file tree
Hide file tree
Showing 55 changed files with 678 additions and 353 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: CDEvents
on:
# Triggers the workflow on push or pull request events but only for the main branch
pull_request:
branches: [ main ]
branches: [ main, spec-v* ]

###############
# Set the Job #
Expand Down Expand Up @@ -33,20 +33,24 @@ jobs:
VALIDATE_MARKDOWN: true

jsonschema:
name: Validate Examples
name: Validate Schemas and Examples
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
go-version: 1.19

- name: Validate Examples
run: ./tools/verify-examples.sh
node-version: 20
cache: npm
cache-dependency-path: tools/package-lock.json
- name: Install dependencies
run: |
cd tools
npm install -g --no-fund ajv-cli ajv-formats
- name: Run Validate
run: ./tools/validate.sh

spellcheck:
name: Spellcheck (en_US)
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

# Mac
.DS_Store

# JS
tools/node_modules
2 changes: 1 addition & 1 deletion schemas/artifactdeleted.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/artifactdownloaded.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/artifactpackaged.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/artifactpublished.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/artifactsigned.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/branchcreated.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/branchdeleted.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/buildfinished.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/buildqueued.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/buildstarted.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/changeabandoned.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/changecreated.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/changemerged.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/changereviewed.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/changeupdated.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/environmentcreated.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/environmentdeleted.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/environmentmodified.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/incidentdetected.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/incidentreported.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion schemas/incidentresolved.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"minLength": 1
},
"links": {
"$ref": "/schema/links/embeddedlinksarray.json"
"$ref": "links/embeddedlinksarray"
}
},
"additionalProperties": false,
Expand Down
46 changes: 25 additions & 21 deletions schemas/links/embeddedlinkend.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
{
"link_type": {
"type": "string",
"enum": [
"END"
]
},
"from": {
"description": "When consuming a CDEvent, you are consuming a parent event. So, when looking at the 'from' key, this is the parent's parent.",
"type": "object",
"properties": {
"context_id": {
"type": "string",
"minLength": 1
}
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://cdevents.dev/0.4.0/schema/links/embeddedlinkend",
"properties": {
"link_type": {
"type": "string",
"enum": [
"END"
]
},
"required": [
"context_id"
]
},
"tags": {
"type": "object",
"additionalProperties": true
"from": {
"description": "When consuming a CDEvent, you are consuming a parent event. So, when looking at the 'from' key, this is the parent's parent.",
"type": "object",
"properties": {
"context_id": {
"type": "string",
"minLength": 1
}
},
"required": [
"context_id"
]
},
"tags": {
"type": "object",
"additionalProperties": true
}
},
"additionalProperties": false,
"type": "object",
Expand Down
46 changes: 25 additions & 21 deletions schemas/links/embeddedlinkpath.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
{
"link_type": {
"type": "string",
"enum": [
"PATH"
]
},
"from": {
"description": "When consuming a CDEvent, you are consuming a parent event. So, when looking at the 'from' key, this is the parent's parent.",
"type": "object",
"properties": {
"context_id": {
"type": "string",
"minLength": 1
}
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://cdevents.dev/0.4.0/schema/links/embeddedlinkpath",
"properties": {
"link_type": {
"type": "string",
"enum": [
"PATH"
]
},
"required": [
"context_id"
]
},
"tags": {
"type": "object",
"additionalProperties": true
"from": {
"description": "When consuming a CDEvent, you are consuming a parent event. So, when looking at the 'from' key, this is the parent's parent.",
"type": "object",
"properties": {
"context_id": {
"type": "string",
"minLength": 1
}
},
"required": [
"context_id"
]
},
"tags": {
"type": "object",
"additionalProperties": true
}
},
"additionalProperties": false,
"type": "object",
Expand Down
46 changes: 25 additions & 21 deletions schemas/links/embeddedlinkrelation.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
{
"link_type": {
"type": "string",
"enum": [
"RELATION"
]
},
"link_kind": {
"type": "string",
"minLength": 1
},
"target": {
"description": "",
"type": "object",
"properties": {
"context_id": {
"type": "string",
"minLength": 1
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://cdevents.dev/0.4.0/schema/links/embeddedlinkrelation",
"properties": {
"link_type": {
"type": "string",
"enum": [
"RELATION"
]
},
"link_kind": {
"type": "string",
"minLength": 1
},
"target": {
"description": "",
"type": "object",
"properties": {
"context_id": {
"type": "string",
"minLength": 1
}
}
},
"tags": {
"type": "object",
"additionalProperties": true
}
},
"tags": {
"type": "object",
"additionalProperties": true
},
"additionalProperties": false,
"type": "object",
"required": [
Expand Down
Loading

0 comments on commit 3c0100b

Please sign in to comment.