Skip to content

Commit a7822fa

Browse files
fix(rulesets): exclude non-schema enum properties from duplicated-entry-in-enum rule (#2934)
* fix(rulesets): exclude non-schema enum properties from duplicated-entry-in-enum rule The duplicated-entry-in-enum rule was incorrectly firing on properties named 'enum' in contexts like discriminator mappings and example values, where 'enum' is a data field rather than a JSON Schema keyword. Narrow the JSONPath filter to only match when the 'enum' value is actually an array, which is the only valid form for a schema enum keyword. Fixes #2199 * chore: restore generated Arazzo validators bundle --------- Co-authored-by: Sebastian Legarraga <slegarraga@users.noreply.github.com> Co-authored-by: tomek-tursa-sb <100731230+tomek-tursa-sb@users.noreply.github.com>
1 parent 60c6c56 commit a7822fa

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

packages/rulesets/src/oas/__tests__/duplicated-entry-in-enum.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,57 @@ testRule('duplicated-entry-in-enum', [
105105
},
106106
],
107107
},
108+
109+
{
110+
name: 'oas3: enum as discriminator mapping key',
111+
document: {
112+
openapi: '3.0.2',
113+
components: {
114+
schemas: {
115+
Pet: {
116+
type: 'object',
117+
discriminator: {
118+
propertyName: 'petType',
119+
mapping: {
120+
enum: '#/components/schemas/Cat',
121+
},
122+
},
123+
},
124+
},
125+
},
126+
},
127+
errors: [],
128+
},
129+
130+
{
131+
name: 'oas3: enum as example value property',
132+
document: {
133+
openapi: '3.0.2',
134+
paths: {
135+
'/test': {
136+
get: {
137+
responses: {
138+
'200': {
139+
description: 'ok',
140+
content: {
141+
'application/json': {
142+
examples: {
143+
sample: {
144+
value: {
145+
foo: {
146+
enum: 'someString',
147+
},
148+
},
149+
},
150+
},
151+
},
152+
},
153+
},
154+
},
155+
},
156+
},
157+
},
158+
},
159+
errors: [],
160+
},
108161
]);

packages/rulesets/src/oas/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const ruleset = {
159159
severity: 'warn',
160160
recommended: true,
161161
message: '{{error}}',
162-
given: ["$..[?(@property !== 'properties' && @ && @.enum)]"],
162+
given: ["$..[?(@property !== 'properties' && @.enum && @.enum.constructor.name === 'Array')]"],
163163
then: {
164164
field: 'enum',
165165
function: oasSchema,

0 commit comments

Comments
 (0)