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:
@@ -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])]
|
||||
|
||||
Reference in New Issue
Block a user