Skip to content

Commit

Permalink
feat: Remove repetiton by using Extract<>
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jul 25, 2024
1 parent 83d407d commit 2300112
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 103 deletions.
129 changes: 30 additions & 99 deletions schemas/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,96 +26,6 @@
],
"type": "object"
},
"BaseWTT": {
"additionalProperties": false,
"properties": {
"applicationType": {
"const": "wtt",
"type": "string"
},
"data": {
"additionalProperties": false,
"properties": {
"application": {
"$ref": "#/definitions/WTTApplicationData"
},
"user": {
"$ref": "#/definitions/WTTUser"
}
},
"required": [
"user",
"application"
],
"type": "object"
}
},
"required": [
"applicationType",
"data"
],
"type": "object"
},
"ConsentWTT": {
"additionalProperties": false,
"properties": {
"applicationType": {
"const": "wtt.consent",
"type": "string"
},
"data": {
"additionalProperties": false,
"properties": {
"application": {
"$ref": "#/definitions/WTTApplicationData"
},
"user": {
"$ref": "#/definitions/WTTUser"
}
},
"required": [
"user",
"application"
],
"type": "object"
}
},
"required": [
"applicationType",
"data"
],
"type": "object"
},
"NoticeWTT": {
"additionalProperties": false,
"properties": {
"applicationType": {
"const": "wtt.notice",
"type": "string"
},
"data": {
"additionalProperties": false,
"properties": {
"application": {
"$ref": "#/definitions/WTTApplicationData"
},
"user": {
"$ref": "#/definitions/WTTUser"
}
},
"required": [
"user",
"application"
],
"type": "object"
}
},
"required": [
"applicationType",
"data"
],
"type": "object"
},
"PPApplicationData": {
"additionalProperties": false,
"description": "Specific ApplicationData required for \"Planning Permission\" applications",
Expand Down Expand Up @@ -270,17 +180,38 @@
"type": "object"
},
"WorksToTreesApplications": {
"anyOf": [
{
"$ref": "#/definitions/BaseWTT"
},
{
"$ref": "#/definitions/ConsentWTT"
"additionalProperties": false,
"properties": {
"applicationType": {
"enum": [
"wtt",
"wtt.consent",
"wtt.notice"
],
"type": "string"
},
{
"$ref": "#/definitions/NoticeWTT"
"data": {
"additionalProperties": false,
"properties": {
"application": {
"$ref": "#/definitions/WTTApplicationData"
},
"user": {
"$ref": "#/definitions/WTTUser"
}
},
"required": [
"user",
"application"
],
"type": "object"
}
]
},
"required": [
"applicationType",
"data"
],
"type": "object"
}
},
"description": "(Temporary name to not clash with the existing `Application` type)\nThe root specification for a planning application in England generated by a digital planning service",
Expand Down
8 changes: 4 additions & 4 deletions types/schemas/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export type PlanningPermissionApplication = ApplicationSpecification<
export type PriorApprovalApplication = ApplicationSpecification<'pa', 'pa'>;
// TODO: All granular types

export type WorksToTreesApplications = BaseWTT | ConsentWTT | NoticeWTT;
export type BaseWTT = ApplicationSpecification<'wtt', 'wtt'>;
export type ConsentWTT = ApplicationSpecification<'wtt', 'wtt.consent'>;
export type NoticeWTT = ApplicationSpecification<'wtt', 'wtt.notice'>;
export type WorksToTreesApplications = ApplicationSpecification<
'wtt',
Extract<ApplicationTypeKeys, 'wtt' | 'wtt.consent' | 'wtt.notice'>
>;

/**
* @title App
Expand Down

0 comments on commit 2300112

Please sign in to comment.