From 8451774db0fb0b97ba41d631641c8bcc562771a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Fri, 11 Feb 2022 14:11:41 +0200 Subject: [PATCH] fix(rulesets): simplify schema used in duplicated-entry-in-enum (#2055) --- .../duplicated-entry-in-enum.test.ts | 43 ++++++++----------- packages/rulesets/src/oas/index.ts | 16 ++----- 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/packages/rulesets/src/oas/__tests__/duplicated-entry-in-enum.test.ts b/packages/rulesets/src/oas/__tests__/duplicated-entry-in-enum.test.ts index fc82db411..8e69150ab 100644 --- a/packages/rulesets/src/oas/__tests__/duplicated-entry-in-enum.test.ts +++ b/packages/rulesets/src/oas/__tests__/duplicated-entry-in-enum.test.ts @@ -24,30 +24,6 @@ testRule('duplicated-entry-in-enum', [ errors: [], }, - { - name: 'oas2: enum is an object property', - document: { - openapi: '3.0.2', - components: { - schemas: { - schema: { - type: 'object', - properties: { - enum: { - type: 'array', - items: { - type: 'string', - }, - }, - }, - }, - }, - }, - }, - - errors: [], - }, - { name: 'oas2: enum with duplicated entries', document: { @@ -70,9 +46,24 @@ testRule('duplicated-entry-in-enum', [ }, { - name: 'oas3: empty object', + name: 'oas3: enum is a property', document: { - openapi: '3.0.0', + openapi: '3.0.2', + components: { + schemas: { + schema: { + type: 'object', + properties: { + enum: { + type: 'array', + items: { + type: 'string', + }, + }, + }, + }, + }, + }, }, errors: [], }, diff --git a/packages/rulesets/src/oas/index.ts b/packages/rulesets/src/oas/index.ts index 66c8ea65f..6e7a4d4fe 100644 --- a/packages/rulesets/src/oas/index.ts +++ b/packages/rulesets/src/oas/index.ts @@ -123,22 +123,14 @@ const ruleset = { severity: 'warn', recommended: true, message: '{{error}}', - given: '$..enum', + given: ["$..[?(@property !== 'properties' && @ && @.enum)]"], then: { + field: 'enum', function: oasSchema, functionOptions: { schema: { - oneOf: [ - { - type: 'array', - uniqueItems: true, - }, - { - not: { - type: 'array', - }, - }, - ], + type: 'array', + uniqueItems: true, }, }, },