-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e40c66
commit 1695aae
Showing
3 changed files
with
45 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |