Skip to content

Commit

Permalink
fix(oas): validate falsy examples (#1418)
Browse files Browse the repository at this point in the history
Co-authored-by: Phil Sturgeon <phil@stoplight.io>
  • Loading branch information
P0lip and Phil Sturgeon committed Jan 4, 2021
1 parent 8103153 commit c5678be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/rulesets/oas/__tests__/templates/_schema-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { setFunctionContext } from '../../../evaluators';
import { functions } from '../../../../functions';
import oasExample from '../../functions/oasExample';

const Decimal = require('decimal.js');

export default (ruleName: string, path: string) => {
let s: Spectral;

Expand Down Expand Up @@ -285,8 +287,8 @@ export default (ruleName: string, path: string) => {
['byte', 'MTI3'],
['int32', 2 ** 30],
['int64', 2 ** 40],
['float', 2 ** 64],
['double', 2 ** 1028],
['float', new Decimal(2).pow(128)],
['double', new Decimal(2).pow(1024)],
])('does not report valid usage of %s format', async (format, example) => {
const results = await s.run({
openapi: '3.0.2',
Expand Down
14 changes: 7 additions & 7 deletions src/rulesets/oas/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
"formats": ["oas2"],
"severity": 0,
"type": "validation",
"given": "$..parameters..[?(@property !== 'properties' && (@.example || @['x-example']) && (@.type || @.format || @.$ref || @.properties || @.items))]",
"given": "$..parameters..[?(@property !== 'properties' && (@.example !== void 0 || @['x-example'] !== void 0) && (@.type || @.format || @.$ref || @.properties || @.items))]",
"then": {
"function": "oasExample",
"functionOptions": {
Expand All @@ -434,7 +434,7 @@
"formats": ["oas2"],
"severity": 0,
"type": "validation",
"given": "$..definitions..[?(@property !== 'properties' && (@.example || @['x-example']) && (@.type || @.format || @.$ref || @.properties || @.items))]",
"given": "$..definitions..[?(@property !== 'properties' && (@.example !== void 0 || @['x-example'] !== void 0) && (@.type || @.format || @.$ref || @.properties || @.items))]",
"then": {
"function": "oasExample",
"functionOptions": {
Expand Down Expand Up @@ -468,7 +468,7 @@
"formats": ["oas2"],
"severity": 0,
"type": "validation",
"given": "$..responses..[?(@property !== 'properties' && (@.example || @['x-example']) && (@.type || @.format || @.$ref || @.properties || @.items))]",
"given": "$..responses..[?(@property !== 'properties' && (@.example !== void 0 || @['x-example'] !== void 0) && (@.type || @.format || @.$ref || @.properties || @.items))]",
"then": {
"function": "oasExample",
"functionOptions": {
Expand Down Expand Up @@ -682,7 +682,7 @@
"severity": 0,
"formats": ["oas3"],
"type": "validation",
"given": "$..parameters..[?(@property !== 'properties' && @.example && (@.type || @.format || @.$ref || @.properties || @.items))]",
"given": "$..parameters..[?(@property !== 'properties' && @.example !== void 0 && (@.type || @.format || @.$ref || @.properties || @.items))]",
"then": {
"function": "oasExample",
"functionOptions": {
Expand All @@ -699,7 +699,7 @@
"severity": 0,
"formats": ["oas3"],
"type": "validation",
"given": "$..headers..[?(@property !== 'properties' && @.example && (@.type || @.format || @.$ref || @.properties || @.items))]",
"given": "$..headers..[?(@property !== 'properties' && @.example !== void 0 && (@.type || @.format || @.$ref || @.properties || @.items))]",
"then": {
"function": "oasExample",
"functionOptions": {
Expand All @@ -717,8 +717,8 @@
"recommended": true,
"type": "validation",
"given": [
"$.components.schemas..[?(@property !== 'properties' && @.example && (@.type || @.format || @.$ref || @.properties || @.items))]",
"$..content..[?(@property !== 'properties' && @.example && (@.type || @.format || @.$ref || @.properties || @.items))]"
"$.components.schemas..[?(@property !== 'properties' && @.example !== void 0 && (@.type || @.format || @.$ref || @.properties || @.items))]",
"$..content..[?(@property !== 'properties' && @.example !== void 0 && (@.type || @.format || @.$ref || @.properties || @.items))]"
],
"then": {
"function": "oasExample",
Expand Down

0 comments on commit c5678be

Please sign in to comment.