feat(samples): add support for merging type keyword (#8916)

This change is specific to JSON Schema 2020-12
and OpenAPI 3.1.0.

Refs #8577
This commit is contained in:
Vladimír Gorej
2023-06-12 14:35:06 +02:00
committed by GitHub
parent a4f544ba6d
commit b593c50c7c

View File

@@ -1,6 +1,7 @@
/**
* @prettier
*/
import { normalizeArray as ensureArray } from "core/utils"
import { isBooleanJSONSchema, isJSONSchema } from "./predicates"
const merge = (target, source, config = {}) => {
@@ -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])]