Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve references before validating the discriminator #1815

Merged
merged 15 commits into from
Jan 15, 2022
Merged
Prev Previous commit
Next Next commit
resolve schema from SchemaEnv
  • Loading branch information
dfeufel committed Nov 17, 2021
commit 3fc732a65d2afaca85a4aae1c9fa554f9e741387
5 changes: 4 additions & 1 deletion lib/vocabularies/discriminator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {CodeKeywordDefinition, AnySchemaObject, KeywordErrorDefinition} fro
import type {KeywordCxt} from "../../compile/validate"
import {_, getProperty, Name} from "../../compile/codegen"
import {DiscrError, DiscrErrorObj} from "../discriminator/types"
import {resolveRef} from "../../compile"
import {resolveRef, SchemaEnv} from "../../compile"
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved

export type DiscriminatorError = DiscrErrorObj<DiscrError.Tag> | DiscrErrorObj<DiscrError.Mapping>

Expand Down Expand Up @@ -67,6 +67,9 @@ const def: CodeKeywordDefinition = {
let propSch
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved
if (sch?.["$ref"] && Object.keys(sch).length === 1) {
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved
epoberezkin marked this conversation as resolved.
Show resolved Hide resolved
sch = resolveRef.call(it.self, it.schemaEnv, it.baseId, sch?.["$ref"])
if (sch instanceof SchemaEnv) {
sch = sch.schema
}
propSch = sch?.properties?.[tagName]
if (typeof propSch != "object") {
throw new Error(
Expand Down