Skip to content

Commit

Permalink
feat(samples): add support for merging type keyword
Browse files Browse the repository at this point in the history
This change is specific to JSON Schema 2020-12
and OpenAPI 3.1.0.

Refs #8577
  • Loading branch information
char0n committed Jun 12, 2023
1 parent a4f544b commit df2fbb2
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @prettier
*/
import { normalizeArray as ensureArray } from "core/utils"
import { isBooleanJSONSchema, isJSONSchema } from "./predicates"

const merge = (target, source, config = {}) => {
Expand All @@ -18,6 +19,14 @@ const merge = (target, source, config = {}) => {
*/
const merged = { ...source, ...target }

// merging the type keyword
if (source.type && target.type) {
if (Array.isArray(source.type) && typeof source.type === "string") {
const mergedType = ensureArray(source.type).concat(target.type)
merged.type = Array.from(new Set(mergedType))
}
}

// merging required keyword
if (Array.isArray(source.required) && Array.isArray(target.required)) {
merged.required = [...new Set([...target.required, ...source.required])]
Expand Down

0 comments on commit df2fbb2

Please sign in to comment.