Skip to content

Commit

Permalink
add app-config json schema (#988)
Browse files Browse the repository at this point in the history
Signed-off-by: Teo Koon Peng <[email protected]>
  • Loading branch information
koonpeng committed Aug 7, 2024
1 parent 10cc4bd commit 16c2dbe
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 59 deletions.
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

pnpm exec lint-staged
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
".venv/bin/pipenv run black"
]
},
"pnpm": {
"overrides": {
"typescript-json-schema>@types/node": "*"
}
},
"overrides": {
"react-error-overlay": "6.0.9"
}
Expand Down
56 changes: 0 additions & 56 deletions packages/dashboard/app-config.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/dashboard/app-config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "./app-config.schema.json",
"rmfServerUrl": "http://localhost:8000",
"trajectoryServerUrl": "ws://localhost:8006",
"authConfig": {},
Expand Down
194 changes: 194 additions & 0 deletions packages/dashboard/app-config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"BuildConfig": {
"properties": {
"adminTab": {
"type": "boolean"
},
"authProvider": {
"enum": [
"keycloak",
"stub"
],
"type": "string"
},
"baseUrl": {
"type": "string"
},
"customTabs": {
"type": "boolean"
}
},
"required": [
"authProvider",
"baseUrl"
],
"type": "object"
},
"KeycloakAuthConfig": {
"properties": {
"clientId": {
"type": "string"
},
"realm": {
"type": "string"
},
"url": {
"type": "string"
}
},
"required": [
"clientId",
"realm",
"url"
],
"type": "object"
},
"LogoResource": {
"properties": {
"header": {
"type": "string"
}
},
"required": [
"header"
],
"type": "object"
},
"Record<\"default\",Resources>": {
"properties": {
"default": {
"$ref": "#/definitions/Resources"
}
},
"required": [
"default"
],
"type": "object"
},
"Record<string,FleetResource>": {
"type": "object"
},
"Record<string,Resources>": {
"type": "object"
},
"Resources": {
"properties": {
"fleets": {
"$ref": "#/definitions/Record<string,FleetResource>"
},
"logos": {
"$ref": "#/definitions/LogoResource"
}
},
"required": [
"fleets",
"logos"
],
"type": "object"
},
"StubAuthConfig": {
"type": "object"
},
"TaskResource": {
"properties": {
"displayName": {
"type": "string"
},
"taskDefinitionId": {
"type": "string"
}
},
"required": [
"taskDefinitionId"
],
"type": "object"
}
},
"properties": {
"allowedTasks": {
"items": {
"$ref": "#/definitions/TaskResource"
},
"type": "array"
},
"attributionPrefix": {
"type": "string"
},
"authConfig": {
"anyOf": [
{
"$ref": "#/definitions/StubAuthConfig"
},
{
"$ref": "#/definitions/KeycloakAuthConfig"
}
]
},
"buildConfig": {
"$ref": "#/definitions/BuildConfig"
},
"cartIds": {
"items": {
"type": "string"
},
"type": "array"
},
"defaultMapLevel": {
"type": "string"
},
"defaultRobotZoom": {
"type": "number"
},
"defaultZoom": {
"type": "number"
},
"helpLink": {
"type": "string"
},
"pickupZones": {
"items": {
"type": "string"
},
"type": "array"
},
"reportIssue": {
"type": "string"
},
"resources": {
"allOf": [
{
"$ref": "#/definitions/Record<string,Resources>"
},
{
"$ref": "#/definitions/Record<\"default\",Resources>"
}
]
},
"rmfServerUrl": {
"type": "string"
},
"trajectoryServerUrl": {
"type": "string"
}
},
"required": [
"allowedTasks",
"attributionPrefix",
"authConfig",
"buildConfig",
"cartIds",
"defaultMapLevel",
"defaultRobotZoom",
"defaultZoom",
"helpLink",
"pickupZones",
"reportIssue",
"resources",
"rmfServerUrl",
"trajectoryServerUrl"
],
"type": "object"
}

2 changes: 2 additions & 0 deletions packages/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"build": "pnpm run --filter {.}^... build && vite build",
"build-storybook": "storybook build",
"gen-app-config-schema": "pnpm typescript-json-schema tsconfig.gen.json AppConfig --required -o app-config.schema.json",
"lint": "tsc --build && eslint --max-warnings 0 src",
"start": "concurrently npm:start:rmf-server npm:start:react",
"start:airport": "RMF_DASHBOARD_DEMO_MAP=airport_terminal.launch.xml pnpm run start:sim",
Expand Down Expand Up @@ -75,6 +76,7 @@
"history": "^5.3.0",
"storybook": "^8.0.5",
"typescript": "~5.4.3",
"typescript-json-schema": "^0.64.0",
"vite": "^5.3.5",
"vitest": "^2.0.4"
}
Expand Down
19 changes: 19 additions & 0 deletions packages/dashboard/src/app-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @vitest-environment node
*/

import childProcess from 'child_process';
import fs from 'fs';
import { expect, it } from 'vitest';

it('app-config json schema is up to date', () => {
const curSchema = fs.readFileSync('app-config.schema.json');
const newSchema = childProcess.execSync(
'pnpm typescript-json-schema tsconfig.gen.json AppConfig --required',
);
if (!newSchema.equals(curSchema)) {
expect.fail(
'app config schema has changed, please run `pnpm gen-app-config-schema` to update it',
);
}
});
4 changes: 2 additions & 2 deletions packages/dashboard/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src", "app-config.json"]
}
7 changes: 7 additions & 0 deletions packages/dashboard/tsconfig.gen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.app.json",
"compilerOptions": {
"composite": false,
"tsBuildInfoFile": null
}
}
Loading

0 comments on commit 16c2dbe

Please sign in to comment.