Skip to content

Commit

Permalink
Create minimal reference schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberixae committed Aug 30, 2023
1 parent d406509 commit 977e78e
Show file tree
Hide file tree
Showing 21 changed files with 508 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/cd-maasglobal-reference-schemas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CD maasglobal-reference-schemas

on:
push:
branches:
- main
paths:
- 'maasglobal-reference-schemas/package.json'
- '.github/workflows/cd-maasglobal-reference-schemas.yml'

defaults:
run:
working-directory: maasglobal-reference-schemas

env:
NODE_AUTH_TOKEN: ${{ secrets.PUBLIC_NPM_TOKEN }}

jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 15
name: publish
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "14"
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
run: |
yarn
- name: Deploy to Registry
run: |
yarn deploy-npm
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ jobs:
run: |
yarn --cwd maasglobal-schema-generator-io-ts ci
test-reference-schemas:
runs-on: ubuntu-latest
timeout-minutes: 15
name: test reference schemas
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "14"
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
run: |
yarn --cwd maasglobal-reference-schemas
- name: Run Tests
run: |
yarn --cwd maasglobal-reference-schemas ci
test-maas-schemas:
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down
12 changes: 12 additions & 0 deletions maasglobal-reference-schemas/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# IDE Stuff
**/.idea
.vscode/launch.json
*.swp

# OS STUFF
.DS_Store
.tmp
13 changes: 13 additions & 0 deletions maasglobal-reference-schemas/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
package-lock.json

# IDE Stuff
**/.idea
.vscode/launch.json
*.swp

# OS STUFF
.DS_Store
.tmp
1 change: 1 addition & 0 deletions maasglobal-reference-schemas/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('eslint-config-maasglobal-ts/prettierrc.js');
9 changes: 9 additions & 0 deletions maasglobal-reference-schemas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# MaaS Global Reference Schemas

This repository contains definitions and examples for the JSON Schema format used by MaaS Global.
The format is currently a subset of `http://json-schema.org/draft-07/schema#` and
`https://json-schema.org/draft/2019-09/vocab/hyper-schema`.

The way we describe tuples seem to be from some earlier version of the specification.

