Skip to content

Commit

Permalink
fix(rulesets): simplify schema used in duplicated-entry-in-enum (#2055)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored Feb 11, 2022
1 parent 7f2f5aa commit 8451774
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: [],
},
Expand Down
16 changes: 4 additions & 12 deletions packages/rulesets/src/oas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down

0 comments on commit 8451774

Please sign in to comment.