feat(plugins): expose JSON Schema merging mechanism from samples plugins (#9766)

Refs #9765
This commit is contained in:
Oliwia Rogala
2024-03-29 12:56:20 +01:00
committed by GitHub
parent c0e3eb63d0
commit 6a493fb4f3
7 changed files with 148 additions and 28 deletions

View File

@@ -8,6 +8,7 @@ import {
sampleFromSchema,
memoizedCreateXMLExample,
memoizedSampleFromSchema,
mergeJsonSchema,
} from "core/plugins/json-schema-2020-12-samples/fn"
describe("sampleFromSchema", () => {
@@ -2983,3 +2984,55 @@ describe("memoizedCreateXMLExample", () => {
).toEqual(updatedExpected)
})
})
describe("merge", function () {
it("should merge two schemas", function () {
const schema = {
properties: {
name: {
type: "string",
},
id: {
type: "integer",
},
},
example: {
name: "test",
id: 1,
},
required: ["name"],
}
const target = {
type: "object",
properties: {
username: {
type: "string",
},
},
required: ["username"],
}
const result = mergeJsonSchema(target, schema)
expect(result).toStrictEqual({
type: "object",
properties: {
username: {
type: "string",
},
name: {
type: "string",
},
id: {
type: "integer",
},
},
example: {
name: "test",
id: 1,
},
required: ["username", "name"],
})
})
})