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

isSubset is not correct #30

@tg44

Description

@tg44

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions