UNPKG

starlight-openapi

Version:

Starlight plugin to generate documentation from OpenAPI/Swagger specifications.

19 lines (14 loc) 577 B
import { defineRouteMiddleware } from '@astrojs/starlight/route-data' import schemas from 'virtual:starlight-openapi-schemas' import { stripLeadingAndTrailingSlashes } from './libs/path' import { getSidebarFromSchemas } from './libs/starlight' const allSchemas = Object.values(schemas) export const onRequest = defineRouteMiddleware((context) => { const { starlightRoute } = context.locals const { sidebar } = starlightRoute starlightRoute.sidebar = getSidebarFromSchemas( stripLeadingAndTrailingSlashes(context.url.pathname), sidebar, allSchemas, ) })