Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,57 @@ testRule('duplicated-entry-in-enum', [
},
],
},

{
name: 'oas3: enum as discriminator mapping key',
document: {
openapi: '3.0.2',
components: {
schemas: {
Pet: {
type: 'object',
discriminator: {
propertyName: 'petType',
mapping: {
enum: '#/components/schemas/Cat',
},
},
},
},
},
},
errors: [],
},

{
name: 'oas3: enum as example value property',
document: {
openapi: '3.0.2',
paths: {
'/test': {
get: {
responses: {
'200': {
description: 'ok',
content: {
'application/json': {
examples: {
sample: {
value: {
foo: {
enum: 'someString',
},
},
},
},
},
},
},
},
},
},
},
},
errors: [],
},
]);
2 changes: 1 addition & 1 deletion packages/rulesets/src/oas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const ruleset = {
severity: 'warn',
recommended: true,
message: '{{error}}',
given: ["$..[?(@property !== 'properties' && @ && @.enum)]"],
given: ["$..[?(@property !== 'properties' && @.enum && @.enum.constructor.name === 'Array')]"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the @ && null guard removed on purpose? I believe I'm seeing crashes when nimma hits a null node.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:
$..[?(@property !== 'properties' && @ && @.enum && @.enum.constructor.name === 'Array')]

then: {
field: 'enum',
function: oasSchema,
Expand Down
Loading