Files
medusa-store/www/apps/api-reference/app/api/base-specs/route.ts
Shahed Nasser 22f30f54fd docs: update api-reference project for v2 (#7307)
* remove everything v1 and make v2 default

* move main v2 rewrites to book

* move rewrites to book + other fixes
2024-05-16 09:02:35 +02:00

38 lines
997 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 { ExpandedDocument } from "@/types/openapi"
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 ExpandedDocument
if (expand) {
const paths = await getPathsOfTag(expand, area)
if (paths) {
baseSpecs.expandedTags = {}
baseSpecs.expandedTags[expand] = paths.paths
}
}
return NextResponse.json(baseSpecs, {
status: 200,
})
}