docs: fixes and refactoring for API reference (#9708)
* docs: fixes and refactoring for API reference * add route caching * remove caching * use next cache
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { promises as fs } from "fs"
|
||||
import { parseDocument } from "yaml"
|
||||
import { SchemaObject } from "../types/openapi"
|
||||
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
|
||||
|
||||
// resolve references in schema
|
||||
const dereferencedDocument = await dereference({
|
||||
basePath: baseSchemasPath,
|
||||
schemas: [schema],
|
||||
})
|
||||
|
||||
return {
|
||||
dereferencedDocument,
|
||||
originalSchema: schema,
|
||||
}
|
||||
}
|
||||
|
||||
const getSchemaContent = unstable_cache(
|
||||
async (schemaPath: string, baseSchemasPath: string) =>
|
||||
getSchemaContent_(schemaPath, baseSchemasPath),
|
||||
["tag-schema"]
|
||||
)
|
||||
|
||||
export default getSchemaContent
|
||||
Reference in New Issue
Block a user