diff --git a/src/v1/validateJsonSchema.ts b/src/v1/validateJsonSchema.ts index f94dccc..9013545 100644 --- a/src/v1/validateJsonSchema.ts +++ b/src/v1/validateJsonSchema.ts @@ -262,8 +262,7 @@ const validateSchema = (validations: any, schema: any) => { // Clean up inactive choices if (isInactiveChoice(property)) { schema.schema.properties[key].enum = cleanUpInactiveEnumChoice(property); - - if (isEmpty(schema.schema.properties[key].enum.length)) { + if (isEmpty(schema.schema.properties[key].enum)) { schema.schema.properties[key].enum = ['0']; schema.schema.properties[key].enumNames = { 0: 'No Options' }; } diff --git a/test/JsonFormatter.test.tsx b/test/JsonFormatter.test.tsx index abf6b77..df338ce 100644 --- a/test/JsonFormatter.test.tsx +++ b/test/JsonFormatter.test.tsx @@ -78,6 +78,10 @@ describe("JSON Schema validation", () => { it("Validate remove inactive enum choices", () => { const validSchema = validateJSONSchema(JSON_SCHEMA_INACTIVE_CHOICES_FAKE_DATA); + expect(validSchema.schema.properties.invasivespecies_urgency.enum).toContain("unknown"); + // Before fixing this, it was generating the enum as ["0"]. This test makes sure that's not the case anymore. + expect(validSchema.schema.properties.invasivespecies_urgency.enum).not.toContain("0"); + // Verify the inactive option is not in the enum anymore expect(validSchema.schema.properties.invasivespecies_urgency.enum).not.toContain("test"); });