Skip to content

Commit

Permalink
use 'property' instead of 'tag' in error message. According to OAS3 d…
Browse files Browse the repository at this point in the history
…iscriminator is a keyword which points to a property, but never a tag.
  • Loading branch information
Adrian Hoehn committed May 2, 2023
1 parent 5f41b74 commit 0980a57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 15 additions & 3 deletions lib/compile/validate/index.ts
@@ -1,4 +1,10 @@
import type {AddedKeywordDefinition, AnySchema, AnySchemaObject, KeywordCxtParams, KeywordErrorCxt,} from "../../types"
import type {
AddedKeywordDefinition,
AnySchema,
AnySchemaObject,
KeywordCxtParams,
KeywordErrorCxt,
} from "../../types"
import type {SchemaCxt, SchemaObjCxt} from ".."
import type {InstanceOptions} from "../../core"
import {boolOrEmptySchema, topBoolOrEmptySchema} from "./boolSchema"
Expand All @@ -8,7 +14,7 @@ import {
coerceAndCheckDataType,
DataType,
getSchemaTypes,
reportTypeError
reportTypeError,
} from "./dataType"
import {shouldUseGroup, shouldUseRule} from "./applicability"
import {assignDefaults} from "./defaults"
Expand All @@ -26,7 +32,13 @@ import {
unescapeJsonPointer,
} from "../util"
import type {JSONType, Rule, RuleGroup} from "../rules"
import {ErrorPaths, keyword$DataError, reportError, reportExtraError, resetErrorsCount,} from "../errors"
import {
ErrorPaths,
keyword$DataError,
reportError,
reportExtraError,
resetErrorsCount,
} from "../errors"
import {strictDiscriminatorValidation} from "../../vocabularies/discriminator"

// schema compilation - generates validation function, subschemaCode (below) is used for subschemas
Expand Down
6 changes: 3 additions & 3 deletions lib/vocabularies/discriminator/index.ts
Expand Up @@ -10,10 +10,10 @@ export type DiscriminatorError = DiscrErrorObj<DiscrError.Tag> | DiscrErrorObj<D
const error: KeywordErrorDefinition = {
message: ({params: {discrError, tagName}}) =>
discrError === DiscrError.Tag
? `tag "${tagName}" must be string`
: `value of tag "${tagName}" must be in oneOf`,
? `property "${tagName}" must be string`
: `value of property "${tagName}" must be in oneOf`,
params: ({params: {discrError, tag, tagName}}) =>
_`{error: ${discrError}, tag: ${tagName}, tagValue: ${tag}}`,
_`{error: ${discrError}, property: ${tagName}, propertyValue: ${tag}}`,
}

const def: CodeKeywordDefinition = {
Expand Down

0 comments on commit 0980a57

Please sign in to comment.