feat(plugins): expose JSON Schema merging mechanism from samples plugins (#9766)
Refs #9765
This commit is contained in:
@@ -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"],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { fromJS } from "immutable"
|
||||
import { createXMLExample, sampleFromSchema, memoizedCreateXMLExample, memoizedSampleFromSchema } from "core/plugins/json-schema-5-samples/fn/index"
|
||||
import {
|
||||
createXMLExample,
|
||||
sampleFromSchema,
|
||||
memoizedCreateXMLExample,
|
||||
memoizedSampleFromSchema,
|
||||
mergeJsonSchema,
|
||||
} from "core/plugins/json-schema-5-samples/fn/index"
|
||||
|
||||
describe("sampleFromSchema", () => {
|
||||
it("handles Immutable.js objects for nested schemas", function () {
|
||||
@@ -2438,3 +2444,55 @@ describe("memoizedCreateXMLExample", () => {
|
||||
expect(memoizedCreateXMLExample(definition, {}, updatedOverrideExample)).toEqual(updatedExpected)
|
||||
})
|
||||
})
|
||||
|
||||
describe("mergeJsonSchema", 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"],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user