From 9ebee76fc48e5d2f3e33b9ffd11166289314b08c Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 28 Jun 2024 13:10:19 +0200 Subject: [PATCH 1/8] add Resource, Response, hard code ResourceType --- src/lib/blueprint.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index 296ff4e..f53c41c 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -3,6 +3,7 @@ import type { Openapi } from './openapi.js' export interface Blueprint { name: string routes: Route[] + resources: Record } interface Route { @@ -12,6 +13,11 @@ interface Route { subroutes: Route[] } +interface Resource { + resourceType: ResourceType + properties: Property[] +} + interface Namespace { path: string } @@ -49,8 +55,19 @@ interface Request { interface Response { description: string + responseType: 'resource' | 'resource_list' | 'void' + responseKey: string | null + resourceType: ResourceType | null +} + +interface Property { + name: string + type: 'string' | 'enum' | 'record' | 'list' | 'object' + properties: Property[] | null } +type ResourceType = 'access_code' | 'user' | 'order' | string + type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' export interface TypesModule { @@ -61,5 +78,6 @@ export const createBlueprint = ({ openapi }: TypesModule): Blueprint => { return { name: openapi.info.title, routes: [], + resources: {} } } From 9fa460496dc0eaac14c5c6146bbbbc81d4bec17c Mon Sep 17 00:00:00 2001 From: Seam Bot Date: Fri, 28 Jun 2024 11:27:38 +0000 Subject: [PATCH 2/8] ci: Format code --- src/lib/blueprint.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index f53c41c..8106b40 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -78,6 +78,6 @@ export const createBlueprint = ({ openapi }: TypesModule): Blueprint => { return { name: openapi.info.title, routes: [], - resources: {} + resources: {}, } } From 4d6be943fdd78ed042a74b846eec92da6d466ebb Mon Sep 17 00:00:00 2001 From: Pawel Date: Mon, 1 Jul 2024 02:01:45 +0200 Subject: [PATCH 3/8] add generic types, ResourceType and SafeAccess --- src/lib/blueprint.ts | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index 8106b40..4bd7b0a 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -1,28 +1,36 @@ import type { Openapi } from './openapi.js' -export interface Blueprint { +export interface Blueprint { name: string - routes: Route[] - resources: Record + routes: Array> + resources: Partial, Resource>> } -interface Route { +interface Route { path: string namespace: Namespace | null - endpoints: Endpoint[] - subroutes: Route[] + endpoints: Array> + subroutes: Array> } -interface Resource { - resourceType: ResourceType +interface Resource { + resourceType: ResourceType properties: Property[] } +// Helper type to safely access nested properties of openapi schema - defualt to unknown if not found +type SafeAccess = K extends keyof T ? T[K] : unknown + +type ResourceType = keyof SafeAccess< + SafeAccess, + 'schemas' +> + interface Namespace { path: string } -interface Endpoint { +interface Endpoint { name: string path: string methods: Method[] @@ -34,7 +42,7 @@ interface Endpoint { deprecationMessage: string parameters: Parameter[] request: Request - response: Response + response: Response } interface Parameter { @@ -53,11 +61,11 @@ interface Request { parameters: Parameter[] } -interface Response { +interface Response { description: string responseType: 'resource' | 'resource_list' | 'void' responseKey: string | null - resourceType: ResourceType | null + resourceType: ResourceType } interface Property { @@ -66,15 +74,15 @@ interface Property { properties: Property[] | null } -type ResourceType = 'access_code' | 'user' | 'order' | string - type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' export interface TypesModule { openapi: Openapi } -export const createBlueprint = ({ openapi }: TypesModule): Blueprint => { +export const createBlueprint = ({ + openapi, +}: T): Blueprint => { return { name: openapi.info.title, routes: [], From 6958742f043ad1b11663f67d0d3d207b87f044b1 Mon Sep 17 00:00:00 2001 From: Pawel Date: Mon, 1 Jul 2024 02:05:52 +0200 Subject: [PATCH 4/8] update snapshots --- test/snapshots/blueprint.test.ts.md | 1 + test/snapshots/blueprint.test.ts.snap | Bin 220 -> 245 bytes test/snapshots/seam-blueprint.test.ts.md | 1 + test/snapshots/seam-blueprint.test.ts.snap | Bin 232 -> 258 bytes 4 files changed, 2 insertions(+) diff --git a/test/snapshots/blueprint.test.ts.md b/test/snapshots/blueprint.test.ts.md index 8f3311f..53fe393 100644 --- a/test/snapshots/blueprint.test.ts.md +++ b/test/snapshots/blueprint.test.ts.md @@ -10,5 +10,6 @@ Generated by [AVA](https://avajs.dev). { name: 'Foo', + resources: {}, routes: [], } diff --git a/test/snapshots/blueprint.test.ts.snap b/test/snapshots/blueprint.test.ts.snap index f00d94f1094e08a70aa67d3abfe7454d596c9931..75db6a75caafbd99f4d6c3dfcd602bce7c82edb2 100644 GIT binary patch literal 245 zcmVRzV@wj_rBs~9*0z_>};BrZDA#=OtY}OmNi$pC~aX%QJJH%rfKtBSh0J#7@<1~ z$y)$e0@wq%0!S#BQLs%e2+W-0nMr6*63;_TD!f0~W literal 220 zcmV<203-iFRzVfq|iTHrULm6Em$j_kgKJgG6J z-t^r!T<(3TwQ25dn#Ffsi)pMVFGoGfV7uOTu2+M*8tbszrBoxcdP`SiG3e0002;Xk)_w diff --git a/test/snapshots/seam-blueprint.test.ts.md b/test/snapshots/seam-blueprint.test.ts.md index 9d20981..a6c7320 100644 --- a/test/snapshots/seam-blueprint.test.ts.md +++ b/test/snapshots/seam-blueprint.test.ts.md @@ -10,5 +10,6 @@ Generated by [AVA](https://avajs.dev). { name: 'Seam Connect', + resources: {}, routes: [], } diff --git a/test/snapshots/seam-blueprint.test.ts.snap b/test/snapshots/seam-blueprint.test.ts.snap index ca94c4645bb9b3a0832800778499622783d39d27..e9b7da93d4e7379df530ec45af40949da663064b 100644 GIT binary patch literal 258 zcmV+d0sa0#RzVpc(!CkhF(=Mmp5JIJ?iKe?rO&fSc>T zF3G$hOCO5}00000000A3k1=k-KoCX$*v27Jz_!c*I0Y3=$N^HMp8@95e&PpbRBNi=HM0B~~>&gr_%F&GN-r z%UVElqE7&Wee@h$>otcTb^WJO?^@~m>3BaH@BiA#v-j#u@jzLYu~8M9x*DFo0U|Tr IWEBAb07}YrWdHyG literal 232 zcmVCH1A}JQ|1IbVCjH?XKd+NO_5L$!< zu+m>j&F|=RouK=5s9k8z>G4);&1q<&is{DP^cq`lZSrzW$6)F4-tWca_nBjWPdH@0 z1h4`i0A?(vEPm>fHb(wqRaM{^%)k;eW^?9Xf6AVhi*{wSQ@Jd*!Fz2CoRD__oh@Rx inI>@f9qF%QlsmJI%Cb}^wYs+Me*Xbl(&ekz00020-)gb| From 6c6481399dc04d3888d0c4e60fb8fd57d8dd5b2b Mon Sep 17 00:00:00 2001 From: Pawel Date: Tue, 2 Jul 2024 00:52:13 +0200 Subject: [PATCH 5/8] remove generic types --- src/lib/blueprint.ts | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index 4bd7b0a..319bc37 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -1,36 +1,28 @@ import type { Openapi } from './openapi.js' -export interface Blueprint { +export interface Blueprint { name: string - routes: Array> - resources: Partial, Resource>> + routes: Route[] + resources: Record } -interface Route { +interface Route { path: string namespace: Namespace | null - endpoints: Array> - subroutes: Array> + endpoints: Endpoint[] + subroutes: Route[] } -interface Resource { - resourceType: ResourceType +interface Resource { + resourceType: string properties: Property[] } -// Helper type to safely access nested properties of openapi schema - defualt to unknown if not found -type SafeAccess = K extends keyof T ? T[K] : unknown - -type ResourceType = keyof SafeAccess< - SafeAccess, - 'schemas' -> - interface Namespace { path: string } -interface Endpoint { +interface Endpoint { name: string path: string methods: Method[] @@ -42,7 +34,7 @@ interface Endpoint { deprecationMessage: string parameters: Parameter[] request: Request - response: Response + response: Response } interface Parameter { @@ -61,11 +53,11 @@ interface Request { parameters: Parameter[] } -interface Response { +interface Response { description: string responseType: 'resource' | 'resource_list' | 'void' responseKey: string | null - resourceType: ResourceType + resourceType: string | null } interface Property { @@ -80,9 +72,7 @@ export interface TypesModule { openapi: Openapi } -export const createBlueprint = ({ - openapi, -}: T): Blueprint => { +export const createBlueprint = ({ openapi }: TypesModule): Blueprint => { return { name: openapi.info.title, routes: [], From 3d5a42ef65df04a5e9d4da124681d6d0801820e7 Mon Sep 17 00:00:00 2001 From: Pawel Date: Tue, 2 Jul 2024 21:22:55 +0200 Subject: [PATCH 6/8] Improve Response and Property types --- src/lib/blueprint.ts | 58 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index 319bc37..592d9fe 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -53,17 +53,61 @@ interface Request { parameters: Parameter[] } -interface Response { +type Response = VoidResponse | ResourceResponse | ResourceListResponse + +interface BaseResponse { description: string - responseType: 'resource' | 'resource_list' | 'void' - responseKey: string | null - resourceType: string | null } -interface Property { +interface VoidResponse extends BaseResponse { + responseType: 'void' +} + +interface ResourceResponse extends BaseResponse { + responseType: 'resource' + responseKey: string + resourceType: string +} + +interface ResourceListResponse extends BaseResponse { + responseType: 'resource_list' + responseKey: string + resourceType: string +} + +type Property = + | StringProperty + | EnumProperty + | RecordProperty + | ListProperty + | ObjectProperty + +interface BaseProperty { name: string - type: 'string' | 'enum' | 'record' | 'list' | 'object' - properties: Property[] | null +} + +interface StringProperty extends BaseProperty { + type: 'string' +} + +interface EnumProperty extends BaseProperty { + type: 'enum' + values: string[] +} + +interface RecordProperty extends BaseProperty { + type: 'record' + properties: Property[] +} + +interface ListProperty extends BaseProperty { + type: 'list' + items: Property +} + +interface ObjectProperty extends BaseProperty { + type: 'object' + properties: Property[] } type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' From e2c273635c536c05dfbd532f3f11f2e9f07304a9 Mon Sep 17 00:00:00 2001 From: Pawel Date: Tue, 2 Jul 2024 21:30:05 +0200 Subject: [PATCH 7/8] implement EnumProperty and EnumValue types --- src/lib/blueprint.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index 592d9fe..e01b8b5 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -75,6 +75,15 @@ interface ResourceListResponse extends BaseResponse { resourceType: string } +interface BaseProperty { + name: string + type: 'string' | 'enum' | 'record' | 'list' | 'object' + description?: string + isRequired?: boolean + isDeprecated?: boolean + deprecationMessage?: string +} + type Property = | StringProperty | EnumProperty @@ -82,17 +91,19 @@ type Property = | ListProperty | ObjectProperty -interface BaseProperty { - name: string -} - interface StringProperty extends BaseProperty { type: 'string' } interface EnumProperty extends BaseProperty { type: 'enum' - values: string[] + values: EnumValue[] +} + +interface EnumValue { + name: string + description: string + // Additional metadata fields for enum values } interface RecordProperty extends BaseProperty { From cb9fe062216ac1129b83df62fc32310207c4a01c Mon Sep 17 00:00:00 2001 From: Pawel <41388251+kainpets@users.noreply.github.com> Date: Tue, 2 Jul 2024 21:52:59 +0200 Subject: [PATCH 8/8] Apply suggestions from code review Co-authored-by: Evan Sosenko --- src/lib/blueprint.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index e01b8b5..d79cd83 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -77,11 +77,9 @@ interface ResourceListResponse extends BaseResponse { interface BaseProperty { name: string - type: 'string' | 'enum' | 'record' | 'list' | 'object' description?: string - isRequired?: boolean - isDeprecated?: boolean - deprecationMessage?: string + isDeprecated: boolean + deprecationMessage: string } type Property = @@ -102,18 +100,14 @@ interface EnumProperty extends BaseProperty { interface EnumValue { name: string - description: string - // Additional metadata fields for enum values } interface RecordProperty extends BaseProperty { type: 'record' - properties: Property[] } interface ListProperty extends BaseProperty { type: 'list' - items: Property } interface ObjectProperty extends BaseProperty {