From 689bd64b6f88d5c8f9ec7997f18b633f40ca3f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 25 Jul 2024 11:27:38 +0100 Subject: [PATCH] feat: Remove repetiton by using `Extract<>` --- schemas/app.json | 129 +++++++++---------------------------- types/schemas/app/index.ts | 8 +-- 2 files changed, 34 insertions(+), 103 deletions(-) diff --git a/schemas/app.json b/schemas/app.json index e436a7ef..adbb73cd 100644 --- a/schemas/app.json +++ b/schemas/app.json @@ -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", @@ -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", diff --git a/types/schemas/app/index.ts b/types/schemas/app/index.ts index 8cd96be2..e520863a 100644 --- a/types/schemas/app/index.ts +++ b/types/schemas/app/index.ts @@ -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 +>; /** * @title App