docs: add prepare script to generate sidebar (#11894)

This commit is contained in:
Shahed Nasser
2025-03-18 17:37:51 +02:00
committed by GitHub
parent eb2aa8da3c
commit 9ead47c51e
72 changed files with 1709 additions and 295 deletions
+4 -4
View File
@@ -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)
+4 -4
View File
@@ -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)
@@ -1,11 +1,11 @@
"use server"
import type { OpenAPIV3 } from "openapi-types"
import type { OpenAPI } from "types"
import Section from "../Section"
import MDXContentServer from "../MDXContent/Server"
export type DescriptionProps = {
specs: OpenAPIV3.Document
specs: OpenAPI.OpenAPIV3.Document
}
const Description = ({ specs }: DescriptionProps) => {
@@ -1,15 +1,14 @@
"use client"
import { useScrollController, useSidebar, H2 as UiH2 } from "docs-ui"
import { getSectionId } from "docs-utils"
import { useEffect, useMemo, useRef, useState } from "react"
import getSectionId from "../../../utils/get-section-id"
import { Sidebar } from "types"
type H2Props = React.HTMLAttributes<HTMLHeadingElement>
const H2 = ({ children, ...props }: H2Props) => {
const headingRef = useRef<HTMLHeadingElement>(null)
const { activePath, addItems, removeItems, shownSidebar } = useSidebar()
const { activePath } = useSidebar()
const { scrollableElement, scrollToElement } = useScrollController()
const [scrolledFirstTime, setScrolledFirstTime] = useState(false)
@@ -28,30 +27,6 @@ const H2 = ({ children, ...props }: H2Props) => {
setScrolledFirstTime(scrolledFirstTime)
}, [scrollableElement, headingRef, id])
useEffect(() => {
if (!shownSidebar) {
return
}
const items: Sidebar.SidebarItem[] = [
{
type: "link",
path: `${id}`,
title: children as string,
loaded: true,
},
]
addItems(items, {
sidebar_id: shownSidebar.sidebar_id,
})
return () => {
removeItems({
items,
sidebar_id: shownSidebar.sidebar_id,
})
}
}, [id, shownSidebar?.sidebar_id])
return (
<UiH2 {...props} id={id} passRef={headingRef}>
{children}
@@ -1,6 +1,6 @@
import type { MDXContentClientProps } from "@/components/MDXContent/Client"
import type { MDXContentServerProps } from "@/components/MDXContent/Server"
import type { SecuritySchemeObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import getSecuritySchemaTypeName from "@/utils/get-security-schema-type-name"
import clsx from "clsx"
import { Loading } from "docs-ui"
@@ -21,7 +21,7 @@ const MDXContentServer = dynamic<MDXContentServerProps>(
) as React.FC<MDXContentServerProps>
export type SecurityDescriptionProps = {
securitySchema: SecuritySchemeObject
securitySchema: OpenAPI.SecuritySchemeObject
isServer?: boolean
}
@@ -1,5 +1,5 @@
import dynamic from "next/dynamic"
import type { OpenAPIV3 } from "openapi-types"
import type { OpenAPI } from "types"
import type { SecurityDescriptionProps } from "./Description"
import { Fragment } from "react"
@@ -8,7 +8,7 @@ const SecurityDescription = dynamic<SecurityDescriptionProps>(
) as React.FC<SecurityDescriptionProps>
type SecurityProps = {
specs?: OpenAPIV3.Document
specs?: OpenAPI.OpenAPIV3.Document
}
const Security = ({ specs }: SecurityProps) => {
@@ -1,11 +1,11 @@
import type { MDXComponents } from "mdx/types"
import Security from "./Security"
import type { OpenAPIV3 } from "openapi-types"
import type { OpenAPI } from "types"
import H2 from "./H2"
import { Link, MDXComponents as UiMDXComponents } from "docs-ui"
export type ScopeType = {
specs?: OpenAPIV3.Document
specs?: OpenAPI.OpenAPIV3.Document
addToSidebar?: boolean
}
@@ -1,9 +1,9 @@
import type { Code } from "@/types/openapi"
import type { OpenAPI } from "types"
import { CodeBlock, CodeTab, CodeTabs } from "docs-ui"
import slugify from "slugify"
export type TagOperationCodeSectionRequestSamplesProps = {
codeSamples: Code[]
codeSamples: OpenAPI.Code[]
}
const TagOperationCodeSectionRequestSamples = ({
@@ -1,10 +1,10 @@
import { CodeBlock } from "docs-ui"
import type { ExampleObject, ResponseObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import { useEffect, useState } from "react"
import useSchemaExample from "../../../../../../hooks/use-schema-example"
export type TagsOperationCodeSectionResponsesSampleProps = {
response: ResponseObject
response: OpenAPI.ResponseObject
} & React.AllHTMLAttributes<HTMLDivElement>
const TagsOperationCodeSectionResponsesSample = ({
@@ -20,7 +20,7 @@ const TagsOperationCodeSectionResponsesSample = ({
schemaExamples: contentSchema?.examples,
})
const [selectedExample, setSelectedExample] = useState<
ExampleObject | undefined
OpenAPI.ExampleObject | undefined
>()
useEffect(() => {
@@ -1,4 +1,4 @@
import type { Operation } from "@/types/openapi"
import type { OpenAPI } from "types"
import dynamic from "next/dynamic"
import type { TagsOperationCodeSectionResponsesSampleProps } from "./Sample"
import { Badge } from "docs-ui"
@@ -9,7 +9,7 @@ const TagsOperationCodeSectionResponsesSample =
) as React.FC<TagsOperationCodeSectionResponsesSampleProps>
type TagsOperationCodeSectionResponsesProps = {
operation: Operation
operation: OpenAPI.Operation
}
const TagsOperationCodeSectionResponses = ({
@@ -1,7 +1,7 @@
"use client"
import MethodLabel from "@/components/MethodLabel"
import type { Operation } from "@/types/openapi"
import type { OpenAPI } from "types"
import TagsOperationCodeSectionResponses from "./Responses"
import type { TagOperationCodeSectionRequestSamplesProps } from "./RequestSamples"
import dynamic from "next/dynamic"
@@ -15,7 +15,7 @@ const TagOperationCodeSectionRequestSamples =
) as React.FC<TagOperationCodeSectionRequestSamplesProps>
export type TagOperationCodeSectionProps = {
operation: Operation
operation: OpenAPI.Operation
method: string
endpointPath: string
} & React.HTMLAttributes<HTMLDivElement>
@@ -1,24 +1,24 @@
import type { Parameter, SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import TagOperationParameters from "../../Parameters"
export type TagsOperationDescriptionSectionParametersProps = {
parameters: Parameter[]
parameters: OpenAPI.Parameter[]
}
const TagsOperationDescriptionSectionParameters = ({
parameters,
}: TagsOperationDescriptionSectionParametersProps) => {
const pathParameters: SchemaObject = {
const pathParameters: OpenAPI.SchemaObject = {
type: "object",
required: [],
properties: {},
}
const queryParameters: SchemaObject = {
const queryParameters: OpenAPI.SchemaObject = {
type: "object",
required: [],
properties: {},
}
const headerParameters: SchemaObject = {
const headerParameters: OpenAPI.SchemaObject = {
type: "object",
required: [],
properties: {},
@@ -1,9 +1,9 @@
import type { RequestObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import TagOperationParameters from "../../Parameters"
import { DetailsSummary } from "docs-ui"
export type TagsOperationDescriptionSectionRequestProps = {
requestBody: RequestObject
requestBody: OpenAPI.RequestObject
}
const TagsOperationDescriptionSectionRequest = ({
@@ -1,11 +1,11 @@
import type { ResponsesObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import clsx from "clsx"
import TagOperationParameters from "../../Parameters"
import { Fragment } from "react"
import { Badge, Details, DetailsSummary } from "docs-ui"
export type TagsOperationDescriptionSectionResponsesProps = {
responses: ResponsesObject
responses: OpenAPI.ResponsesObject
}
const TagsOperationDescriptionSectionResponses = ({
@@ -1,10 +1,10 @@
import { useBaseSpecs } from "@/providers/base-specs"
import type { OpenAPIV3 } from "openapi-types"
import type { OpenAPI } from "types"
import { Card } from "docs-ui"
import { useMemo } from "react"
export type TagsOperationDescriptionSectionSecurityProps = {
security: OpenAPIV3.SecurityRequirementObject[]
security: OpenAPI.OpenAPIV3.SecurityRequirementObject[]
}
const TagsOperationDescriptionSectionSecurity = ({
@@ -1,6 +1,6 @@
"use client"
import type { Operation } from "@/types/openapi"
import type { OpenAPI } from "types"
import type { TagsOperationDescriptionSectionSecurityProps } from "./Security"
import type { TagsOperationDescriptionSectionRequestProps } from "./RequestBody"
import type { TagsOperationDescriptionSectionResponsesProps } from "./Responses"
@@ -33,7 +33,7 @@ const TagsOperationDescriptionSectionWorkflowBadge =
) as React.FC<TagsOperationDescriptionSectionWorkflowBadgeProps>
type TagsOperationDescriptionSectionProps = {
operation: Operation
operation: OpenAPI.Operation
}
const TagsOperationDescriptionSection = ({
operation,
@@ -1,5 +1,5 @@
import MDXContentClient from "@/components/MDXContent/Client"
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import clsx from "clsx"
import dynamic from "next/dynamic"
import { Fragment } from "react"
@@ -10,7 +10,7 @@ const InlineCode = dynamic<InlineCodeProps>(
) as React.FC<InlineCodeProps>
type TagOperationParametersDescriptionProps = {
schema: SchemaObject
schema: OpenAPI.SchemaObject
}
const TagOperationParametersDescription = ({
@@ -1,11 +1,11 @@
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import { Badge, ExpandableNotice, FeatureFlagNotice } from "docs-ui"
import { Fragment } from "react"
export type TagOperationParametersNameProps = {
name: string
isRequired?: boolean
schema: SchemaObject
schema: OpenAPI.SchemaObject
}
const TagOperationParametersName = ({
@@ -94,7 +94,7 @@ const TagOperationParametersName = ({
export default TagOperationParametersName
function formatArrayDescription(schema?: SchemaObject) {
function formatArrayDescription(schema?: OpenAPI.SchemaObject) {
if (!schema) {
return "Array"
}
@@ -107,7 +107,7 @@ function formatArrayDescription(schema?: SchemaObject) {
return `Array of ${type}`
}
function formatUnionDescription(arr?: SchemaObject[]) {
function formatUnionDescription(arr?: OpenAPI.SchemaObject[]) {
const types = [...new Set(arr?.map((type) => type.type || "object"))]
return <>{types.join(" or ")}</>
}
@@ -1,4 +1,4 @@
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import clsx from "clsx"
import type { TagOperationParametersProps } from ".."
import dynamic from "next/dynamic"
@@ -14,7 +14,7 @@ const TagOperationParameters = dynamic<TagOperationParametersProps>(
type TagsOperationParametersSectionProps = {
header?: string
contentType?: string
schema: SchemaObject
schema: OpenAPI.SchemaObject
}
const TagsOperationParametersSection = ({
@@ -1,4 +1,4 @@
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import dynamic from "next/dynamic"
import type { TagOperationParametersDefaultProps } from "../Default"
import type { TagOperationParametersProps } from "../.."
@@ -22,7 +22,7 @@ const TagOperationParameters = dynamic<TagOperationParametersProps>(
export type TagOperationParametersArrayProps = {
name: string
schema: SchemaObject
schema: OpenAPI.SchemaObject
isRequired?: boolean
}
@@ -1,11 +1,11 @@
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import TagOperationParametersDescription from "../../Description"
import clsx from "clsx"
import TagOperationParametersName from "../../Name"
export type TagOperationParametersDefaultProps = {
name?: string
schema: SchemaObject
schema: OpenAPI.SchemaObject
isRequired?: boolean
className?: string
expandable?: boolean
@@ -1,6 +1,6 @@
"use client"
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import TagOperationParametersDefault from "../Default"
import dynamic from "next/dynamic"
import type { TagOperationParametersProps } from "../.."
@@ -33,7 +33,7 @@ const Details = dynamic<DetailsProps>(
export type TagOperationParametersObjectProps = {
name?: string
schema: SchemaObject
schema: OpenAPI.SchemaObject
isRequired?: boolean
topLevel?: boolean
}
@@ -1,4 +1,4 @@
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import clsx from "clsx"
import dynamic from "next/dynamic"
import { useState } from "react"
@@ -31,7 +31,7 @@ const TagsOperationParametersNested =
) as React.FC<TagsOperationParametersNestedProps>
export type TagOperationParamatersOneOfProps = {
schema: SchemaObject
schema: OpenAPI.SchemaObject
isRequired?: boolean
isNested?: boolean
}
@@ -43,7 +43,7 @@ const TagOperationParamatersOneOf = ({
}: TagOperationParamatersOneOfProps) => {
const [activeTab, setActiveTab] = useState<number>(0)
const getName = (item: SchemaObject): string => {
const getName = (item: OpenAPI.SchemaObject): string => {
if (item.title) {
return item.title
}
@@ -1,4 +1,4 @@
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import dynamic from "next/dynamic"
import type { TagOperationParametersDefaultProps } from "../Default"
import { TagOperationParametersObjectProps } from "../Object"
@@ -22,7 +22,7 @@ const TagOperationParametersDefault =
export type TagOperationParametersUnionProps = {
name: string
schema: SchemaObject
schema: OpenAPI.SchemaObject
isRequired?: boolean
topLevel?: boolean
}
@@ -1,4 +1,4 @@
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import dynamic from "next/dynamic"
import type { TagOperationParametersObjectProps } from "./Types/Object"
import type { TagOperationParametersDefaultProps } from "./Types/Default"
@@ -41,7 +41,7 @@ const TagOperationParamatersOneOf = dynamic<TagOperationParamatersOneOfProps>(
) as React.FC<TagOperationParamatersOneOfProps>
export type TagOperationParametersProps = {
schemaObject: SchemaObject
schemaObject: OpenAPI.SchemaObject
topLevel?: boolean
className?: string
isRequired?: boolean
@@ -1,9 +1,7 @@
"use client"
import type { Operation } from "@/types/openapi"
import type { OpenAPI } from "types"
import clsx from "clsx"
import type { OpenAPIV3 } from "openapi-types"
import getSectionId from "@/utils/get-section-id"
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
import dynamic from "next/dynamic"
import { InView } from "react-intersection-observer"
@@ -21,15 +19,16 @@ import { useRouter } from "next/navigation"
import checkElementInViewport from "../../../utils/check-element-in-viewport"
import DividedLoading from "../../DividedLoading"
import SectionContainer from "../../Section/Container"
import { getSectionId } from "docs-utils"
const TagOperationCodeSection = dynamic<TagOperationCodeSectionProps>(
async () => import("./CodeSection")
) as React.FC<TagOperationCodeSectionProps>
export type TagOperationProps = {
operation: Operation
operation: OpenAPI.Operation
method?: string
tag: OpenAPIV3.TagObject
tag: OpenAPI.OpenAPIV3.TagObject
endpointPath: string
className?: string
}
@@ -1,6 +1,6 @@
"use client"
import type { Operation, PathsObject, TagObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import { findSidebarItem, useSidebar } from "docs-ui"
import { Fragment, Suspense, useEffect } from "react"
import dynamic from "next/dynamic"
@@ -16,8 +16,8 @@ const TagOperation = dynamic<TagOperationProps>(
) as React.FC<TagOperationProps>
export type TagPathsProps = {
tag: TagObject
paths: PathsObject
tag: OpenAPI.TagObject
paths: OpenAPI.PathsObject
} & React.HTMLAttributes<HTMLDivElement>
const TagPaths = ({ tag, className, paths }: TagPathsProps) => {
@@ -50,6 +50,7 @@ const TagPaths = ({ tag, className, paths }: TagPathsProps) => {
path: "",
changeLoaded: true,
},
indexPosition: tag["x-associatedSchema"] ? 1 : 0,
})
}
}
@@ -66,7 +67,7 @@ const TagPaths = ({ tag, className, paths }: TagPathsProps) => {
([method, operation], operationIndex) => (
<TagOperation
method={method}
operation={operation as Operation}
operation={operation as OpenAPI.Operation}
tag={tag}
key={`${pathIndex}-${operationIndex}`}
endpointPath={endpointPath}
@@ -1,7 +1,7 @@
"use client"
import { Suspense, useEffect, useMemo } from "react"
import { SchemaObject } from "../../../../types/openapi"
import { OpenAPI } from "types"
import TagOperationParameters from "../../Operation/Parameters"
import {
Badge,
@@ -13,7 +13,6 @@ import {
useScrollController,
useSidebar,
} from "docs-ui"
import getSectionId from "../../../../utils/get-section-id"
import DividedLayout from "../../../../layouts/Divided"
import SectionContainer from "../../../Section/Container"
import useSchemaExample from "../../../../hooks/use-schema-example"
@@ -22,14 +21,15 @@ import checkElementInViewport from "../../../../utils/check-element-in-viewport"
import { singular } from "pluralize"
import clsx from "clsx"
import { useArea } from "../../../../providers/area"
import { getSectionId } from "docs-utils"
export type TagSectionSchemaProps = {
schema: SchemaObject
schema: OpenAPI.SchemaObject
tagName: string
}
const TagSectionSchema = ({ schema, tagName }: TagSectionSchemaProps) => {
const { addItems, setActivePath, activePath, shownSidebar } = useSidebar()
const { setActivePath, activePath, shownSidebar, updateItems } = useSidebar()
const { displayedArea } = useArea()
const formattedName = useMemo(
() => singular(tagName).replaceAll(" ", ""),
@@ -56,34 +56,6 @@ const TagSectionSchema = ({ schema, tagName }: TagSectionSchemaProps) => {
return isElmWindow(scrollableElement) ? document.body : scrollableElement
}, [isBrowser, scrollableElement])
useEffect(() => {
if (!shownSidebar) {
return
}
addItems(
[
{
type: "link",
path: schemaSlug,
title: `${formattedName} Object`,
additionalElms: <Badge variant="neutral">Schema</Badge>,
loaded: true,
},
],
{
sidebar_id: shownSidebar.sidebar_id,
parent: {
type: "category",
title: tagName,
path: "",
changeLoaded: true,
},
indexPosition: 0,
}
)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [formattedName, shownSidebar?.sidebar_id])
useEffect(() => {
if (!isBrowser) {
return
@@ -1,6 +1,5 @@
"use client"
import getSectionId from "@/utils/get-section-id"
import { InView } from "react-intersection-observer"
import { useEffect, useMemo, useState } from "react"
import {
@@ -22,15 +21,16 @@ import SectionDivider from "../../Section/Divider"
import clsx from "clsx"
import { Feedback, Loading, Link } from "docs-ui"
import { usePathname, useRouter } from "next/navigation"
import { PathsObject, SchemaObject, TagObject } from "@/types/openapi"
import { OpenAPI } from "types"
import TagSectionSchema from "./Schema"
import checkElementInViewport from "../../../utils/check-element-in-viewport"
import TagPaths from "../Paths"
import useSWR from "swr"
import basePathUrl from "../../../utils/base-path-url"
import { getSectionId } from "docs-utils"
export type TagSectionProps = {
tag: TagObject
tag: OpenAPI.TagObject
} & React.HTMLAttributes<HTMLDivElement>
const Section = dynamic<SectionProps>(
@@ -62,7 +62,7 @@ const TagSectionComponent = ({ tag }: TagSectionProps) => {
return isElmWindow(scrollableElement) ? document.body : scrollableElement
}, [scrollableElement, isBrowser])
const { data: schemaData } = useSWR<{
schema: SchemaObject
schema: OpenAPI.SchemaObject
}>(
loadData && tag["x-associatedSchema"]
? basePathUrl(
@@ -75,7 +75,7 @@ const TagSectionComponent = ({ tag }: TagSectionProps) => {
}
)
const { data: pathsData } = useSWR<{
paths: PathsObject
paths: OpenAPI.PathsObject
}>(
loadData ? basePathUrl(`/tag?tagName=${slugTagName}&area=${area}`) : null,
swrFetcher,
@@ -1,4 +1,4 @@
import { OpenAPIV3 } from "openapi-types"
import { OpenAPI } from "types"
import { TagSectionProps } from "./Section"
import dynamic from "next/dynamic"
import { Suspense } from "react"
@@ -8,7 +8,7 @@ const TagSection = dynamic<TagSectionProps>(
) as React.FC<TagSectionProps>
type TagsProps = {
tags?: OpenAPIV3.TagObject[]
tags?: OpenAPI.OpenAPIV3.TagObject[]
}
const Tags = ({ tags }: TagsProps) => {
+1 -8
View File
@@ -12,14 +12,7 @@ export const config: DocsConfig = {
{
sidebar_id: "api-ref",
title: "API Reference",
items: [
{
type: "link",
title: "Introduction",
path: "introduction",
loaded: true,
},
],
items: [],
},
],
project: {
+1
View File
@@ -28,6 +28,7 @@ export default [
"**/node_modules",
"**/public",
"**/.eslintrc.js",
"**/generated",
],
},
...compat.extends(
@@ -0,0 +1,784 @@
const generatedgeneratedAdminSidebarSidebar = {
"sidebar_id": "admin",
"title": "Admin",
"items": [
{
"type": "link",
"title": "Introduction",
"path": "introduction",
"loaded": true
},
{
"type": "link",
"title": "Authentication",
"path": "authentication",
"loaded": true
},
{
"type": "link",
"title": "HTTP Compression",
"path": "http-compression",
"loaded": true
},
{
"type": "link",
"title": "Select Fields and Relations",
"path": "select-fields-and-relations",
"loaded": true
},
{
"type": "link",
"title": "Query Parameter Types",
"path": "query-parameter-types",
"loaded": true
},
{
"type": "link",
"title": "Pagination",
"path": "pagination",
"loaded": true
},
{
"type": "link",
"title": "Workflows",
"path": "workflows",
"loaded": true
},
{
"type": "separator"
},
{
"type": "category",
"title": "Auth",
"children": [],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Api Keys",
"children": [
{
"type": "link",
"path": "api-keys_apikey_schema",
"title": "ApiKey Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Campaigns",
"children": [
{
"type": "link",
"path": "campaigns_campaign_schema",
"title": "Campaign Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Claims",
"children": [
{
"type": "link",
"path": "claims_claim_schema",
"title": "Claim Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Collections",
"children": [
{
"type": "link",
"path": "collections_collection_schema",
"title": "Collection Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Currencies",
"children": [
{
"type": "link",
"path": "currencies_currency_schema",
"title": "Currency Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Customer Groups",
"children": [
{
"type": "link",
"path": "customer-groups_customergroup_schema",
"title": "CustomerGroup Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Customers",
"children": [
{
"type": "link",
"path": "customers_customer_schema",
"title": "Customer Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Draft Orders",
"children": [
{
"type": "link",
"path": "draft-orders_draftorder_schema",
"title": "DraftOrder Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Exchanges",
"children": [
{
"type": "link",
"path": "exchanges_exchange_schema",
"title": "Exchange Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Fulfillment Providers",
"children": [
{
"type": "link",
"path": "fulfillment-providers_fulfillmentprovider_schema",
"title": "FulfillmentProvider Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Fulfillment Sets",
"children": [
{
"type": "link",
"path": "fulfillment-sets_fulfillmentset_schema",
"title": "FulfillmentSet Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Fulfillments",
"children": [
{
"type": "link",
"path": "fulfillments_fulfillment_schema",
"title": "Fulfillment Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Inventory Items",
"children": [
{
"type": "link",
"path": "inventory-items_inventoryitem_schema",
"title": "InventoryItem Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Invites",
"children": [
{
"type": "link",
"path": "invites_invite_schema",
"title": "Invite Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Notifications",
"children": [
{
"type": "link",
"path": "notifications_notification_schema",
"title": "Notification Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Order Edits",
"children": [],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Orders",
"children": [
{
"type": "link",
"path": "orders_order_schema",
"title": "Order Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Payment Collections",
"children": [
{
"type": "link",
"path": "payment-collections_paymentcollection_schema",
"title": "PaymentCollection Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Payments",
"children": [
{
"type": "link",
"path": "payments_payment_schema",
"title": "Payment Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Price Lists",
"children": [
{
"type": "link",
"path": "price-lists_pricelist_schema",
"title": "PriceList Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Price Preferences",
"children": [
{
"type": "link",
"path": "price-preferences_pricepreference_schema",
"title": "PricePreference Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Product Categories",
"children": [
{
"type": "link",
"path": "product-categories_productcategory_schema",
"title": "ProductCategory Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Product Tags",
"children": [
{
"type": "link",
"path": "product-tags_producttag_schema",
"title": "ProductTag Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Product Types",
"children": [
{
"type": "link",
"path": "product-types_producttype_schema",
"title": "ProductType Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Product Variants",
"children": [
{
"type": "link",
"path": "product-variants_productvariant_schema",
"title": "ProductVariant Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Products",
"children": [
{
"type": "link",
"path": "products_product_schema",
"title": "Product Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Promotions",
"children": [
{
"type": "link",
"path": "promotions_promotion_schema",
"title": "Promotion Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Refund Reasons",
"children": [
{
"type": "link",
"path": "refund-reasons_refundreason_schema",
"title": "RefundReason Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Regions",
"children": [
{
"type": "link",
"path": "regions_region_schema",
"title": "Region Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Reservations",
"children": [
{
"type": "link",
"path": "reservations_reservation_schema",
"title": "Reservation Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Return Reasons",
"children": [
{
"type": "link",
"path": "return-reasons_returnreason_schema",
"title": "ReturnReason Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Returns",
"children": [
{
"type": "link",
"path": "returns_return_schema",
"title": "Return Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Sales Channels",
"children": [
{
"type": "link",
"path": "sales-channels_saleschannel_schema",
"title": "SalesChannel Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Shipping Options",
"children": [
{
"type": "link",
"path": "shipping-options_shippingoption_schema",
"title": "ShippingOption Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Shipping Profiles",
"children": [
{
"type": "link",
"path": "shipping-profiles_shippingprofile_schema",
"title": "ShippingProfile Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Stock Locations",
"children": [
{
"type": "link",
"path": "stock-locations_stocklocation_schema",
"title": "StockLocation Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Stores",
"children": [
{
"type": "link",
"path": "stores_store_schema",
"title": "Store Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Tax Rates",
"children": [
{
"type": "link",
"path": "tax-rates_taxrate_schema",
"title": "TaxRate Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Tax Regions",
"children": [
{
"type": "link",
"path": "tax-regions_taxregion_schema",
"title": "TaxRegion Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Uploads",
"children": [],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Users",
"children": [
{
"type": "link",
"path": "users_user_schema",
"title": "User Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Workflows Executions",
"children": [],
"loaded": false,
"showLoadingIfEmpty": true
}
],
"custom_autogenerate": "api-ref"
}
export default generatedgeneratedAdminSidebarSidebar
@@ -0,0 +1,337 @@
const generatedgeneratedStoreSidebarSidebar = {
"sidebar_id": "store",
"title": "Store",
"items": [
{
"type": "link",
"title": "Introduction",
"path": "introduction",
"loaded": true
},
{
"type": "link",
"title": "Authentication",
"path": "authentication",
"loaded": true
},
{
"type": "link",
"title": "Publishable API Key",
"path": "publishable-api-key",
"loaded": true
},
{
"type": "link",
"title": "HTTP Compression",
"path": "http-compression",
"loaded": true
},
{
"type": "link",
"title": "Select Fields and Relations",
"path": "select-fields-and-relations",
"loaded": true
},
{
"type": "link",
"title": "Query Parameter Types",
"path": "query-parameter-types",
"loaded": true
},
{
"type": "link",
"title": "Pagination",
"path": "pagination",
"loaded": true
},
{
"type": "link",
"title": "Workflows",
"path": "workflows",
"loaded": true
},
{
"type": "separator"
},
{
"type": "category",
"title": "Auth",
"children": [],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Carts",
"children": [
{
"type": "link",
"path": "carts_cart_schema",
"title": "Cart Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Collections",
"children": [
{
"type": "link",
"path": "collections_collection_schema",
"title": "Collection Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Currencies",
"children": [
{
"type": "link",
"path": "currencies_currency_schema",
"title": "Currency Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Customers",
"children": [
{
"type": "link",
"path": "customers_customer_schema",
"title": "Customer Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Orders",
"children": [
{
"type": "link",
"path": "orders_order_schema",
"title": "Order Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Payment Collections",
"children": [
{
"type": "link",
"path": "payment-collections_paymentcollection_schema",
"title": "PaymentCollection Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Payment Providers",
"children": [
{
"type": "link",
"path": "payment-providers_paymentprovider_schema",
"title": "PaymentProvider Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Product Categories",
"children": [
{
"type": "link",
"path": "product-categories_productcategory_schema",
"title": "ProductCategory Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Product Tags",
"children": [
{
"type": "link",
"path": "product-tags_producttag_schema",
"title": "ProductTag Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Product Types",
"children": [
{
"type": "link",
"path": "product-types_producttype_schema",
"title": "ProductType Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Products",
"children": [
{
"type": "link",
"path": "products_product_schema",
"title": "Product Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Regions",
"children": [
{
"type": "link",
"path": "regions_region_schema",
"title": "Region Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Return",
"children": [
{
"type": "link",
"path": "return_return_schema",
"title": "Return Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Return Reasons",
"children": [
{
"type": "link",
"path": "return-reasons_returnreason_schema",
"title": "ReturnReason Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
},
{
"type": "category",
"title": "Shipping Options",
"children": [
{
"type": "link",
"path": "shipping-options_shippingoption_schema",
"title": "ShippingOption Object",
"loaded": true,
"badge": {
"variant": "neutral",
"text": "Schema"
}
}
],
"loaded": false,
"showLoadingIfEmpty": true
}
],
"custom_autogenerate": "api-ref"
}
export default generatedgeneratedStoreSidebarSidebar
@@ -1,15 +1,14 @@
"use client"
import { useMemo } from "react"
import { ExampleObject, SchemaObject } from "../types/openapi"
import { OpenAPI } from "types"
import type { JSONSchema7 } from "json-schema"
import stringify from "json-stringify-pretty-compact"
import { sample } from "openapi-sampler"
import { OpenAPIV3 } from "openapi-types"
type Options = {
schema?: SchemaObject
schemaExamples?: OpenAPIV3.ExampleObject
schema?: OpenAPI.SchemaObject
schemaExamples?: OpenAPI.OpenAPIV3.ExampleObject
schemaExample?: any
options?: {
skipNonRequired?: boolean
@@ -24,7 +23,7 @@ const useSchemaExample = ({
}: Options) => {
const { skipNonRequired = true } = options
const examples = useMemo(() => {
const tempExamples: ExampleObject[] = []
const tempExamples: OpenAPI.ExampleObject[] = []
if (!schema) {
return tempExamples
+3 -3
View File
@@ -1,10 +1,10 @@
"use server"
import { Area, ExpandedDocument } from "../types/openapi"
import { OpenAPI } from "types"
const URL = `${process.env.NEXT_PUBLIC_BASE_URL}${process.env.NEXT_PUBLIC_BASE_PATH}`
export async function getBaseSpecs(area: Area) {
export async function getBaseSpecs(area: OpenAPI.Area) {
try {
const res = await fetch(`${URL}/base-specs?area=${area}`, {
next: {
@@ -13,7 +13,7 @@ export async function getBaseSpecs(area: Area) {
},
}).then(async (res) => res.json())
return res as ExpandedDocument
return res as OpenAPI.ExpandedDocument
} catch (e) {
console.error(e)
}
+4 -1
View File
@@ -18,7 +18,10 @@ const nextConfig = {
return config
},
transpilePackages: ["docs-ui"],
transpilePackages: ["docs-ui", "docs-utils"],
experimental: {
optimizePackageImports: ["docs-utils"],
},
async redirects() {
return [
{
+2 -2
View File
@@ -10,7 +10,8 @@
"build:prod": "NEXT_PUBLIC_ENV=production next build",
"start": "next start",
"start:monorepo": "yarn start -p 3000",
"lint": "next lint --fix"
"lint": "next lint --fix",
"prep": "node ./scripts/prepare.mjs"
},
"dependencies": {
"@mdx-js/loader": "^3.1.0",
@@ -31,7 +32,6 @@
"next": "15.0.4",
"next-mdx-remote": "5.0.0",
"openapi-sampler": "^1.3.1",
"openapi-types": "^12.1.3",
"pluralize": "^8.0.0",
"postcss": "8.4.27",
"prism-react-renderer": "2.4.0",
+14 -7
View File
@@ -1,27 +1,30 @@
"use client"
import type { Area } from "@/types/openapi"
import { capitalize, usePrevious, useSearch } from "docs-ui"
import type { OpenAPI } from "types"
import { capitalize, usePrevious, useSearch, useSidebar } from "docs-ui"
import { createContext, useContext, useEffect, useMemo, useState } from "react"
import { usePathname } from "next/navigation"
type AreaContextType = {
area: Area
prevArea: Area | undefined
area: OpenAPI.Area
prevArea: OpenAPI.Area | undefined
displayedArea: string
setArea: (value: Area) => void
setArea: (value: OpenAPI.Area) => void
}
const AreaContext = createContext<AreaContextType | null>(null)
type AreaProviderProps = {
area: Area
area: OpenAPI.Area
children: React.ReactNode
}
const AreaProvider = ({ area: passedArea, children }: AreaProviderProps) => {
const [area, setArea] = useState<Area>(passedArea)
const [area, setArea] = useState<OpenAPI.Area>(passedArea)
const prevArea = usePrevious(area)
const { defaultFilters, setDefaultFilters } = useSearch()
const { setActivePath } = useSidebar()
const pathname = usePathname()
const displayedArea = useMemo(() => {
return capitalize(area)
@@ -33,6 +36,10 @@ const AreaProvider = ({ area: passedArea, children }: AreaProviderProps) => {
}
}, [area, defaultFilters, setDefaultFilters])
useEffect(() => {
setActivePath(null)
}, [pathname])
return (
<AreaContext.Provider
value={{
+38 -33
View File
@@ -1,33 +1,35 @@
"use client"
import { ExpandedDocument, SecuritySchemeObject } from "@/types/openapi"
import { OpenAPI } from "types"
import { ReactNode, createContext, useContext, useEffect, useMemo } from "react"
import { Sidebar } from "types"
import getSectionId from "../utils/get-section-id"
import getTagChildSidebarItems from "../utils/get-tag-child-sidebar-items"
import { useRouter } from "next/navigation"
import { useSidebar } from "docs-ui"
import { UpdateActionType, UpdateSidebarItemTypes, useSidebar } from "docs-ui"
import { getSectionId } from "docs-utils"
type BaseSpecsContextType = {
baseSpecs: ExpandedDocument | undefined
getSecuritySchema: (securityName: string) => SecuritySchemeObject | null
baseSpecs: OpenAPI.ExpandedDocument | undefined
getSecuritySchema: (
securityName: string
) => OpenAPI.SecuritySchemeObject | null
}
const BaseSpecsContext = createContext<BaseSpecsContextType | null>(null)
type BaseSpecsProviderProps = {
baseSpecs: ExpandedDocument | undefined
baseSpecs: OpenAPI.ExpandedDocument | undefined
children?: ReactNode
}
const BaseSpecsProvider = ({ children, baseSpecs }: BaseSpecsProviderProps) => {
const router = useRouter()
const { activePath, addItems, setActivePath, resetItems, shownSidebar } =
const { activePath, setActivePath, resetItems, shownSidebar, updateItems } =
useSidebar()
const getSecuritySchema = (
securityName: string
): SecuritySchemeObject | null => {
): OpenAPI.SecuritySchemeObject | null => {
if (
baseSpecs?.components?.securitySchemes &&
Object.prototype.hasOwnProperty.call(
@@ -44,16 +46,12 @@ const BaseSpecsProvider = ({ children, baseSpecs }: BaseSpecsProviderProps) => {
return null
}
const itemsToAdd = useMemo(() => {
const itemsToUpdate = useMemo(() => {
if (!baseSpecs) {
return []
}
const itemsToAdd: Sidebar.SidebarItem[] = [
{
type: "separator",
},
]
const itemsToUpdate: UpdateActionType["items"] = []
baseSpecs.tags?.forEach((tag) => {
const tagPathName = getSectionId([tag.name.toLowerCase()])
@@ -62,37 +60,44 @@ const BaseSpecsProvider = ({ children, baseSpecs }: BaseSpecsProviderProps) => {
Object.hasOwn(baseSpecs.expandedTags, tagPathName)
? getTagChildSidebarItems(baseSpecs.expandedTags[tagPathName])
: []
itemsToAdd.push({
type: "category",
title: tag.name,
children: childItems,
loaded: childItems.length > 0,
showLoadingIfEmpty: true,
onOpen: () => {
if (location.hash !== tagPathName) {
router.push(`#${tagPathName}`, {
scroll: false,
})
}
if (activePath !== tagPathName) {
setActivePath(tagPathName)
}
itemsToUpdate.push({
existingItem: {
type: "category",
title: tag.name,
},
newItem: {
children: childItems,
loaded: childItems.length > 0,
onOpen: () => {
if (location.hash !== tagPathName) {
router.push(`#${tagPathName}`, {
scroll: false,
})
}
if (activePath !== tagPathName) {
setActivePath(tagPathName)
}
},
},
options: {
setChildrenBehavior: "merge",
},
})
})
return itemsToAdd
return itemsToUpdate
}, [baseSpecs])
useEffect(() => {
if (!itemsToAdd.length || !shownSidebar) {
if (!itemsToUpdate.length || !shownSidebar) {
return
}
addItems(itemsToAdd, {
updateItems({
sidebar_id: shownSidebar.sidebar_id,
items: itemsToUpdate,
})
}, [itemsToAdd, shownSidebar?.sidebar_id])
}, [itemsToUpdate, shownSidebar?.sidebar_id])
useEffect(() => {
return () => {
+24 -1
View File
@@ -5,6 +5,9 @@ import {
usePageLoading,
useScrollController,
} from "docs-ui"
import { usePathname } from "next/navigation"
import { Sidebar } from "types"
import { useCallback, useEffect, useState } from "react"
import { config } from "../config"
type SidebarProviderProps = {
@@ -14,6 +17,26 @@ type SidebarProviderProps = {
const SidebarProvider = ({ children }: SidebarProviderProps) => {
const { isLoading, setIsLoading } = usePageLoading()
const { scrollableElement } = useScrollController()
const [sidebar, setSidebar] = useState<Sidebar.Sidebar | undefined>()
const path = usePathname()
const loadSidebar = useCallback(async () => {
if (path.startsWith("/store")) {
return (await import("../generated/generated-store-sidebar.mjs"))
.default as Sidebar.Sidebar
}
return (await import("../generated/generated-admin-sidebar.mjs"))
.default as Sidebar.Sidebar
}, [path])
useEffect(() => {
loadSidebar()
.then(setSidebar)
.catch((error) => {
console.error("Error loading sidebar:", error)
})
}, [loadSidebar])
return (
<UiSidebarProvider
@@ -22,7 +45,7 @@ const SidebarProvider = ({ children }: SidebarProviderProps) => {
shouldHandleHashChange={true}
shouldHandlePathChange={false}
scrollableElement={scrollableElement}
sidebars={config.sidebars}
sidebars={sidebar ? [sidebar] : config.sidebars}
persistCategoryState={false}
disableActiveTransition={false}
isSidebarStatic={false}
@@ -0,0 +1,22 @@
import { generateSplitSidebars } from "build-scripts"
async function main() {
await generateSplitSidebars({
sidebars: [
{
sidebar_id: "store",
title: "Store",
items: [],
custom_autogenerate: "api-ref",
},
{
sidebar_id: "admin",
title: "Admin",
items: [],
custom_autogenerate: "api-ref",
},
],
})
}
void main()
-134
View File
@@ -1,134 +0,0 @@
import type { OpenAPIV3 } from "openapi-types"
export type Area = "admin" | "store"
export type Code = {
lang: string
label: string
source: string
}
export type Operation = OpenAPIV3.OperationObject<{
operationId: string
summary: string
description: string
"x-authenticated": boolean
"x-codeSamples": Code[]
requestBody: RequestObject
responses: ResponsesObject
parameters: Parameter[]
"x-featureFlag"?: string
"x-workflow"?: string
"x-sidebar-summary"?: string
}>
export type RequestObject = OpenAPIV3.RequestBodyObject & {
content: {
[media: string]: OpenAPIV3.MediaTypeObject & {
schema: SchemaObject
}
}
}
export type ResponseObject = OpenAPIV3.ResponseObject & {
content: {
[media: string]: Omit<OpenAPIV3.MediaTypeObject, "examples"> & {
schema: SchemaObject
}
}
contentSample?: string
}
export type ResponsesObject = {
[code: string]: ResponseObject
}
export type ExampleObject = {
title: string
value: string
content: string
contentDetailed?: string
contentSchema?: string
}
export type PathsObject = {
[pattern: string]: Path
}
export type Path = OpenAPIV3.PathItemObject & {
[method in OpenAPIV3.HttpMethods]?: Operation
}
export type ArraySchemaObject = Omit<
OpenAPIV3.ArraySchemaObject,
"properties" | "anyOf" | "allOf" | "oneOf" | "examples"
> & {
items: SchemaObject
properties: PropertiesObject
anyOf?: SchemaObject[]
allOf?: SchemaObject[]
oneOf?: SchemaObject[]
}
export type NonArraySchemaObject = Omit<
OpenAPIV3.NonArraySchemaObject,
| "properties"
| "anyOf"
| "allOf"
| "oneOf"
| "examples"
| "additionalProperties"
> & {
properties: PropertiesObject
additionalProperties?: SchemaObject
anyOf?: SchemaObject[]
allOf?: SchemaObject[]
oneOf?: SchemaObject[]
}
export type SchemaObject = (ArraySchemaObject | NonArraySchemaObject) & {
parameterName?: string
resolvedRef?: SchemaObject
examples?: {
[media: string]: OpenAPIV3.ExampleObject
}
isRequired?: boolean
"x-featureFlag"?: string
"x-expandable"?: string
"x-schemaName"?: string
additionalProperties?: SchemaObject
}
export type PropertiesObject = {
[name: string]: SchemaObject
}
export type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject & {
"x-displayName"?: string
"x-is-auth"?: boolean
}
export type Parameter = OpenAPIV3.ParameterObject & {
examples: {
[media: string]: OpenAPIV3.ExampleObject
}
schema: SchemaObject
}
export type Document = Omit<OpenAPIV3.Document, "paths"> & {
paths: PathsObject
}
export type ExpandedDocument = Document & {
expandedTags?: {
[k: string]: PathsObject
}
}
export type TagObject = OpenAPIV3.TagObject & {
"x-associatedSchema"?: OpenAPIV3.ReferenceObject
}
export type ParsedPathItemObject = OpenAPIV3.PathItemObject<Operation> & {
operationPath?: string
}
@@ -1,5 +1,8 @@
import type { SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
export default function checkRequired(schema: SchemaObject, property?: string) {
export default function checkRequired(
schema: OpenAPI.SchemaObject,
property?: string
) {
return property !== undefined && schema.required?.includes(property)
}
+6 -6
View File
@@ -1,19 +1,19 @@
import { Document, ParsedPathItemObject, SchemaObject } from "@/types/openapi"
import { OpenAPI } from "types"
import OpenAPIParser from "@readme/openapi-parser"
type Options = {
basePath: string
paths?: ParsedPathItemObject[]
schemas?: SchemaObject[]
paths?: OpenAPI.ParsedPathItemObject[]
schemas?: OpenAPI.SchemaObject[]
}
export default async function dereference({
basePath,
paths,
schemas,
}: Options): Promise<Document> {
}: Options): Promise<OpenAPI.Document> {
// dereference the references in the paths
let document: Document = {
let document: OpenAPI.Document = {
paths: {},
// These attributes are only for validation purposes
openapi: "3.0.0",
@@ -56,7 +56,7 @@ export default async function dereference({
dereference: {
circular: "ignore",
},
})) as unknown as Document
})) as unknown as OpenAPI.Document
return document
}
@@ -1,28 +1,26 @@
import path from "path"
import { promises as fs } from "fs"
import type { OpenAPIV3 } from "openapi-types"
import type { Operation, Document, ParsedPathItemObject } from "@/types/openapi"
import type { OpenAPI } from "types"
import readSpecDocument from "./read-spec-document"
import getSectionId from "./get-section-id"
import dereference from "./dereference"
import { unstable_cache } from "next/cache"
import { oasFileToPath } from "docs-utils"
import { getSectionId, oasFileToPath } from "docs-utils"
async function getPathsOfTag_(
tagName: string,
area: string
): Promise<Document> {
): Promise<OpenAPI.Document> {
// get path files
const basePath = path.join(process.cwd(), "specs", `${area}/paths`)
const files = await fs.readdir(basePath)
// read the path documents
let documents: ParsedPathItemObject[] = await Promise.all(
let documents: OpenAPI.ParsedPathItemObject[] = await Promise.all(
files.map(async (file) => {
const fileContent = (await readSpecDocument(
path.join(basePath, file)
)) as OpenAPIV3.PathItemObject<Operation>
)) as OpenAPI.OpenAPIV3.PathItemObject<OpenAPI.Operation>
return {
...fileContent,
@@ -1,12 +1,12 @@
import { promises as fs } from "fs"
import { parseDocument } from "yaml"
import { SchemaObject } from "../types/openapi"
import { OpenAPI } from "types"
import dereference from "./dereference"
import { unstable_cache } from "next/cache"
async function getSchemaContent_(schemaPath: string, baseSchemasPath: string) {
const schemaContent = await fs.readFile(schemaPath, "utf-8")
const schema = parseDocument(schemaContent).toJS() as SchemaObject
const schema = parseDocument(schemaContent).toJS() as OpenAPI.SchemaObject
// resolve references in schema
const dereferencedDocument = await dereference({
@@ -1,6 +0,0 @@
import slugify from "slugify"
export default function getSectionId(path: string[]) {
path = path.map((p) => slugify(p.trim().toLowerCase()))
return path.join("_")
}
@@ -1,7 +1,7 @@
import { OpenAPIV3 } from "openapi-types"
import { OpenAPI } from "types"
export default function getSecuritySchemaTypeName(
securitySchema: OpenAPIV3.SecuritySchemeObject
securitySchema: OpenAPI.OpenAPIV3.SecuritySchemeObject
) {
switch (securitySchema.type) {
case "apiKey":
@@ -1,22 +1,21 @@
import type { Operation, PathsObject } from "@/types/openapi"
import type { OpenAPIV3 } from "openapi-types"
import type { OpenAPI } from "types"
import dynamic from "next/dynamic"
import type { MethodLabelProps } from "@/components/MethodLabel"
import getSectionId from "./get-section-id"
import { Sidebar } from "types"
import { getSectionId } from "docs-utils"
const MethodLabel = dynamic<MethodLabelProps>(
async () => import("../components/MethodLabel")
) as React.FC<MethodLabelProps>
export default function getTagChildSidebarItems(
paths: PathsObject
paths: OpenAPI.PathsObject
): Sidebar.SidebarItem[] {
const items: Sidebar.SidebarItem[] = []
Object.entries(paths).forEach(([, operations]) => {
Object.entries(operations).map(([method, operation]) => {
const definedOperation = operation as Operation
const definedMethod = method as OpenAPIV3.HttpMethods
const definedOperation = operation as OpenAPI.Operation
const definedMethod = method as OpenAPI.OpenAPIV3.HttpMethods
items.push({
type: "link",
path: getSectionId([
@@ -1,14 +1,14 @@
import type { PropertiesObject, SchemaObject } from "@/types/openapi"
import type { OpenAPI } from "types"
export default function mergeAllOfTypes(
allOfSchema: SchemaObject
): SchemaObject {
allOfSchema: OpenAPI.SchemaObject
): OpenAPI.SchemaObject {
if (!allOfSchema.allOf) {
// return whatever the schema is
return allOfSchema
}
// merge objects' properties in this var
let properties: PropertiesObject = {}
let properties: OpenAPI.PropertiesObject = {}
let foundObjects = false
allOfSchema.allOf.forEach((item) => {
@@ -1,8 +1,8 @@
import { promises as fs } from "fs"
import { OpenAPIV3 } from "openapi-types"
import { OpenAPI } from "types"
import { parseDocument } from "yaml"
export default async function readSpecDocument(filePath: string) {
const fileContent = await fs.readFile(filePath, "utf-8")
return parseDocument(fileContent).toJS() as OpenAPIV3.PathItemObject
return parseDocument(fileContent).toJS() as OpenAPI.OpenAPIV3.PathItemObject
}