Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 42 additions & 0 deletions .github/workflows/frontend-json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: JSON validate Frontend service

on:
push:
branches:
- main
paths:
- 'frontend/pbtar_schema.json'
- 'frontend/src/data/scenarios_metadata.json'
- '.github/workflows/frontend-json.yml'
pull_request:
branches:
- main
paths:
- 'frontend/pbtar_schema.json'
- 'frontend/src/data/scenarios_metadata.json'
- '.github/workflows/frontend-json.yml'
workflow_dispatch:

jobs:
lint:
name: "Run ajv JSON validator"
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json

- name: Install dependencies
working-directory: ./frontend
run: npm ci

- name: Run ajv JSON validator
working-directory: ./frontend
run: npm run json:check
153 changes: 153 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
"format:check": "prettier --check ."
"format:check": "prettier --check .",
"json:check": "ajv validate -s pbtar_schema.json src/data/scenarios_metadata.json"
},
"author": "RMI",
"license": "MIT",
Expand All @@ -25,6 +26,7 @@
},
"devDependencies": {
"@eslint/js": "^9.27.0",
"@jirutka/ajv-cli": "^6.0.0",
"@tailwindcss/postcss": "^4.1.7",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0",
Expand Down
103 changes: 103 additions & 0 deletions frontend/pbtar_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "pbtar_schema.json",
"title": "PBTAR Scenarios metadata Schema",
"description": "A schema for the scenarios metadata dataset in PBTAR",
"type": "array",
"items": {
"type": "object",
"properties": {
Comment thread
cjyetman marked this conversation as resolved.
"id": {
"description": "The unique identifier for a scenario",
"type": "string"
},
"name": {
"description": "Name of the scenario",
"type": "string"
},
"description": {
"description": "Description of the scenario",
"type": "string"
},
"category": {
"description": "Category of the scenario",
"type": "string"
},
"target_year": {
"description": "Target year of the scenario",
"type": "string"
},
"target_temperature": {
"description": "Target temperature of the scenario",
"type": "string"
},
"regions": {
"description": "Regions that the scenario covers",
"type": "array",
"uniqueItems": true,
"items": {
"type": "string"
}
},
"sectors": {
"description": "Sectors that the scenario covers",
"type": "array",
"items": {
"enum": [
"Agriculture",
"Buildings",
"Coal",
"Industrial",
"Oil & Gas",
"Power",
"Renewables",
"Transport"
]
}
},
"publisher": {
"description": "Publisher of the scenario",
"type": "string"
},
"published_date": {
"description": "Date that the scenario was published",
"type": "string"
},
"overview": {
"description": "Overview of the scenario",
"type": "string"
},
"expertRecommendation": {
"description": "Expert recommendation for the scenario",
"type": "string"
},
"dataSource": {
"description": "Data source for the scenario",
"type": "object",
"properties": {
"description": { "type": "string" },
"url": { "type": "string" },
"downloadAvailable": { "type": "boolean" }
},
"additionalProperties": false,
"required": ["description", "url", "downloadAvailable"]
}
},
"additionalProperties": false,
"required": [
"id",
"name",
"description",
"category",
"target_year",
"target_temperature",
"regions",
"sectors",
"publisher",
"published_date",
"overview",
"expertRecommendation",
"dataSource"
]
}
}