-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Boris Cherny
committed
Jun 27, 2022
1 parent
e65ad1f
commit 86f398d
Showing
12 changed files
with
1,492 additions
and
1,448 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
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 |
---|---|---|
@@ -1,12 +1,24 @@ | ||
import $RefParser = require('json-schema-ref-parser') | ||
import $RefParser = require('@apidevtools/json-schema-ref-parser') | ||
import {JSONSchema} from './types/JSONSchema' | ||
import {log} from './utils' | ||
|
||
export type DereferencedPaths = WeakMap<$RefParser.JSONSchemaObject, string> | ||
|
||
export async function dereference( | ||
schema: JSONSchema, | ||
{cwd, $refOptions}: {cwd: string; $refOptions: $RefParser.Options} | ||
): Promise<JSONSchema> { | ||
): Promise<{dereferencedPaths: DereferencedPaths; dereferencedSchema: JSONSchema}> { | ||
log('green', 'dereferencer', 'Dereferencing input schema:', cwd, schema) | ||
const parser = new $RefParser() | ||
return parser.dereference(cwd, schema, $refOptions) | ||
const dereferencedPaths: DereferencedPaths = new WeakMap() | ||
const dereferencedSchema = await parser.dereference(cwd, schema as any, { | ||
...$refOptions, | ||
dereference: { | ||
...$refOptions.dereference, | ||
onDereference($ref, schema) { | ||
dereferencedPaths.set(schema, $ref) | ||
} | ||
} | ||
}) as any // TODO | ||
return {dereferencedPaths, dereferencedSchema} | ||
} |
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
Oops, something went wrong.