Skip to content

Commit

Permalink
feat: Support multiple schema types (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Jul 17, 2024
1 parent dcfefbc commit c7d6578
Show file tree
Hide file tree
Showing 66 changed files with 5,730 additions and 6,130 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: |
VERSION=v${{steps.version_check.outputs.version}} pnpm build
mkdir -p "$GITHUB_WORKSPACE/v${{ steps.version_check.outputs.version }}"
mv schema/* "$GITHUB_WORKSPACE/v${{ steps.version_check.outputs.version }}"
mv schemas/* "$GITHUB_WORKSPACE/v${{ steps.version_check.outputs.version }}"
mkdir -p "$GITHUB_WORKSPACE/v${{ steps.version_check.outputs.version }}/types"
mv types/* "$GITHUB_WORKSPACE/v${{ steps.version_check.outputs.version }}/types"
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$branch" != "main" ]; then
pnpm build-json-examples && pnpm build-schema:dev
pnpm build
fi

pnpm check && pnpm fix
Expand Down
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ There's two main options for integrating with Digital Planning Data schemas:

1. Reference a hosted schema file directly:

`https://theopensystemslab.github.io/digital-planning-data-schemas/<VERSION>/schema.json`
`https://theopensystemslab.github.io/digital-planning-data-schemas/<VERSION>/schemas/<SCHEMA>.json`

1. Clone this repository and reference the local schema files programmatically in your own code using tools that support JSON Schema validation

For more detailed info on integrating and validating schemas, please refer to the examples and tests in this repo.

## Repository structure

`/examples`: Examples of valid payloads for each application type supported by this specification.
`/examples`: Examples of valid payloads for each application type supported by the specifications encoded in this repository.

`/schema`: The main JSON Schema file. The `main` branch of this repo will reflect the `@next` version, while historic versions are documented and released on the `dist` branch.
`/schemas`: The main JSON Schema files. The `main` branch of this repo will reflect the `@next` version, while historic versions are documented and released on the `dist` branch.

`/types`: TypeScript interfaces used to generate the JSON Schema.
`/types`: TypeScript interfaces used to generate the JSON Schemas.

`/tests`: Test suites to ensure that the generated schema and example payloads are valid, accurate, and capable of handling different scenarios.

Expand All @@ -37,19 +37,17 @@ pnpm i
```

## Developing
The JSON Schema is defined using TypeScript interfaces and then generated using the `ts-json-schema-generator` library.
The JSON Schemas are defined using TypeScript interfaces and then generated using the `ts-json-schema-generator` library.

To make changes, update `/types` and then run `pnpm build` to automatically generate the output JSON file under `/schema`.
To make changes, update `/types` and then run `pnpm build` to automatically generate the output JSON file under `/schemas`.

Types should be annotated using JSDocs, which will then be read during schema generation.

Please see the [JSON schema docs](https://json-schema.org/understanding-json-schema/reference/) for a full list of references for various types.

## Adding examples and testing

Add a TypeScript file to `/examples/data` with at least one exported variable representing an example payload definition.

Add each exported payload to `examplesToConvert` in `/scripts/build-json-examples` and `examplesToTest` in `/tests/usage.test.ts`.
Add a TypeScript file to `/examples/<SCHEMA>/data` with at least one exported variable representing an example payload definition.

Run `pnpm build-json-examples` to automatically generate a corresponding JSON file per example payload in the root of `/examples`.

Expand All @@ -58,7 +56,7 @@ Run `pnpm test` to confirm your example payload can be successfully validated ag
## Publishing
To publish a new version, open a pull request against `main` which increments the `package.json` version.

On merge, the [publish.yml](https://github.com/theopensystemslab/digital-planning-data-schemas/blob/main/.github/workflows/publish.yml) GitHub Action will update the `dist` branch, create a release, and publish the new version via GitHub pages at `http://theopensystemslab.github.io/digital-planning-data-schemas/<VERSION>/schema.json`
On merge, the [publish.yml](https://github.com/theopensystemslab/digital-planning-data-schemas/blob/main/.github/workflows/publish.yml) GitHub Action will update the `dist` branch, create a release, and publish the new version via GitHub pages at `http://theopensystemslab.github.io/digital-planning-data-schemas/<VERSION>/schemas/<SCHEMA>.json`

## Contributing
We welcome feedback, bug reports, and contributions to help improve and grow the Digital Planning Data schemas via GitHub Issues and Pull Requests.
Expand Down
Loading

0 comments on commit c7d6578

Please sign in to comment.