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

Support undocumented/deprecated namespace and routes #86

Merged
merged 17 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -307,7 +311,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 @@ -360,9 +369,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