Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(json-schema-2020-12-samples): skip anyOf and oneOf while merging schemas #9853

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/core/plugins/json-schema-2020-12-samples/fn/core/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ const merge = (target, source, config = {}) => {
*/
const merged = { ...source, ...target }

if (source["anyOf"] && !target["anyOf"]) {
delete merged["anyOf"]
}

if (source["oneOf"] && !target["oneOf"]) {
delete merged["oneOf"]
}

// merging the type keyword
if (source.type && target.type) {
if (Array.isArray(source.type) && typeof source.type === "string") {
Expand Down
43 changes: 43 additions & 0 deletions test/unit/core/plugins/json-schema-2020-12-samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3035,4 +3035,47 @@ describe("merge", function () {
required: ["username", "name"],
})
})

it("should skip `oneOf` from the source schema", function () {
const schema = {
oneOf: {
user: {
type: "object",
properties: {
name: {
type: "string",
},
},
},
order: {
type: "object",
properties: {
id: {
type: "string",
},
},
},
},
}

const target = {
type: "object",
properties: {
name: {
type: "string",
},
},
}

const result = mergeJsonSchema(target, schema)

expect(result).toStrictEqual({
type: "object",
properties: {
name: {
type: "string",
},
},
})
})
})