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
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
import AreaProvider from "@/providers/area"
|
||||
import AdminContentV1 from "../../_mdx/v1/admin.mdx"
|
||||
import StoreContentV1 from "../../_mdx/v1/store.mdx"
|
||||
import ClientLibrariesV1 from "../../_mdx/v1/client-libraries.mdx"
|
||||
import AdminContentV2 from "../../_mdx/admin.mdx"
|
||||
import StoreContentV2 from "../../_mdx/store.mdx"
|
||||
import ClientLibrariesV2 from "../../_mdx/client-libraries.mdx"
|
||||
import Section from "@/components/Section"
|
||||
import Tags from "@/components/Tags"
|
||||
import type { Area } from "@/types/openapi"
|
||||
import DividedLayout from "@/layouts/Divided"
|
||||
import { capitalize } from "docs-ui"
|
||||
import PageTitleProvider from "../../../providers/page-title"
|
||||
import PageHeading from "../../../components/PageHeading"
|
||||
import PageTitleProvider from "@/providers/page-title"
|
||||
|
||||
type ReferencePageProps = {
|
||||
params: {
|
||||
@@ -20,16 +19,20 @@ const ReferencePage = async ({ params: { area } }: ReferencePageProps) => {
|
||||
return (
|
||||
<AreaProvider area={area}>
|
||||
<PageTitleProvider>
|
||||
<PageHeading className="!text-h2 block lg:hidden" />
|
||||
<h1 className="!text-h2 block lg:hidden">
|
||||
Medusa V2 {capitalize(area)} API Reference
|
||||
</h1>
|
||||
<DividedLayout
|
||||
mainContent={
|
||||
<Section>
|
||||
<PageHeading className="!text-h2 hidden lg:block" />
|
||||
{area.includes("admin") && <AdminContentV1 />}
|
||||
{area.includes("store") && <StoreContentV1 />}
|
||||
<h1 className="!text-h2 hidden lg:block">
|
||||
Medusa V2 {capitalize(area)} API Reference
|
||||
</h1>
|
||||
{area.includes("admin") && <AdminContentV2 />}
|
||||
{area.includes("store") && <StoreContentV2 />}
|
||||
</Section>
|
||||
}
|
||||
codeContent={<ClientLibrariesV1 />}
|
||||
codeContent={<ClientLibrariesV2 />}
|
||||
className="flex-col-reverse"
|
||||
/>
|
||||
<Tags />
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 253 KiB |
@@ -1,62 +0,0 @@
|
||||
import AreaProvider from "@/providers/area"
|
||||
import AdminContentV2 from "../../../_mdx/v2/admin.mdx"
|
||||
import StoreContentV2 from "../../../_mdx/v2/store.mdx"
|
||||
import ClientLibrariesV2 from "../../../_mdx/v2/client-libraries.mdx"
|
||||
import Section from "@/components/Section"
|
||||
import Tags from "@/components/Tags"
|
||||
import type { Area } from "@/types/openapi"
|
||||
import DividedLayout from "@/layouts/Divided"
|
||||
import { capitalize } from "docs-ui"
|
||||
import PageTitleProvider from "@/providers/page-title"
|
||||
import PageHeading from "@/components/PageHeading"
|
||||
|
||||
type ReferencePageProps = {
|
||||
params: {
|
||||
area: Area
|
||||
}
|
||||
}
|
||||
|
||||
const ReferencePage = async ({ params: { area } }: ReferencePageProps) => {
|
||||
return (
|
||||
<AreaProvider area={area}>
|
||||
<PageTitleProvider>
|
||||
<PageHeading className="!text-h2 block lg:hidden" />
|
||||
<DividedLayout
|
||||
mainContent={
|
||||
<Section>
|
||||
<PageHeading className="!text-h2 hidden lg:block" />
|
||||
{area.includes("admin") && <AdminContentV2 />}
|
||||
{area.includes("store") && <StoreContentV2 />}
|
||||
</Section>
|
||||
}
|
||||
codeContent={<ClientLibrariesV2 />}
|
||||
className="flex-col-reverse"
|
||||
/>
|
||||
<Tags />
|
||||
</PageTitleProvider>
|
||||
</AreaProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export default ReferencePage
|
||||
|
||||
export function generateMetadata({ params: { area } }: ReferencePageProps) {
|
||||
return {
|
||||
title: `Medusa ${capitalize(area)} API Reference`,
|
||||
description: `REST API reference for the Medusa ${area} API. This reference includes code snippets and examples for Medusa JS Client and cURL.`,
|
||||
metadataBase: process.env.NEXT_PUBLIC_BASE_URL,
|
||||
}
|
||||
}
|
||||
|
||||
export const dynamicParams = false
|
||||
|
||||
export async function generateStaticParams() {
|
||||
return [
|
||||
{
|
||||
area: "admin",
|
||||
},
|
||||
{
|
||||
area: "store",
|
||||
},
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 253 KiB |
@@ -24,7 +24,7 @@ export async function GET() {
|
||||
const defaultIndexData = {
|
||||
version: ["current"],
|
||||
lang: "en",
|
||||
_tags: ["api", area],
|
||||
_tags: ["api", `${area}-v2`],
|
||||
}
|
||||
// find and parse static headers from pages
|
||||
const dom = await JSDOM.fromURL(getUrl(area))
|
||||
|
||||
@@ -2,12 +2,11 @@ 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, Version } from "@/types/openapi"
|
||||
import type { ExpandedDocument } from "@/types/openapi"
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const area = searchParams.get("area")
|
||||
const version = (searchParams.get("version") as Version) || "1"
|
||||
const expand = searchParams.get("expand")
|
||||
if (area !== "admin" && area !== "store") {
|
||||
return NextResponse.json(
|
||||
@@ -21,11 +20,7 @@ export async function GET(request: Request) {
|
||||
)
|
||||
}
|
||||
const baseSpecs = (await OpenAPIParser.parse(
|
||||
path.join(
|
||||
process.cwd(),
|
||||
version === "1" ? "specs" : "specs-v2",
|
||||
`${area}/openapi.yaml`
|
||||
)
|
||||
path.join(process.cwd(), "specs", area, "openapi.yaml")
|
||||
)) as ExpandedDocument
|
||||
|
||||
if (expand) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { existsSync, readFileSync } from "fs"
|
||||
import { NextResponse } from "next/server"
|
||||
import path from "path"
|
||||
import { Version } from "../../../../types/openapi"
|
||||
|
||||
type DownloadParams = {
|
||||
params: {
|
||||
@@ -10,16 +9,8 @@ type DownloadParams = {
|
||||
}
|
||||
|
||||
export function GET(request: Request, { params }: DownloadParams) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const { area } = params
|
||||
const version =
|
||||
process.env.NEXT_PUBLIC_VERSIONING === "true"
|
||||
? (searchParams.get("version") as Version) || "1"
|
||||
: "1"
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
`${version === "1" ? "specs" : "specs-v2"}/${area}/openapi.full.yaml`
|
||||
)
|
||||
const filePath = path.join(process.cwd(), "specs", area, "openapi.full.yaml")
|
||||
|
||||
if (!existsSync(filePath)) {
|
||||
return new NextResponse(null, {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { SchemaObject, Version } from "../../../types/openapi"
|
||||
import { SchemaObject } from "../../../types/openapi"
|
||||
import path from "path"
|
||||
import { existsSync, promises as fs } from "fs"
|
||||
import { parseDocument } from "yaml"
|
||||
@@ -8,7 +8,6 @@ export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
let name = searchParams.get("name")
|
||||
const area = searchParams.get("area")
|
||||
const version = (searchParams.get("version") as Version) || "1"
|
||||
|
||||
if (!name) {
|
||||
return NextResponse.json(
|
||||
@@ -40,7 +39,7 @@ export async function GET(request: Request) {
|
||||
|
||||
const schemaPath = path.join(
|
||||
process.cwd(),
|
||||
version === "1" ? "specs" : "specs-v2",
|
||||
"specs",
|
||||
area,
|
||||
"components",
|
||||
"schemas",
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import path from "path"
|
||||
import getPathsOfTag from "@/utils/get-paths-of-tag"
|
||||
import { Version } from "../../../types/openapi"
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const tagName = searchParams.get("tagName") || ""
|
||||
const area = searchParams.get("area")
|
||||
const version = (searchParams.get("version") as Version) || "1"
|
||||
|
||||
if (area !== "admin" && area !== "store") {
|
||||
return NextResponse.json(
|
||||
@@ -23,10 +21,9 @@ export async function GET(request: Request) {
|
||||
|
||||
// this is just to ensure that vercel picks up these files on build
|
||||
path.join(process.cwd(), "specs")
|
||||
path.join(process.cwd(), "specs-v2")
|
||||
|
||||
// get path files
|
||||
const paths = await getPathsOfTag(tagName, area, version)
|
||||
const paths = await getPathsOfTag(tagName, area)
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user