($ref: string, definitions: Definitions): JsonSchema | undefinedResolves a $ref string by looking up the last path segment in a
definitions map.
When to use
Use when you need to dereference a $ref pointer to get the JSON Schema
object it points to.
Details
This only resolves the final segment of the ref path, such as "User" from
"#/$defs/User". It returns undefined if the definition is not found.
Gotchas
This function does not follow arbitrary JSON Pointer paths.
Example (Resolving a $ref)
import { JsonSchema } from "effect"
const definitions: JsonSchema.Definitions = {
User: { type: "object", properties: { name: { type: "string" } } }
}
const result = JsonSchema.resolve$ref("#/$defs/User", definitions)
console.log(result) // { type: "object", properties: { name: { type: "string" } } }
const missing = JsonSchema.resolve$ref("#/$defs/Unknown", definitions)
console.log(missing) // undefinedexport function function resolve$ref(
$ref: string,
definitions: Definitions
): JsonSchema | undefined
Resolves a $ref string by looking up the last path segment in a
definitions map.
When to use
Use when you need to dereference a $ref pointer to get the JSON Schema
object it points to.
Details
This only resolves the final segment of the ref path, such as "User" from
"#/$defs/User". It returns undefined if the definition is not found.
Gotchas
This function does not follow arbitrary JSON Pointer paths.
Example (Resolving a $ref)
import { JsonSchema } from "effect"
const definitions: JsonSchema.Definitions = {
User: { type: "object", properties: { name: { type: "string" } } }
}
const result = JsonSchema.resolve$ref("#/$defs/User", definitions)
console.log(result) // { type: "object", properties: { name: { type: "string" } } }
const missing = JsonSchema.resolve$ref("#/$defs/Unknown", definitions)
console.log(missing) // undefined
resolve$ref($ref: string$ref: string, definitions: Definitionsdefinitions: Definitions): JsonSchema | undefined {
const const tokens: string[]tokens = $ref: string$ref.String.split(separator: string | RegExp, limit?: number): string[] (+1 overload)Split a string into substrings using the specified separator and return them as an array.
split("/")
if (const tokens: string[]tokens.Array<string>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length > 0) {
const const identifier: anyidentifier = import unescapeTokenunescapeToken(const tokens: string[]tokens[const tokens: string[]tokens.Array<string>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length - 1])
const const definition: JsonSchemadefinition = definitions: Definitionsdefinitions[const identifier: anyidentifier]
if (const definition: JsonSchemadefinition !== var undefinedundefined) {
return const definition: JsonSchemadefinition
}
}
}