Files
2025-03-18 17:37:51 +02:00

38 lines
986 B
TypeScript

import { NextResponse } from "next/server"
import path from "path"
import OpenAPIParser from "@readme/openapi-parser"
import getPathsOfTag from "@/utils/get-paths-of-tag"
import type { OpenAPI } from "types"
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const area = searchParams.get("area")
const expand = searchParams.get("expand")
if (area !== "admin" && area !== "store") {
return NextResponse.json(
{
success: false,
message: `area ${area} is not allowed`,
},
{
status: 400,
}
)
}
const baseSpecs = (await OpenAPIParser.parse(
path.join(process.cwd(), "specs", area, "openapi.yaml")
)) as OpenAPI.ExpandedDocument
if (expand) {
const paths = await getPathsOfTag(expand, area)
if (paths) {
baseSpecs.expandedTags = {}
baseSpecs.expandedTags[expand] = paths.paths
}
}
return NextResponse.json(baseSpecs, {
status: 200,
})
}