Files
threshold/website/pages/api-docs/[[...page]].jsx
T

37 lines
1.1 KiB
React
Raw Normal View History

2020-10-09 16:26:32 -04:00
import { productName, productSlug } from 'data/metadata'
import OpenApiPage from '@hashicorp/react-open-api-page'
/* Used server-side only */
2020-10-09 16:26:32 -04:00
import path from 'path'
import {
2020-10-09 16:26:32 -04:00
getPathsFromSchema,
getPropsForPage,
} from '@hashicorp/react-open-api-page/server'
import { processSchemaFile } from '@hashicorp/react-open-api-page/process-schema'
2020-10-09 16:26:32 -04:00
const targetFile = '../internal/gen/controller.swagger.json'
const pathFromRoot = 'api-docs'
2020-12-16 16:43:06 -05:00
export default function OpenApiDocsPage(props) {
2020-10-09 16:26:32 -04:00
return (
<OpenApiPage
{...props}
productName={productName}
productSlug={productSlug}
baseRoute={pathFromRoot}
2020-10-09 16:26:32 -04:00
/>
)
}
export async function getStaticPaths() {
const swaggerFile = path.join(process.cwd(), targetFile)
const schema = await processSchemaFile(swaggerFile)
2020-10-09 16:26:32 -04:00
const paths = getPathsFromSchema(schema)
return { paths, fallback: false }
}
export async function getStaticProps({ params }) {
const swaggerFile = path.join(process.cwd(), targetFile)
const schema = await processSchemaFile(swaggerFile)
2020-10-09 16:26:32 -04:00
const props = getPropsForPage(schema, params)
return { props }
}