seamapi / blueprint

Build tools for the Seam API using this blueprint.
https://blueprint.seam.vc
MIT License
0 stars 0 forks source link

Define Resource and Response interfaces #10

Open kainpets opened 2 days ago

kainpets commented 2 days ago

Seam API always returns complete resources, so something like this should work

interface Response {
  responseType: 'resource' | 'resource_list' | 'void'
  responseKey: string | null // access_codes
  resourceType: ResourceType | null // access_code
}

interface Blueprint {
  resources: Record<ResourceType, Resource>
  ...
}

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

interface Property {
  name: string
  type: 'string' | 'enum' | 'record' | 'list' | 'object' // unsure about this one
  properties: Property[] | null // only defined if type is 'object'
}

Ideally ResourceType can be self consistent, so blueprint.resources[response.resourceType] is always NonNull<Resource>. Can we do this with a generic or inferred type form the openapi spec?