Skip to content
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: Define Resource and Response #11

Merged
merged 8 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Openapi } from './openapi.js'
export interface Blueprint {
name: string
routes: Route[]
resources: Record<string, Resource>
}

interface Route {
Expand All @@ -12,6 +13,11 @@ interface Route {
subroutes: Route[]
}

interface Resource {
resourceType: string
properties: Property[]
}

interface Namespace {
path: string
}
Expand Down Expand Up @@ -47,10 +53,74 @@ interface Request {
parameters: Parameter[]
}

interface Response {
type Response = VoidResponse | ResourceResponse | ResourceListResponse

interface BaseResponse {
description: string
}

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
}

interface BaseProperty {
name: string
type: 'string' | 'enum' | 'record' | 'list' | 'object'
kainpets marked this conversation as resolved.
Show resolved Hide resolved
description?: string
isRequired?: boolean
kainpets marked this conversation as resolved.
Show resolved Hide resolved
isDeprecated?: boolean
deprecationMessage?: string
kainpets marked this conversation as resolved.
Show resolved Hide resolved
}

type Property =
| StringProperty
| EnumProperty
| RecordProperty
| ListProperty
| ObjectProperty

interface StringProperty extends BaseProperty {
type: 'string'
}

interface EnumProperty extends BaseProperty {
type: 'enum'
values: EnumValue[]
}

interface EnumValue {
name: string
description: string
kainpets marked this conversation as resolved.
Show resolved Hide resolved
// Additional metadata fields for enum values
kainpets marked this conversation as resolved.
Show resolved Hide resolved
}

interface RecordProperty extends BaseProperty {
type: 'record'
properties: Property[]
kainpets marked this conversation as resolved.
Show resolved Hide resolved
}

interface ListProperty extends BaseProperty {
type: 'list'
items: Property
kainpets marked this conversation as resolved.
Show resolved Hide resolved
}

interface ObjectProperty extends BaseProperty {
type: 'object'
properties: Property[]
}

type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'

export interface TypesModule {
Expand All @@ -61,5 +131,6 @@ export const createBlueprint = ({ openapi }: TypesModule): Blueprint => {
return {
name: openapi.info.title,
routes: [],
resources: {},
}
}
1 change: 1 addition & 0 deletions test/snapshots/blueprint.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ Generated by [AVA](https://avajs.dev).

{
name: 'Foo',
resources: {},
routes: [],
}
Binary file modified test/snapshots/blueprint.test.ts.snap
Binary file not shown.
1 change: 1 addition & 0 deletions test/snapshots/seam-blueprint.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ Generated by [AVA](https://avajs.dev).

{
name: 'Seam Connect',
resources: {},
routes: [],
}
Binary file modified test/snapshots/seam-blueprint.test.ts.snap
Binary file not shown.