Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

isSubset is not correct #30

Open
tg44 opened this issue Mar 6, 2023 · 0 comments
Open

isSubset is not correct #30

tg44 opened this issue Mar 6, 2023 · 0 comments

Comments

@tg44
Copy link

tg44 commented Mar 6, 2023

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant