Skip to content

Commit e0d614d

Browse files
authored
Merge pull request #21 from PADAS/bug/EM-1799-fix-inactive-enum-choices
fix(EM-1799): drop just inactive enum choices
2 parents 59ac009 + f44bfa7 commit e0d614d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/v1/validateJsonSchema.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ const validateSchema = (validations: any, schema: any) => {
262262
// Clean up inactive choices
263263
if (isInactiveChoice(property)) {
264264
schema.schema.properties[key].enum = cleanUpInactiveEnumChoice(property);
265-
266-
if (isEmpty(schema.schema.properties[key].enum.length)) {
265+
if (isEmpty(schema.schema.properties[key].enum)) {
267266
schema.schema.properties[key].enum = ['0'];
268267
schema.schema.properties[key].enumNames = { 0: 'No Options' };
269268
}

test/JsonFormatter.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ describe("JSON Schema validation", () => {
7878

7979
it("Validate remove inactive enum choices", () => {
8080
const validSchema = validateJSONSchema(JSON_SCHEMA_INACTIVE_CHOICES_FAKE_DATA);
81+
expect(validSchema.schema.properties.invasivespecies_urgency.enum).toContain("unknown");
82+
// Before fixing this, it was generating the enum as ["0"]. This test makes sure that's not the case anymore.
83+
expect(validSchema.schema.properties.invasivespecies_urgency.enum).not.toContain("0");
84+
// Verify the inactive option is not in the enum anymore
8185
expect(validSchema.schema.properties.invasivespecies_urgency.enum).not.toContain("test");
8286
});
8387

0 commit comments

Comments
 (0)