Skip to content

Commit

Permalink
fix: use correct documentation urls (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored Nov 20, 2020
1 parent e03245d commit 797b19e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/rulesets/__tests__/reader.jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('Rulesets reader', () => {
oasRules[name] = {
...rule,
formats: expect.arrayContaining([expect.any(String)]),
documentationUrl: 'https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/reference/openapi-rules.md',
documentationUrl: `https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md#${name}`,
...(rule.severity === void 0 && { severity: DiagnosticSeverity.Warning }),
...(rule.recommended === void 0 && { recommended: true }),
then: expect.any(Object),
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('Rulesets reader', () => {
rules[name] = {
...rule,
formats: expect.arrayContaining([expect.any(String)]),
documentationUrl: 'https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/reference/openapi-rules.md',
documentationUrl: `https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md#${name}`,
...(rule.severity === undefined && { severity: DiagnosticSeverity.Warning }),
...(rule.recommended === false && { severity: -1 }),
...(rule.recommended === void 0 && { recommended: true }),
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('Rulesets reader', () => {
const formattedRule: IRule = {
...rule,
formats: expect.arrayContaining([expect.any(String)]),
documentationUrl: 'https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/reference/openapi-rules.md',
documentationUrl: `https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md#${name}`,
...(rule.severity === void 0 && { severity: DiagnosticSeverity.Warning }),
...(rule.recommended === false && { severity: -1 }),
...(rule.recommended === void 0 && { recommended: true }),
Expand Down Expand Up @@ -301,7 +301,7 @@ describe('Rulesets reader', () => {
'rules.operation-success-response',
{
description: 'should be overridden',
documentationUrl: 'https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/reference/openapi-rules.md',
documentationUrl: `https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md#operation-success-response`,
given: '$.info',
formats: expect.arrayContaining([expect.any(String)]),
recommended: true,
Expand All @@ -312,7 +312,7 @@ describe('Rulesets reader', () => {
);
});

it('should persist disabled properties of extended rulesets', () => {
it('should persist disabled properties of extended rulesets', async () => {
return expect(readRuleset(extendsOasWithOverrideRuleset)).resolves.toHaveProperty(
'rules.oas2-operation-security-defined',
{
Expand All @@ -321,7 +321,8 @@ describe('Rulesets reader', () => {
formats: expect.arrayContaining([expect.any(String)]),
severity: -1,
description: 'Operation `security` values must match a scheme defined in the `securityDefinitions` object.',
documentationUrl: 'https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/reference/openapi-rules.md',
documentationUrl:
'https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md#oas2-operation-security-defined',
then: expect.any(Object),
type: 'validation',
},
Expand Down Expand Up @@ -944,7 +945,8 @@ describe('Rulesets reader', () => {

expect(ruleset.rules).toStrictEqual({
'foo-rule': {
documentationUrl: 'https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/reference/openapi-rules.md',
documentationUrl:
'https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/reference/openapi-rules.md#foo-rule',
given: '',
recommended: true,
severity: DiagnosticSeverity.Warning,
Expand Down
2 changes: 1 addition & 1 deletion src/rulesets/asyncapi/index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"documentationUrl": "https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/reference/asyncapi-rules.md",
"documentationUrl": "https://meta.stoplight.io/docs/spectral/docs/reference/asyncapi-rules.md",
"formats": ["asyncapi2"],
"functions": ["asyncApi2PayloadValidation"],
"rules": {
Expand Down
2 changes: 1 addition & 1 deletion src/rulesets/oas/index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"documentationUrl": "https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/reference/openapi-rules.md",
"documentationUrl": "https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md",
"formats": ["oas2", "oas3"],
"functions": [
"oasDocumentSchema",
Expand Down
4 changes: 2 additions & 2 deletions src/rulesets/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ const createRulesetProcessor = (
mergeRules(rules, ruleset.rules, severity === void 0 ? 'recommended' : severity);

if (ruleset.documentationUrl !== void 0) {
for (const rule of Object.values(ruleset.rules)) {
for (const [name, rule] of Object.entries(ruleset.rules)) {
if (isValidRule(rule) && rule.documentationUrl === void 0) {
rule.documentationUrl = ruleset.documentationUrl;
rule.documentationUrl = `${ruleset.documentationUrl}#${name}`;
}
}
}
Expand Down

0 comments on commit 797b19e

Please sign in to comment.