Skip to content

Commit

Permalink
Merge branch 'main' of github.com:seamapi/blueprint into thermostats
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-balitskyi committed Sep 19, 2024
2 parents 51713f9 + a743f15 commit 64f0f53
Show file tree
Hide file tree
Showing 11 changed files with 656 additions and 5 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.19.1",
"version": "0.20.0",
"description": "Build tools for the Seam API using this blueprint.",
"type": "module",
"main": "index.js",
Expand Down
55 changes: 53 additions & 2 deletions src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export interface Route {
namespace: Namespace | null
endpoints: Endpoint[]
subroutes: Route[]
isUndocumented: boolean
isDeprecated: boolean
}

export interface Resource {
Expand All @@ -40,6 +42,8 @@ export interface Resource {

export interface Namespace {
path: string
isDeprecated: boolean
isUndocumented: boolean
}

export interface Endpoint {
Expand Down Expand Up @@ -309,7 +313,12 @@ const createRoutes = async (
}
}

return Array.from(routeMap.values())
const routes = Array.from(routeMap.values())

return routes
.map(addIsDeprecatedToRoute)
.map(addIsUndocumentedToRoute)
.map(addNamespaceStatusToRoute)
}

const getNamespace = (path: string, paths: OpenapiPaths): string | null => {
Expand Down Expand Up @@ -362,9 +371,51 @@ const createRoute = async (
return {
path: routePath,
name,
namespace: namespace != null ? { path: namespace } : null,
namespace:
namespace != null
? {
path: namespace,
isDeprecated: false,
isUndocumented: false,
}
: null,
endpoints: await createEndpoints(path, pathItem, context),
subroutes: [],
isUndocumented: false,
isDeprecated: false,
}
}

const addIsDeprecatedToRoute = (route: Route): Route => ({
...route,
isDeprecated: route.endpoints.every((endpoint) => endpoint.isDeprecated),
})

const addIsUndocumentedToRoute = (route: Route): Route => ({
...route,
isUndocumented: route.endpoints.every((endpoint) => endpoint.isUndocumented),
})

const addNamespaceStatusToRoute = (
route: Route,
_idx: number,
routes: Route[],
): Route => {
if (route.namespace == null) return route

const namespaceRoutes = routes.filter(
(r) => r.namespace?.path === route.namespace?.path,
)
const isNamespaceDeprecated = namespaceRoutes.every((r) => r.isDeprecated)
const isNamespaceUndocumented = namespaceRoutes.every((r) => r.isUndocumented)

return {
...route,
namespace: {
...route.namespace,
isDeprecated: isNamespaceDeprecated,
isUndocumented: isNamespaceUndocumented,
},
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/types/code-sample-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,15 @@ export default [
},
},
},
{
title: 'Deprecated and undocumented endpoint',
description: 'This is a deprecated and undocumented endpoint',
request: {
path: '/deprecated/undocumented/endpoint',
parameters: {},
},
response: {
body: {},
},
},
]
27 changes: 27 additions & 0 deletions test/fixtures/types/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,32 @@ export default {
'x-title': 'List planes',
},
},
'/deprecated/undocumented/endpoint': {
get: {
operationId: 'deprecatedUndocumentedEndpointGet',
deprecated: true,
responses: {
200: {
content: {
'application/json': {
schema: {
properties: {
ok: { type: 'boolean' },
},
required: ['ok'],
type: 'object',
},
},
},
description: 'Deprecated and undocumented endpoint',
},
},
security: [],
summary: '/deprecated/undocumented/endpoint',
tags: ['/deprecated/undocumented'],
'x-undocumented': 'true',
'x-title': 'Deprecated and undocumented endpoint',
},
},
},
}
5 changes: 5 additions & 0 deletions test/fixtures/types/route-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ export const routes = {
planes: z.array(schemas.plane),
}),
},
'/deprecated/undocumented/endpoint': {
auth: 'none',
methods: ['GET'],
jsonResponse: z.object({}),
},
},
} as const
9 changes: 9 additions & 0 deletions test/fixtures/types/route-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export interface Routes {
}
}
}
'/deprecated/undocumented/endpoint': {
route: '/deprecated/undocumented/endpoint'
method: 'GET'
queryParams: Record<string, unknown>
jsonBody: Record<string, unknown>
commonParams: Record<string, unknown>
formData: Record<string, unknown>
jsonResponse: Record<string, never>
}
}

export type RouteResponse<Path extends keyof Routes> =
Expand Down
Loading

0 comments on commit 64f0f53

Please sign in to comment.