Skip to content

Commit

Permalink
Merge branch 'master' into chore/v1.0.0-beta.107
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorKarpiuk authored Aug 16, 2022
2 parents 14a8d29 + 32a876b commit 3e19194
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 11 deletions.
13 changes: 13 additions & 0 deletions __tests__/lint/assertions-non-empty-off/.redocly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apis:
main:
root: ./openapi.yaml

styleguide:
rules:
assert/summary-non-empty:
subject: Operation
property: summary
message: Operation summary should not be empty
nonEmpty: true
severity: off
extends: []
29 changes: 29 additions & 0 deletions __tests__/lint/assertions-non-empty-off/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: 3.1.0
servers:
- url: http://example.xyz
info:
license:
name: test licence
url: http://example.xyz
title: Example OpenAPI 3 definition.
description: Example description
version: '1.0'
contact:
name: qa
url: https://swagger.io/specification/#definitions
email: email@redoc.ly

paths:
/pet/findByStatus:
get:
operationId: example
summary:
tags:
- foo
- baz
- bar
responses:
'200':
description: example description
'404':
description: example description
11 changes: 11 additions & 0 deletions __tests__/lint/assertions-non-empty-off/snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint assertions-non-empty-off 1`] = `
validating /openapi.yaml...
/openapi.yaml: validated in <test>ms
Woohoo! Your OpenAPI definition is valid. 🎉
`;
13 changes: 13 additions & 0 deletions __tests__/lint/assertions-non-empty-warn/.redocly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apis:
main:
root: ./openapi.yaml

styleguide:
rules:
assert/summary-non-empty:
subject: Operation
property: summary
message: Operation summary should not be empty
nonEmpty: true
severity: warn
extends: []
29 changes: 29 additions & 0 deletions __tests__/lint/assertions-non-empty-warn/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: 3.1.0
servers:
- url: http://example.xyz
info:
license:
name: test licence
url: http://example.xyz
title: Example OpenAPI 3 definition.
description: Example description
version: '1.0'
contact:
name: qa
url: https://swagger.io/specification/#definitions
email: email@redoc.ly

paths:
/pet/findByStatus:
get:
operationId: example
summary:
tags:
- foo
- baz
- bar
responses:
'200':
description: example description
'404':
description: example description
26 changes: 26 additions & 0 deletions __tests__/lint/assertions-non-empty-warn/snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint assertions-non-empty-warn 1`] = `
validating /openapi.yaml...
[1] openapi.yaml:20:7 at #/paths/~1pet~1findByStatus/get/summary
Operation summary should not be empty
18 | get:
19 | operationId: example
20 | summary:
| ^^^^^^^^
21 | tags:
22 | - foo
Warning was generated by the summary-non-empty assertion rule.
/openapi.yaml: validated in <test>ms
Woohoo! Your OpenAPI definition is valid. 🎉
You have 1 warning.
`;
26 changes: 15 additions & 11 deletions packages/core/src/walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
import { pushStack, popStack } from './utils';
import { OasVersion } from './oas-types';
import { NormalizedNodeType, isNamedType } from './types';
import type { RuleSeverity } from './config';

type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;

export type ResolveResult<T extends NonUndefined> =
Expand Down Expand Up @@ -66,7 +68,7 @@ export type Problem = {
suggest?: string[];
location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
from?: LocationObject;
forceSeverity?: ProblemSeverity;
forceSeverity?: RuleSeverity;
ruleId?: string;
};

Expand Down Expand Up @@ -409,17 +411,19 @@ export function walkDocument<T>(opts: {
: [opts.location]
: [{ ...currentLocation, reportOnKey: false }];

ctx.problems.push({
ruleId: opts.ruleId || ruleId,
severity: opts.forceSeverity || severity,
...opts,
suggest: opts.suggest || [],
location: loc.map((loc: any) => {
return { ...currentLocation, reportOnKey: false, ...loc };
}),
});
const ruleSeverity = opts.forceSeverity || severity;
if (ruleSeverity !== 'off') {
ctx.problems.push({
ruleId: opts.ruleId || ruleId,
severity: ruleSeverity,
...opts,
suggest: opts.suggest || [],
location: loc.map((loc: any) => {
return { ...currentLocation, reportOnKey: false, ...loc };
}),
});
}
}

function getVisitorDataFn(ruleId: string) {
ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
return ctx.visitorsData[ruleId];
Expand Down

0 comments on commit 3e19194

Please sign in to comment.