Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
25 lines
946 B
Plaintext
25 lines
946 B
Plaintext
import {$RefParser, ParserOptions as $RefOptions} from '@apidevtools/json-schema-ref-parser'
|
|
import {JSONSchema} from './types/JSONSchema'
|
|
import {log} from './utils'
|
|
|
|
export type DereferencedPaths = WeakMap<JSONSchema, string>
|
|
|
|
export async function dereference(
|
|
schema: JSONSchema,
|
|
{cwd, $refOptions}: {cwd: string; $refOptions: $RefOptions},
|
|
): Promise<{dereferencedPaths: DereferencedPaths; dereferencedSchema: JSONSchema}> {
|
|
log('green', 'dereferencer', 'Dereferencing input schema:', cwd, schema)
|
|
const parser = new $RefParser()
|
|
const dereferencedPaths: DereferencedPaths = new WeakMap()
|
|
const dereferencedSchema = (await parser.dereference(cwd, schema, {
|
|
...$refOptions,
|
|
dereference: {
|
|
...$refOptions.dereference,
|
|
onDereference($ref: string, schema: JSONSchema) {
|
|
dereferencedPaths.set(schema, $ref)
|
|
},
|
|
},
|
|
})) as any // TODO: fix types
|
|
return {dereferencedPaths, dereferencedSchema}
|
|
}
|