Also, our schemas contain a custom keyword `invalid` with negative test cases.
33 changes: 33 additions & 0 deletions maasglobal-reference-schemas/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "maasglobal-reference-schemas",
"version": "0.0.1",
"description": "Test suite for JSON schema features used by MaaS Global",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/maasglobal/maas-schemas.git"
},
"keywords": [
"schemas",
"maas",
"JSON"
],
"bugs": {
"url": "https://github.com/maasglobal/maas-schemas/issues"
},
"homepage": "https://github.com/maasglobal/maas-schemas/",
"dependencies": {},
"devDependencies": {
"eslint-config-maasglobal-ts": "^0.0.14",
"prettier": "^2.8.1"
},
"scripts": {
"prettier-check": "yarn prettier --check '**/*.{css,html,js,ts,json,md,yaml,yml}'",
"prettier-fix": "yarn prettier-check --write",
"prettify": "yarn prettier-fix",
"lint": "yarn prettier-check",
"ci": "yarn lint",
"deploy-npm": "yarn ci && yarn publish --non-interactive",
"deploy-alpha": "yarn deploy-npm --tag alpha"
}
}
16 changes: 16 additions & 0 deletions maasglobal-reference-schemas/schemas/array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://reference-schemas.maas.global/array.json",
"title": "Array",
"description": "An ordered collection of homogenous values, with duplicates allowed. See Set and Tuple for other array based structures.",
"definitions": {
"exampleArray": {
"type": "array",
"items": { "type": "string" },
"contains": { "type": "string", "const": "foo" },
"minItems": 1,
"maxItems": 10,
"examples": [["asdf", "foo", "qwer"]]
}
}
}
31 changes: 31 additions & 0 deletions maasglobal-reference-schemas/schemas/combinator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://reference-schemas.maas.global/combinator.json",
"title": "Combinator Reference Schemas",
"description": "Keywords that combine several schemas into one.",
"definitions": {
"nonNegative": {
"type": "number",
"minimum": 0
},
"integer": {
"type": "integer"
},
"nonNegativeInteger": {
"allOf": [
{ "$ref": "#/definitions/nonNegative" },
{ "$ref": "#/definitions/integer" }
]
},

"email": {
"type": "string"
},
"username": {
"type": "string"
},
"login": {
"anyOf": [{ "$ref": "#/definitions/email" }, { "$ref": "#/definitions/username" }]
}
}
}
10 changes: 10 additions & 0 deletions maasglobal-reference-schemas/schemas/comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://reference-schemas.maas.global/comment.json",
"$comment": "This is a toplevel comment",
"definitions": {
"exampleDefinition": {
"$comment": "This is a definition comment"
}
}
}
33 changes: 33 additions & 0 deletions maasglobal-reference-schemas/schemas/enum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://reference-schemas.maas.global/enum.json",
"title": "Enum Reference Schemas",
"description": "Basic enum definitions should work as expected. Separate accessors can be defined for each value.",
"definitions": {
"timeOfDay": {
"type": "string",
"enum": ["night", "day"],
"examples": ["night", "day"]
},
"timeOfDayNIGHT": {
"$comment": "Example accessor",
"default": "night",
"allOf": [
{
"$ref": "#/definitions/timeOfDay"
},
{ "const": "night" }
]
},
"timeOfDayDAY": {
"$comment": "Another example accessor",
"default": "day",
"allOf": [
{
"$ref": "#/definitions/timeOfDay"
},
{ "const": "day" }
]
}
}
}
78 changes: 78 additions & 0 deletions maasglobal-reference-schemas/schemas/hyper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://reference-schemas.maas.global/hyper.json",
"title": "Hyper Schema Reference",
"description": "Example endpoint",
"definitions": {
"pizzaId": { "type": "string" },
"recipe": {
"type": "object",
"properties": {
"pizza": { "$ref": "#/definitions/pizzaId" },
"ingredients": { "type": "object" },
"steps": { "type": "array" }
},
"additionalProperties": false
},
"unknownPizza": {
"type": "null",
"default": null
},
"withGarlic": {
"type": "boolean"
},
"request": {
"type": "object",
"properties": {
"garlic": { "$ref": "#/definitions/withGarlic" }
},
"required": ["garlic"],
"additionalProperties": false
},
"response": {
"anyOf": [
{ "$ref": "#/definitions/unknownPizza" },
{ "$ref": "#/definitions/recipe" }
]
}
},
"links": [
{
"rel": "implementation",

"href": "{+api}pizza/{pizzaId}/recipe",
"hrefSchema": {
"type": "object",
"properties": {
"api": {
"type": "string",
"const": "https://example.com/"
},
"pizzaId": {
"$ref": "#/definitions/pizzaId"
}
},
"required": ["api", "pizzaId"],
"additionalProperties": false
},

"headerSchema": {
"content-type": {
"type": "string",
"const": "application/json"
}
},
"submissionSchema": {
"$ref": "#/definitions/request"
},

"targetHints": {
"content-type": ["application/json"],
"allow": ["POST"]
},
"targetSchema": {
"$ref": "#/definitions/response"
}
}
]
}
19 changes: 19 additions & 0 deletions maasglobal-reference-schemas/schemas/literal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://reference-schemas.maas.global/literal.json",
"title": "Literal Reference Schemas",
"description": "Literals can define any JSON structure, and the input needs to match that structure",
"definitions": {
"stringLiteral": {
"type": "string",
"const": "foo",
"default": "foo"
},

"numberLiteral": {
"type": "number",
"const": 123,
"default": 123
}
}
}
27 changes: 27 additions & 0 deletions maasglobal-reference-schemas/schemas/nominal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://reference-schemas.maas.global/nominal.json",
"title": "Nominal Typing",
"description": "Naming basic types is useful as documentation. In addition the TypeScript we generate has nominal typing to prevent assigning unrelated basic types to each other.",
"definitions": {
"customerId": {
"type": "string"
},
"age": {
"type": "integer"
},
"distance": {
"type": "number"
},
"membership": {
"type": "boolean"
},
"metadata": {
"type": "object"
},
"unknownCustomer": {
"type": "null",
"default": null
}
}
}
33 changes: 33 additions & 0 deletions maasglobal-reference-schemas/schemas/number.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://reference-schemas.maas.global/number.json",
"title": "Number Reference Schemas",
"description": "We use several keywords to limit numbers to a specific form",
"definitions": {
"integer": {
"type": "integer"
},
"positiveNumber": {
"type": "number",
"minimum": 1,
"examples": [1, 2],
"invalid": {
"negative number": "LTE=",
"zero": "MA=="
}
},
"evenNumber": {
"type": "number",
"multipleOf": 2,
"examples": [2, 4],
"invalid": {
"odd number": "Mw=="
}
},
"portNumber": {
"type": "number",
"minimum": 0,
"maximum": 65535
}
}
}
Loading

0 comments on commit 977e78e

Please sign in to comment.