Skip to content

Commit

Permalink
Update JSON Schema object parsing logic to use new getDuplicatesOf ut…
Browse files Browse the repository at this point in the history
…il for improved error message upon duplicated 'required' keys
  • Loading branch information
TizzySaurus committed Nov 17, 2024
1 parent 9826c00 commit 5272e44
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ark/jsonschema/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type Predicate,
type TraversalContext
} from "@ark/schema"
import { conflatenateAll, printable } from "@ark/util"
import { conflatenateAll, getDuplicatesOf, printable } from "@ark/util"
import type { Out, Type } from "arktype"

import { parseJsonSchema } from "./json.ts"
Expand Down Expand Up @@ -138,11 +138,12 @@ const parseRequiredAndOptionalKeys = (
const requiredKeys: string[] = []
if ("properties" in jsonSchema) {
if ("required" in jsonSchema) {
if (jsonSchema.required.length !== new Set(jsonSchema.required).size) {
const duplicateRequiredKeys = getDuplicatesOf(jsonSchema.required)
if (duplicateRequiredKeys.length !== 0) {
ctx.reject({
path: ["required"],
expected: "an array of unique strings",
actual: printable(jsonSchema.required)
actual: `an array with the following duplicates: ${printable(duplicateRequiredKeys)}`
})
}

Expand Down

0 comments on commit 5272e44

Please sign in to comment.