genson-js
genson-js copied to clipboard
isSubset is not correct
Given the two schemas;
const s1 = {
type: "object",
properties: { test1: { type: "string" }, test2: { type: "string" } },
required: ["test1"],
nullable: false,
additionalProperties: true,
}
const s2 = {
type: "object",
properties: { test1: { type: "string" }, test2: { type: "string" } },
required: ["test1", "test2"],
nullable: false,
additionalProperties: true,
}
s2 is more restrictive than s1, hence isSubset(s1, s2)
should be true.
If I merge up two schemas with noRequired, I will surely loose context. But if I use ignoreRequired
on the check it feels like I will loose context too...
Also;
export const isSubsetSchema = async (superset: any, subset: any) => {
return isSubset(superset, subset, { ignoreRequired: false });
};
describe("jsonSchemaGen", () => {
test("sanity", async () => {
const s1 = {
type: "object",
properties: { test: { type: "string" } },
required: ["test"],
nullable: false,
additionalProperties: false,
};
const s2 = {
type: "object",
properties: { test: { type: "string" } },
required: ["test"],
nullable: false,
additionalProperties: true,
};
expect(await isSubsetSchema(s2, s1)).toBeTruthy();
expect(await isSubsetSchema(s1, s2)).toBeFalsy();
});
test("sanity2", async () => {
const s1 = {
type: "object",
properties: { test: { type: "string" } },
required: ["test"],
nullable: true,
additionalProperties: true,
};
const s2 = {
type: "object",
properties: { test: { type: "string" } },
required: ["test"],
nullable: false,
additionalProperties: true,
};
expect(await isSubsetSchema(s2, s1)).toBeTruthy();
expect(await isSubsetSchema(s1, s2)).toBeFalsy();
});
});
These test are failing.
Is this repository accepts PRs, or it is dead or in low maintanance mode?