-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support multiple schema types #203
Conversation
7e0eb07
to
a858bfd
Compare
@@ -1,7 +1,7 @@ | |||
{ | |||
"extends": "./node_modules/gts/", | |||
"rules": { | |||
"node/no-unpublished-import": ["error", { | |||
"n/no-unpublished-import": ["error", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required by gts 5.3.1 - https://github.com/google/gts/releases/tag/v5.3.1
Bug Fixes
deps: replace dependency eslint-plugin-node with eslint-plugin-n (google/gts#865) (efbe3a8)
70d1b7b
to
323e133
Compare
@@ -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 }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the only change needed here!
This has the nice benefit of preserving the old URLs in the format -
https://theopensystemslab.github.io/digital-planning-data-schemas/<VERSION>/schema.json
and generating new URLs in the format -
https://theopensystemslab.github.io/digital-planning-data-schemas/<VERSION>/schemas/<SCHEMA>.json
@@ -1,9 +1,9 @@ | |||
import {Schema} from '../../types/Schema'; | |||
import {BaseProposal} from '../../types/schema/data/Proposal'; | |||
import {DigitalPlanningApplication} from '../../../types/schemas/digitalPlanningApplication'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look (in another PR) at path aliases in our tsconfig.json
- it could be nice to import from @types
, @utils
etc now that these import paths are more deeply nested.
dirs=("digitalPlanningApplication") | ||
types=("DigitalPlanningApplication") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we get new schemas, we'll just need to add them to this list, e.g.
dirs=("digitalPlanningApplication", "mySchemaDirectory")
types=("DigitalPlanningApplication", "MySchemaType")
* @title Digital Planning Application | ||
* @description The root specification for a planning application in England generated by a digital planning service | ||
*/ | ||
export interface DigitalPlanningApplication { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something to consider - is DigitalPlanningApplication
actually the right name? Is the DigitalPlanning
prefix redundant given the context, will all schemas end up with the prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very on board with simplifying at this stage ⚡ agree dropping prefix and keeping Application
only is less redundant and going to be easier to extend (eg PreApplication
, Assessment
, Consultation
, SiteNotice
etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! Will pick this up in a follow up PR shortly.
7fb8a41
to
f5a2389
Compare
{ | ||
name: 'DigitalPlanningApplication', | ||
schema: digitalPlanningApplicationSchema, | ||
examples: getJSONExamples<DigitalPlanningApplication>( | ||
'digitalPlanningApplication' | ||
), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New schemas will also need to be added here, and then all their examples will get picked up by tests automatically 👍
const ajv = addFormats(new Ajv({allowUnionTypes: true})); | ||
const validate = ajv.compile(schema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving the instantiation of ajv
and jsonschema
up to the describe()
block and not repeating in it each test speeds tests up from ~55s to ~3s locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huge ! Thanks for spotting that misconfiguration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great ! Reviewed as much as one can for 65+ changed files, let's get to main & fix forward anything else we spot 🙂
(async () => { | ||
await walkDirectory('./examples'); | ||
console.log('All example files converted to JSON'); | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much appreciated dev workflow improvement 👍
Thanks @jessicamcinchak! Certainly a larger and noisier PR than intended, really appreciate the speedy review 🙌 |
What does this PR do?
Schema
is nowDigitalPlanningApplication
/examples
to import all JSON files, avoid manual importsChanges to folder structure
The changes made are as follows -
/schema/schema.json
→/schemas/${SCHEMA}.json
/examples/someExample.json
→examples/${SCHEMA}/someExample.json
/types/Schema.ts
→/types/${SCHEMA}.index.ts
/types/utils.ts
→/types/shared/utils.ts
/shared
folder (maybe some enums?). The main motivation for moving utils there now (before it's actually shared) was just to be sure that these types would still be accessible tots-json-schema-generator
when they were "outside" / "above" the scope of the type being converted. Good news is that it works!Tree view