Skip to content

Commit

Permalink
Merge branch 'main' into generate-all-acs
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Sep 9, 2024
2 parents 7d06019 + d3ba884 commit 849c5bf
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seamapi/blueprint",
"version": "0.15.2",
"version": "0.16.1",
"description": "Build tools for the Seam API using this blueprint.",
"type": "module",
"main": "index.js",
Expand Down
15 changes: 14 additions & 1 deletion src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Blueprint {

export interface Route {
path: string
name: string
namespace: Namespace | null
endpoints: Endpoint[]
subroutes: Route[]
Expand All @@ -44,6 +45,7 @@ export interface Namespace {
export interface Endpoint {
title: string
path: string
name: string
description: string
isUndocumented: boolean
isDeprecated: boolean
Expand Down Expand Up @@ -304,9 +306,14 @@ const createRoute = async (
): Promise<Route> => {
const pathParts = path.split('/')
const routePath = `/${pathParts.slice(1, -1).join('/')}`
const name = pathParts.at(-2)
if (name == null) {
throw new Error(`Could not resolve name for route at ${path}`)
}

return {
path: routePath,
name,
namespace: { path: `/${pathParts[1]}` },
endpoints: await createEndpoints(path, pathItem, context),
subroutes: [],
Expand Down Expand Up @@ -349,6 +356,11 @@ const createEndpoint = async (
const pathParts = path.split('/')
const endpointPath = `/${pathParts.slice(1).join('/')}`

const name = pathParts.at(-1)
if (name == null) {
throw new Error(`Could not resolve name for endpoint at ${path}`)
}

const parsedOperation = OpenapiOperationSchema.parse(operation)

const title = parsedOperation['x-title']
Expand All @@ -363,8 +375,9 @@ const createEndpoint = async (

const request = createRequest(methods, operation)

const endpoint = {
const endpoint: Omit<Endpoint, 'codeSamples'> = {
title,
name,
path: endpointPath,
description,
isUndocumented,
Expand Down
10 changes: 10 additions & 0 deletions test/snapshots/blueprint.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Generated by [AVA](https://avajs.dev).
description: '',
isDeprecated: false,
isUndocumented: false,
name: 'get',
path: '/foos/get',
request: {
methods: [
Expand Down Expand Up @@ -210,6 +211,7 @@ Generated by [AVA](https://avajs.dev).
description: '',
isDeprecated: false,
isUndocumented: false,
name: 'get',
path: '/foos/get',
request: {
methods: [
Expand Down Expand Up @@ -291,6 +293,7 @@ Generated by [AVA](https://avajs.dev).
description: '',
isDeprecated: false,
isUndocumented: false,
name: 'list',
path: '/foos/list',
request: {
methods: [
Expand Down Expand Up @@ -372,6 +375,7 @@ Generated by [AVA](https://avajs.dev).
description: '',
isDeprecated: false,
isUndocumented: false,
name: 'list',
path: '/foos/list',
request: {
methods: [
Expand All @@ -390,6 +394,7 @@ Generated by [AVA](https://avajs.dev).
title: 'List foos',
},
],
name: 'foos',
namespace: {
path: '/foos',
},
Expand Down Expand Up @@ -535,6 +540,7 @@ Generated by [AVA](https://avajs.dev).
description: '',
isDeprecated: false,
isUndocumented: false,
name: 'get',
path: '/foos/get',
request: {
methods: [
Expand Down Expand Up @@ -626,6 +632,7 @@ Generated by [AVA](https://avajs.dev).
description: '',
isDeprecated: false,
isUndocumented: false,
name: 'get',
path: '/foos/get',
request: {
methods: [
Expand Down Expand Up @@ -717,6 +724,7 @@ Generated by [AVA](https://avajs.dev).
description: '',
isDeprecated: false,
isUndocumented: false,
name: 'list',
path: '/foos/list',
request: {
methods: [
Expand Down Expand Up @@ -808,6 +816,7 @@ Generated by [AVA](https://avajs.dev).
description: '',
isDeprecated: false,
isUndocumented: false,
name: 'list',
path: '/foos/list',
request: {
methods: [
Expand All @@ -826,6 +835,7 @@ Generated by [AVA](https://avajs.dev).
title: 'List foos',
},
],
name: 'foos',
namespace: {
path: '/foos',
},
Expand Down
Binary file modified test/snapshots/blueprint.test.ts.snap
Binary file not shown.
Loading

0 comments on commit 849c5bf

Please sign in to comment.