docs: add prepare script to generate sidebar (#11894)
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import OpenAPIParser from "@readme/openapi-parser"
|
||||
import algoliasearch from "algoliasearch"
|
||||
import type { ExpandedDocument, Operation } from "../../types/openapi"
|
||||
import type { OpenAPI } from "types"
|
||||
import path from "path"
|
||||
import getSectionId from "../../utils/get-section-id"
|
||||
import { NextResponse } from "next/server"
|
||||
import { JSDOM } from "jsdom"
|
||||
import getUrl from "../../utils/get-url"
|
||||
import { capitalize } from "docs-ui"
|
||||
import { getSectionId } from "docs-utils"
|
||||
|
||||
export async function GET() {
|
||||
const algoliaClient = algoliasearch(
|
||||
@@ -50,7 +50,7 @@ export async function GET() {
|
||||
// find and index tag and operations
|
||||
const baseSpecs = (await OpenAPIParser.parse(
|
||||
path.join(process.cwd(), `specs/${area}/openapi.full.yaml`)
|
||||
)) as ExpandedDocument
|
||||
)) as OpenAPI.ExpandedDocument
|
||||
|
||||
baseSpecs.tags?.map((tag) => {
|
||||
const tagName = getSectionId([tag.name])
|
||||
@@ -71,7 +71,7 @@ export async function GET() {
|
||||
|
||||
Object.values(paths).forEach((path) => {
|
||||
Object.values(path).forEach((op) => {
|
||||
const operation = op as Operation
|
||||
const operation = op as OpenAPI.Operation
|
||||
const tag = operation.tags?.[0]
|
||||
const operationName = getSectionId([tag || "", operation.operationId])
|
||||
const url = getUrl(area, operationName)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { MetadataRoute } from "next"
|
||||
import OpenAPIParser from "@readme/openapi-parser"
|
||||
import path from "path"
|
||||
import type { ExpandedDocument, Operation } from "../../types/openapi"
|
||||
import type { OpenAPI } from "types"
|
||||
import getUrl from "../../utils/get-url"
|
||||
import getSectionId from "../../utils/get-section-id"
|
||||
import getPathsOfTag from "../../utils/get-paths-of-tag"
|
||||
import { config } from "../../config"
|
||||
import { getSectionId } from "docs-utils"
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const baseUrl = config.baseUrl
|
||||
@@ -24,7 +24,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
for (const area of ["store", "admin"]) {
|
||||
const baseSpecs = (await OpenAPIParser.parse(
|
||||
path.join(process.cwd(), `specs/${area}/openapi.yaml`)
|
||||
)) as ExpandedDocument
|
||||
)) as OpenAPI.ExpandedDocument
|
||||
|
||||
await Promise.all(
|
||||
baseSpecs.tags?.map(async (tag) => {
|
||||
@@ -39,7 +39,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
|
||||
Object.values(paths.paths).forEach((path) => {
|
||||
Object.values(path).forEach((op) => {
|
||||
const operation = op as Operation
|
||||
const operation = op as OpenAPI.Operation
|
||||
const operationName = getSectionId([
|
||||
tag.name,
|
||||
operation.operationId,
|
||||
|
||||
@@ -2,7 +2,7 @@ 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"
|
||||
import type { OpenAPI } from "types"
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
@@ -21,7 +21,7 @@ export async function GET(request: Request) {
|
||||
}
|
||||
const baseSpecs = (await OpenAPIParser.parse(
|
||||
path.join(process.cwd(), "specs", area, "openapi.yaml")
|
||||
)) as ExpandedDocument
|
||||
)) as OpenAPI.ExpandedDocument
|
||||
|
||||
if (expand) {
|
||||
const paths = await getPathsOfTag(expand, area)
|
||||
|
||||
Reference in New Issue
Block a user