@redocly/openapi-core 1.0.0-beta.123 → 1.0.0-beta.125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bundle.d.ts +7 -12
- package/lib/config/config.js +9 -4
- package/lib/config/types.d.ts +5 -1
- package/lib/format/format.js +16 -7
- package/lib/rules/common/assertions/asserts.d.ts +6 -2
- package/lib/rules/common/assertions/asserts.js +30 -20
- package/lib/rules/common/assertions/utils.d.ts +8 -0
- package/lib/rules/common/assertions/utils.js +28 -34
- package/lib/rules/common/required-string-property-missing-min-length.d.ts +2 -0
- package/lib/rules/common/required-string-property-missing-min-length.js +37 -0
- package/lib/rules/oas2/index.d.ts +1 -0
- package/lib/rules/oas2/index.js +2 -0
- package/lib/rules/oas3/index.js +2 -0
- package/lib/types/redocly-yaml.js +1 -0
- package/package.json +1 -1
- package/src/bundle.ts +11 -2
- package/src/config/__tests__/__snapshots__/config.test.ts.snap +144 -0
- package/src/config/__tests__/config.test.ts +25 -0
- package/src/config/__tests__/fixtures/ingore-file.ts +8 -0
- package/src/config/config.ts +14 -4
- package/src/config/types.ts +4 -1
- package/src/format/format.ts +17 -6
- package/src/rules/common/assertions/__tests__/asserts.test.ts +264 -178
- package/src/rules/common/assertions/__tests__/index.test.ts +1 -1
- package/src/rules/common/assertions/__tests__/utils.test.ts +122 -1
- package/src/rules/common/assertions/asserts.ts +59 -28
- package/src/rules/common/assertions/utils.ts +46 -44
- package/src/rules/common/required-string-property-missing-min-length.ts +44 -0
- package/src/rules/oas2/index.ts +2 -0
- package/src/rules/oas3/index.ts +2 -0
- package/src/types/redocly-yaml.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`generation ignore object should generate config with absoluteUri for ignore 1`] = `
|
|
4
|
+
StyleguideConfig {
|
|
5
|
+
"_usedRules": Set {},
|
|
6
|
+
"_usedVersions": Set {},
|
|
7
|
+
"configFile": undefined,
|
|
8
|
+
"decorators": Object {
|
|
9
|
+
"oas2": Object {
|
|
10
|
+
"oas2": Object {},
|
|
11
|
+
"oas3_0": Object {},
|
|
12
|
+
"oas3_1": Object {},
|
|
13
|
+
},
|
|
14
|
+
"oas3_0": Object {
|
|
15
|
+
"oas2": Object {},
|
|
16
|
+
"oas3_0": Object {},
|
|
17
|
+
"oas3_1": Object {},
|
|
18
|
+
},
|
|
19
|
+
"oas3_1": Object {
|
|
20
|
+
"oas2": Object {},
|
|
21
|
+
"oas3_0": Object {},
|
|
22
|
+
"oas3_1": Object {},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
"doNotResolveExamples": false,
|
|
26
|
+
"extendPaths": Array [],
|
|
27
|
+
"ignore": Object {
|
|
28
|
+
"https://some-path.yaml": Object {
|
|
29
|
+
"no-unused-components": Set {
|
|
30
|
+
"#/components/schemas/Foo",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
"some-path/openapi.yaml": Object {
|
|
34
|
+
"no-unused-components": Set {
|
|
35
|
+
"#/components/schemas/Foo",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
"pluginPaths": Array [],
|
|
40
|
+
"plugins": Array [],
|
|
41
|
+
"preprocessors": Object {
|
|
42
|
+
"oas2": Object {
|
|
43
|
+
"oas2": Object {},
|
|
44
|
+
"oas3_0": Object {},
|
|
45
|
+
"oas3_1": Object {},
|
|
46
|
+
},
|
|
47
|
+
"oas3_0": Object {
|
|
48
|
+
"oas2": Object {},
|
|
49
|
+
"oas3_0": Object {},
|
|
50
|
+
"oas3_1": Object {},
|
|
51
|
+
},
|
|
52
|
+
"oas3_1": Object {
|
|
53
|
+
"oas2": Object {},
|
|
54
|
+
"oas3_0": Object {},
|
|
55
|
+
"oas3_1": Object {},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
"rawConfig": Object {
|
|
59
|
+
"_usedRules": Set {},
|
|
60
|
+
"_usedVersions": Set {},
|
|
61
|
+
"configFile": "redocly.yaml",
|
|
62
|
+
"decorators": Object {
|
|
63
|
+
"oas2": Object {},
|
|
64
|
+
"oas3_0": Object {},
|
|
65
|
+
"oas3_1": Object {},
|
|
66
|
+
},
|
|
67
|
+
"doNotResolveExamples": false,
|
|
68
|
+
"ignore": Object {},
|
|
69
|
+
"plugins": Array [],
|
|
70
|
+
"preprocessors": Object {
|
|
71
|
+
"oas2": Object {},
|
|
72
|
+
"oas3_0": Object {},
|
|
73
|
+
"oas3_1": Object {},
|
|
74
|
+
},
|
|
75
|
+
"rawConfig": Object {
|
|
76
|
+
"plugins": Array [],
|
|
77
|
+
"rules": Object {
|
|
78
|
+
"no-empty-servers": "error",
|
|
79
|
+
"operation-summary": "error",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
"recommendedFallback": false,
|
|
83
|
+
"rules": Object {
|
|
84
|
+
"oas2": Object {
|
|
85
|
+
"no-empty-servers": "error",
|
|
86
|
+
"operation-summary": "error",
|
|
87
|
+
},
|
|
88
|
+
"oas3_0": Object {
|
|
89
|
+
"no-empty-servers": "error",
|
|
90
|
+
"operation-summary": "error",
|
|
91
|
+
},
|
|
92
|
+
"oas3_1": Object {
|
|
93
|
+
"no-empty-servers": "error",
|
|
94
|
+
"operation-summary": "error",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
"recommendedFallback": false,
|
|
99
|
+
"rules": Object {
|
|
100
|
+
"oas2": Object {
|
|
101
|
+
"oas2": Object {
|
|
102
|
+
"no-empty-servers": "error",
|
|
103
|
+
"operation-summary": "error",
|
|
104
|
+
},
|
|
105
|
+
"oas3_0": Object {
|
|
106
|
+
"no-empty-servers": "error",
|
|
107
|
+
"operation-summary": "error",
|
|
108
|
+
},
|
|
109
|
+
"oas3_1": Object {
|
|
110
|
+
"no-empty-servers": "error",
|
|
111
|
+
"operation-summary": "error",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
"oas3_0": Object {
|
|
115
|
+
"oas2": Object {
|
|
116
|
+
"no-empty-servers": "error",
|
|
117
|
+
"operation-summary": "error",
|
|
118
|
+
},
|
|
119
|
+
"oas3_0": Object {
|
|
120
|
+
"no-empty-servers": "error",
|
|
121
|
+
"operation-summary": "error",
|
|
122
|
+
},
|
|
123
|
+
"oas3_1": Object {
|
|
124
|
+
"no-empty-servers": "error",
|
|
125
|
+
"operation-summary": "error",
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
"oas3_1": Object {
|
|
129
|
+
"oas2": Object {
|
|
130
|
+
"no-empty-servers": "error",
|
|
131
|
+
"operation-summary": "error",
|
|
132
|
+
},
|
|
133
|
+
"oas3_0": Object {
|
|
134
|
+
"no-empty-servers": "error",
|
|
135
|
+
"operation-summary": "error",
|
|
136
|
+
},
|
|
137
|
+
"oas3_1": Object {
|
|
138
|
+
"no-empty-servers": "error",
|
|
139
|
+
"operation-summary": "error",
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
`;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { OasVersion } from '../../oas-types';
|
|
2
2
|
import { Config, StyleguideConfig } from '../config';
|
|
3
3
|
import { getMergedConfig } from '../utils';
|
|
4
|
+
import { doesYamlFileExist } from '../../utils';
|
|
5
|
+
import { parseYaml } from '../../js-yaml';
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { ignoredFileStub } from './fixtures/ingore-file';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { NormalizedProblem } from '../../walk';
|
|
10
|
+
import { Source } from '../../resolve';
|
|
11
|
+
|
|
12
|
+
jest.mock('../../utils');
|
|
13
|
+
jest.mock('../../js-yaml');
|
|
14
|
+
jest.mock('fs');
|
|
4
15
|
|
|
5
16
|
const testConfig: Config = {
|
|
6
17
|
rawConfig: {
|
|
@@ -280,3 +291,17 @@ describe('StyleguideConfig.extendTypes', () => {
|
|
|
280
291
|
);
|
|
281
292
|
});
|
|
282
293
|
});
|
|
294
|
+
|
|
295
|
+
describe('generation ignore object', () => {
|
|
296
|
+
it('should generate config with absoluteUri for ignore', () => {
|
|
297
|
+
(readFileSync as jest.Mock<any, any>).mockImplementationOnce(() => '');
|
|
298
|
+
(parseYaml as jest.Mock<any, any>).mockImplementationOnce(() => ignoredFileStub);
|
|
299
|
+
(doesYamlFileExist as jest.Mock<any, any>).mockImplementationOnce(() => true);
|
|
300
|
+
|
|
301
|
+
jest.spyOn(path, 'resolve').mockImplementationOnce((_, filename) => `some-path/${filename}`);
|
|
302
|
+
|
|
303
|
+
const styleguideConfig = new StyleguideConfig(testConfig.styleguide);
|
|
304
|
+
|
|
305
|
+
expect(styleguideConfig).toMatchSnapshot();
|
|
306
|
+
});
|
|
307
|
+
});
|
package/src/config/config.ts
CHANGED
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
ThemeRawConfig,
|
|
22
22
|
} from './types';
|
|
23
23
|
import { getResolveConfig } from './utils';
|
|
24
|
+
import { isAbsoluteUrl } from '../ref-utils';
|
|
24
25
|
|
|
25
26
|
export const IGNORE_FILE = '.redocly.lint-ignore.yaml';
|
|
26
27
|
const IGNORE_BANNER =
|
|
@@ -115,11 +116,17 @@ export class StyleguideConfig {
|
|
|
115
116
|
|
|
116
117
|
// resolve ignore paths
|
|
117
118
|
for (const fileName of Object.keys(this.ignore)) {
|
|
118
|
-
this.ignore[
|
|
119
|
+
this.ignore[
|
|
120
|
+
isAbsoluteUrl(fileName) ? fileName : path.resolve(path.dirname(ignoreFile), fileName)
|
|
121
|
+
] = this.ignore[fileName];
|
|
122
|
+
|
|
119
123
|
for (const ruleId of Object.keys(this.ignore[fileName])) {
|
|
120
124
|
this.ignore[fileName][ruleId] = new Set(this.ignore[fileName][ruleId]);
|
|
121
125
|
}
|
|
122
|
-
|
|
126
|
+
|
|
127
|
+
if (!isAbsoluteUrl(fileName)) {
|
|
128
|
+
delete this.ignore[fileName];
|
|
129
|
+
}
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
132
|
|
|
@@ -128,8 +135,11 @@ export class StyleguideConfig {
|
|
|
128
135
|
const ignoreFile = path.join(dir, IGNORE_FILE);
|
|
129
136
|
const mapped: Record<string, any> = {};
|
|
130
137
|
for (const absFileName of Object.keys(this.ignore)) {
|
|
131
|
-
const
|
|
132
|
-
|
|
138
|
+
const mappedDefinitionName = isAbsoluteUrl(absFileName)
|
|
139
|
+
? absFileName
|
|
140
|
+
: slash(path.relative(dir, absFileName));
|
|
141
|
+
const ignoredRules = (mapped[mappedDefinitionName] = this.ignore[absFileName]);
|
|
142
|
+
|
|
133
143
|
for (const ruleId of Object.keys(ignoredRules)) {
|
|
134
144
|
ignoredRules[ruleId] = Array.from(ignoredRules[ruleId]) as any;
|
|
135
145
|
}
|
package/src/config/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProblemSeverity } from '../walk';
|
|
1
|
+
import type { ProblemSeverity, UserContext } from '../walk';
|
|
2
2
|
import type {
|
|
3
3
|
Oas3PreprocessorsSet,
|
|
4
4
|
OasMajorVersion,
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
} from '../oas-types';
|
|
12
12
|
import type { NodeType } from '../types';
|
|
13
13
|
import { Location } from '../ref-utils';
|
|
14
|
+
import { SkipFunctionContext } from '../visitors';
|
|
14
15
|
|
|
15
16
|
export type RuleSeverity = ProblemSeverity | 'off';
|
|
16
17
|
|
|
@@ -86,6 +87,8 @@ export type CustomRulesConfig = {
|
|
|
86
87
|
oas2?: Oas2RuleSet;
|
|
87
88
|
};
|
|
88
89
|
|
|
90
|
+
export type AssertionContext = Partial<UserContext> & SkipFunctionContext & { node: any };
|
|
91
|
+
|
|
89
92
|
export type AssertResult = { message?: string; location?: Location };
|
|
90
93
|
export type CustomFunction = (
|
|
91
94
|
value: any,
|
package/src/format/format.ts
CHANGED
|
@@ -7,6 +7,7 @@ const coreVersion = require('../../package.json').version;
|
|
|
7
7
|
import { NormalizedProblem, ProblemSeverity, LineColLocationObject, LocationObject } from '../walk';
|
|
8
8
|
import { getCodeframe, getLineColLocation } from './codeframes';
|
|
9
9
|
import { env } from '../env';
|
|
10
|
+
import { isAbsoluteUrl } from '../ref-utils';
|
|
10
11
|
|
|
11
12
|
export type Totals = {
|
|
12
13
|
errors: number;
|
|
@@ -120,7 +121,7 @@ export function formatProblems(
|
|
|
120
121
|
for (const [file, { ruleIdPad, locationPad: positionPad, fileProblems }] of Object.entries(
|
|
121
122
|
groupedByFile
|
|
122
123
|
)) {
|
|
123
|
-
logger.info(`${colorize.blue(path.relative(cwd, file))}:\n`);
|
|
124
|
+
logger.info(`${colorize.blue(isAbsoluteUrl(file) ? file : path.relative(cwd, file))}:\n`);
|
|
124
125
|
|
|
125
126
|
for (let i = 0; i < fileProblems.length; i++) {
|
|
126
127
|
const problem = fileProblems[i];
|
|
@@ -138,7 +139,9 @@ export function formatProblems(
|
|
|
138
139
|
output.write('<checkstyle version="4.3">\n');
|
|
139
140
|
|
|
140
141
|
for (const [file, { fileProblems }] of Object.entries(groupedByFile)) {
|
|
141
|
-
output.write(
|
|
142
|
+
output.write(
|
|
143
|
+
`<file name="${xmlEscape(isAbsoluteUrl(file) ? file : path.relative(cwd, file))}">\n`
|
|
144
|
+
);
|
|
142
145
|
fileProblems.forEach(formatCheckstyle);
|
|
143
146
|
output.write(`</file>\n`);
|
|
144
147
|
}
|
|
@@ -169,7 +172,9 @@ export function formatProblems(
|
|
|
169
172
|
return {
|
|
170
173
|
description: p.message,
|
|
171
174
|
location: {
|
|
172
|
-
path:
|
|
175
|
+
path: isAbsoluteUrl(location.source.absoluteRef)
|
|
176
|
+
? location.source.absoluteRef
|
|
177
|
+
: path.relative(cwd, location.source.absoluteRef),
|
|
173
178
|
lines: {
|
|
174
179
|
begin: lineCol.start.line,
|
|
175
180
|
},
|
|
@@ -191,14 +196,18 @@ export function formatProblems(
|
|
|
191
196
|
location: p.location.map((location: any) => ({
|
|
192
197
|
...location,
|
|
193
198
|
source: {
|
|
194
|
-
ref:
|
|
199
|
+
ref: isAbsoluteUrl(location.source.absoluteRef)
|
|
200
|
+
? location.source.absoluteRef
|
|
201
|
+
: path.relative(cwd, location.source.absoluteRef),
|
|
195
202
|
},
|
|
196
203
|
})),
|
|
197
204
|
from: p.from
|
|
198
205
|
? {
|
|
199
206
|
...p.from,
|
|
200
207
|
source: {
|
|
201
|
-
ref:
|
|
208
|
+
ref: isAbsoluteUrl(p.from?.source.absoluteRef)
|
|
209
|
+
? p.from?.source.absoluteRef
|
|
210
|
+
: path.relative(cwd, p.from?.source.absoluteRef || cwd),
|
|
202
211
|
},
|
|
203
212
|
}
|
|
204
213
|
: undefined,
|
|
@@ -226,7 +235,9 @@ export function formatProblems(
|
|
|
226
235
|
function formatCodeframe(problem: NormalizedProblem, idx: number) {
|
|
227
236
|
const bgColor = getBgColor(problem);
|
|
228
237
|
const location = problem.location[0]; // TODO: support multiple locations
|
|
229
|
-
const relativePath =
|
|
238
|
+
const relativePath = isAbsoluteUrl(location.source.absoluteRef)
|
|
239
|
+
? location.source.absoluteRef
|
|
240
|
+
: path.relative(cwd, location.source.absoluteRef);
|
|
230
241
|
const loc = getLineColLocation(location);
|
|
231
242
|
const atPointer = location.pointer ? colorize.gray(`at ${location.pointer}`) : '';
|
|
232
243
|
const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
|