@redocly/openapi-core 1.0.0-beta.108 → 1.0.0-beta.110
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/README.md +2 -2
- package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +4 -4
- package/lib/config/all.js +3 -1
- package/lib/config/config-resolvers.js +22 -4
- package/lib/config/config.d.ts +1 -0
- package/lib/config/config.js +1 -0
- package/lib/config/load.d.ts +8 -2
- package/lib/config/load.js +4 -2
- package/lib/config/minimal.js +3 -1
- package/lib/config/recommended.js +3 -1
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +17 -0
- package/lib/config/utils.d.ts +2 -2
- package/lib/config/utils.js +44 -6
- package/lib/decorators/common/registry-dependencies.js +1 -1
- package/lib/format/format.d.ts +1 -1
- package/lib/format/format.js +22 -1
- package/lib/lint.js +2 -2
- package/lib/redocly/registry-api.d.ts +0 -1
- package/lib/redocly/registry-api.js +5 -4
- package/lib/resolve.js +3 -1
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +5 -5
- package/lib/rules/common/assertions/asserts.d.ts +3 -5
- package/lib/rules/common/assertions/asserts.js +137 -97
- package/lib/rules/common/assertions/index.js +2 -6
- package/lib/rules/common/assertions/utils.d.ts +12 -6
- package/lib/rules/common/assertions/utils.js +33 -20
- package/lib/rules/common/no-ambiguous-paths.js +1 -1
- package/lib/rules/common/no-identical-paths.js +1 -1
- package/lib/rules/common/operation-2xx-response.js +1 -1
- package/lib/rules/common/operation-4xx-response.js +1 -1
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/operation-tag-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/{operation-security-defined.js → security-defined.js} +18 -4
- package/lib/rules/common/spec.js +12 -1
- package/lib/rules/common/tags-alphabetical.js +1 -1
- package/lib/rules/oas2/index.d.ts +1 -1
- package/lib/rules/oas2/index.js +2 -2
- package/lib/rules/oas2/remove-unused-components.js +1 -1
- package/lib/rules/oas2/request-mime-type.js +1 -1
- package/lib/rules/oas2/response-mime-type.js +1 -1
- package/lib/rules/oas3/index.js +6 -2
- package/lib/rules/oas3/no-empty-servers.js +1 -1
- package/lib/rules/oas3/no-server-variables-empty-enum.js +1 -1
- package/lib/rules/oas3/no-unused-components.js +1 -1
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
- package/lib/rules/oas3/remove-unused-components.js +1 -1
- package/lib/rules/oas3/request-mime-type.js +1 -1
- package/lib/rules/oas3/response-mime-type.js +1 -1
- package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
- package/lib/rules/other/stats.d.ts +2 -2
- package/lib/rules/other/stats.js +2 -2
- package/lib/rules/utils.js +1 -1
- package/lib/types/oas2.js +5 -5
- package/lib/types/oas3.js +27 -20
- package/lib/types/oas3_1.js +3 -3
- package/lib/types/redocly-yaml.js +60 -54
- package/lib/utils.d.ts +3 -3
- package/lib/utils.js +5 -5
- package/lib/visitors.d.ts +11 -11
- package/lib/visitors.js +13 -1
- package/package.json +3 -5
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +3 -3
- package/src/__tests__/fixtures/extension.js +3 -3
- package/src/__tests__/format.test.ts +76 -0
- package/src/__tests__/lint.test.ts +184 -121
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +9 -9
- package/src/__tests__/walk.test.ts +78 -10
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/bundle.ts +4 -4
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +6 -2
- package/src/config/__tests__/config-resolvers.test.ts +37 -1
- package/src/config/__tests__/config.test.ts +5 -0
- package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
- package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +16 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +16 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +11 -0
- package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
- package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
- package/src/config/__tests__/load.test.ts +13 -16
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +64 -4
- package/src/config/all.ts +3 -1
- package/src/config/config-resolvers.ts +30 -7
- package/src/config/config.ts +2 -0
- package/src/config/load.ts +13 -6
- package/src/config/minimal.ts +3 -1
- package/src/config/recommended.ts +3 -1
- package/src/config/rules.ts +2 -2
- package/src/config/types.ts +24 -0
- package/src/config/utils.ts +103 -13
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/format/format.ts +32 -2
- package/src/lint.ts +2 -2
- package/src/redocly/registry-api.ts +5 -4
- package/src/resolve.ts +3 -1
- package/src/rules/__tests__/utils.test.ts +1 -1
- package/src/rules/ajv.ts +4 -4
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
- package/src/rules/common/__tests__/security-defined.test.ts +175 -0
- package/src/rules/common/__tests__/spec.test.ts +79 -0
- package/src/rules/common/assertions/__tests__/asserts.test.ts +491 -428
- package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
- package/src/rules/common/assertions/asserts.ts +155 -97
- package/src/rules/common/assertions/index.ts +2 -11
- package/src/rules/common/assertions/utils.ts +66 -36
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-identical-paths.ts +1 -1
- package/src/rules/common/operation-2xx-response.ts +1 -1
- package/src/rules/common/operation-4xx-response.ts +1 -1
- package/src/rules/common/operation-operationId.ts +1 -1
- package/src/rules/common/operation-tag-defined.ts +1 -1
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +19 -4
- package/src/rules/common/spec.ts +15 -1
- package/src/rules/common/tags-alphabetical.ts +1 -1
- package/src/rules/oas2/index.ts +2 -2
- package/src/rules/oas2/remove-unused-components.ts +1 -1
- package/src/rules/oas2/request-mime-type.ts +1 -1
- package/src/rules/oas2/response-mime-type.ts +1 -1
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +51 -2
- package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
- package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
- package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
- package/src/rules/oas3/index.ts +6 -2
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-server-variables-empty-enum.ts +1 -1
- package/src/rules/oas3/no-unused-components.ts +1 -1
- package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
- package/src/rules/oas3/remove-unused-components.ts +1 -1
- package/src/rules/oas3/request-mime-type.ts +1 -1
- package/src/rules/oas3/response-mime-type.ts +1 -1
- package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
- package/src/rules/other/stats.ts +2 -2
- package/src/rules/utils.ts +2 -1
- package/src/types/index.ts +2 -2
- package/src/types/oas2.ts +5 -5
- package/src/types/oas3.ts +27 -20
- package/src/types/oas3_1.ts +3 -3
- package/src/types/redocly-yaml.ts +66 -38
- package/src/utils.ts +11 -7
- package/src/visitors.ts +29 -13
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/operation-security-defined.d.ts +0 -2
- package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
import { lintDocument } from '../../../lint';
|
|
3
|
+
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
|
|
4
|
+
import { BaseResolver } from '../../../resolve';
|
|
5
|
+
|
|
6
|
+
describe('Oas3 security-defined', () => {
|
|
7
|
+
it('should report on securityRequirements object if security scheme is not defined in components', async () => {
|
|
8
|
+
const document = parseYamlToDocument(
|
|
9
|
+
outdent`
|
|
10
|
+
openapi: 3.0.0
|
|
11
|
+
paths:
|
|
12
|
+
/pets:
|
|
13
|
+
get:
|
|
14
|
+
security:
|
|
15
|
+
- some: []`,
|
|
16
|
+
'foobar.yaml'
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const results = await lintDocument({
|
|
20
|
+
externalRefResolver: new BaseResolver(),
|
|
21
|
+
document,
|
|
22
|
+
config: await makeConfig({ 'security-defined': 'error' }),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
26
|
+
Array [
|
|
27
|
+
Object {
|
|
28
|
+
"location": Array [
|
|
29
|
+
Object {
|
|
30
|
+
"pointer": "#/paths/~1pets/get/security/0/some",
|
|
31
|
+
"reportOnKey": true,
|
|
32
|
+
"source": "foobar.yaml",
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
"message": "There is no \`some\` security scheme defined.",
|
|
36
|
+
"ruleId": "security-defined",
|
|
37
|
+
"severity": "error",
|
|
38
|
+
"suggest": Array [],
|
|
39
|
+
},
|
|
40
|
+
]
|
|
41
|
+
`);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should not report if security defined with an empty array', async () => {
|
|
45
|
+
const document = parseYamlToDocument(
|
|
46
|
+
outdent`
|
|
47
|
+
openapi: 3.0.0
|
|
48
|
+
security: []
|
|
49
|
+
paths:`,
|
|
50
|
+
'foobar.yaml'
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const results = await lintDocument({
|
|
54
|
+
externalRefResolver: new BaseResolver(),
|
|
55
|
+
document,
|
|
56
|
+
config: await makeConfig({ 'security-defined': 'error' }),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should report if security not defined at all', async () => {
|
|
63
|
+
const document = parseYamlToDocument(
|
|
64
|
+
outdent`
|
|
65
|
+
openapi: 3.0.0
|
|
66
|
+
paths:
|
|
67
|
+
/pets:
|
|
68
|
+
get:
|
|
69
|
+
requestBody:`,
|
|
70
|
+
'foobar.yaml'
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const results = await lintDocument({
|
|
74
|
+
externalRefResolver: new BaseResolver(),
|
|
75
|
+
document,
|
|
76
|
+
config: await makeConfig({ 'security-defined': 'error' }),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
80
|
+
Array [
|
|
81
|
+
Object {
|
|
82
|
+
"location": Array [
|
|
83
|
+
Object {
|
|
84
|
+
"pointer": "#/",
|
|
85
|
+
"reportOnKey": false,
|
|
86
|
+
"source": "foobar.yaml",
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
"message": "Every API should have security defined on the root level or for each operation.",
|
|
90
|
+
"ruleId": "security-defined",
|
|
91
|
+
"severity": "error",
|
|
92
|
+
"suggest": Array [],
|
|
93
|
+
},
|
|
94
|
+
]
|
|
95
|
+
`);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should report if security not defined for each operation', async () => {
|
|
99
|
+
const document = parseYamlToDocument(
|
|
100
|
+
outdent`
|
|
101
|
+
openapi: 3.0.0
|
|
102
|
+
paths:
|
|
103
|
+
/pets:
|
|
104
|
+
get:
|
|
105
|
+
security:
|
|
106
|
+
- some: []
|
|
107
|
+
/cats:
|
|
108
|
+
get:`,
|
|
109
|
+
'foobar.yaml'
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const results = await lintDocument({
|
|
113
|
+
externalRefResolver: new BaseResolver(),
|
|
114
|
+
document,
|
|
115
|
+
config: await makeConfig({ 'security-defined': 'error' }),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
119
|
+
Array [
|
|
120
|
+
Object {
|
|
121
|
+
"location": Array [
|
|
122
|
+
Object {
|
|
123
|
+
"pointer": "#/paths/~1pets/get/security/0/some",
|
|
124
|
+
"reportOnKey": true,
|
|
125
|
+
"source": "foobar.yaml",
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
"message": "There is no \`some\` security scheme defined.",
|
|
129
|
+
"ruleId": "security-defined",
|
|
130
|
+
"severity": "error",
|
|
131
|
+
"suggest": Array [],
|
|
132
|
+
},
|
|
133
|
+
Object {
|
|
134
|
+
"location": Array [
|
|
135
|
+
Object {
|
|
136
|
+
"pointer": "#/",
|
|
137
|
+
"reportOnKey": false,
|
|
138
|
+
"source": "foobar.yaml",
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
"message": "Every API should have security defined on the root level or for each operation.",
|
|
142
|
+
"ruleId": "security-defined",
|
|
143
|
+
"severity": "error",
|
|
144
|
+
"suggest": Array [],
|
|
145
|
+
},
|
|
146
|
+
]
|
|
147
|
+
`);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should not report on securityRequirements object if security scheme is defined in components', async () => {
|
|
151
|
+
const document = parseYamlToDocument(
|
|
152
|
+
outdent`
|
|
153
|
+
openapi: 3.0.0
|
|
154
|
+
paths:
|
|
155
|
+
/pets:
|
|
156
|
+
get:
|
|
157
|
+
security:
|
|
158
|
+
some: []
|
|
159
|
+
components:
|
|
160
|
+
securitySchemes:
|
|
161
|
+
some:
|
|
162
|
+
type: http
|
|
163
|
+
scheme: basic`,
|
|
164
|
+
'foobar.yaml'
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const results = await lintDocument({
|
|
168
|
+
externalRefResolver: new BaseResolver(),
|
|
169
|
+
document,
|
|
170
|
+
config: await makeConfig({ 'security-defined': 'error' }),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -31,6 +31,7 @@ describe('Oas3 spec', () => {
|
|
|
31
31
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
32
32
|
Array [
|
|
33
33
|
Object {
|
|
34
|
+
"from": undefined,
|
|
34
35
|
"location": Array [
|
|
35
36
|
Object {
|
|
36
37
|
"pointer": "#/",
|
|
@@ -44,6 +45,7 @@ describe('Oas3 spec', () => {
|
|
|
44
45
|
"suggest": Array [],
|
|
45
46
|
},
|
|
46
47
|
Object {
|
|
48
|
+
"from": undefined,
|
|
47
49
|
"location": Array [
|
|
48
50
|
Object {
|
|
49
51
|
"pointer": "#/paths/~1test/get/parameters/0",
|
|
@@ -59,4 +61,81 @@ describe('Oas3 spec', () => {
|
|
|
59
61
|
]
|
|
60
62
|
`);
|
|
61
63
|
});
|
|
64
|
+
|
|
65
|
+
it('should report with "referenced from"', async () => {
|
|
66
|
+
const document = parseYamlToDocument(
|
|
67
|
+
outdent`
|
|
68
|
+
openapi: 3.0.0
|
|
69
|
+
components:
|
|
70
|
+
requestBodies:
|
|
71
|
+
TestRequestBody:
|
|
72
|
+
content:
|
|
73
|
+
application/json:
|
|
74
|
+
schema:
|
|
75
|
+
type: object
|
|
76
|
+
schemas:
|
|
77
|
+
TestSchema:
|
|
78
|
+
title: TestSchema
|
|
79
|
+
allOf:
|
|
80
|
+
- $ref: "#/components/requestBodies/TestRequestBody"
|
|
81
|
+
`,
|
|
82
|
+
'foobar.yaml'
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const results = await lintDocument({
|
|
86
|
+
externalRefResolver: new BaseResolver(),
|
|
87
|
+
document,
|
|
88
|
+
config: await makeConfig({ spec: 'error' }),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
92
|
+
Array [
|
|
93
|
+
Object {
|
|
94
|
+
"from": undefined,
|
|
95
|
+
"location": Array [
|
|
96
|
+
Object {
|
|
97
|
+
"pointer": "#/",
|
|
98
|
+
"reportOnKey": true,
|
|
99
|
+
"source": "foobar.yaml",
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
"message": "The field \`paths\` must be present on this level.",
|
|
103
|
+
"ruleId": "spec",
|
|
104
|
+
"severity": "error",
|
|
105
|
+
"suggest": Array [],
|
|
106
|
+
},
|
|
107
|
+
Object {
|
|
108
|
+
"from": undefined,
|
|
109
|
+
"location": Array [
|
|
110
|
+
Object {
|
|
111
|
+
"pointer": "#/",
|
|
112
|
+
"reportOnKey": true,
|
|
113
|
+
"source": "foobar.yaml",
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
"message": "The field \`info\` must be present on this level.",
|
|
117
|
+
"ruleId": "spec",
|
|
118
|
+
"severity": "error",
|
|
119
|
+
"suggest": Array [],
|
|
120
|
+
},
|
|
121
|
+
Object {
|
|
122
|
+
"from": Object {
|
|
123
|
+
"pointer": "#/components/schemas/TestSchema/allOf/0",
|
|
124
|
+
"source": "foobar.yaml",
|
|
125
|
+
},
|
|
126
|
+
"location": Array [
|
|
127
|
+
Object {
|
|
128
|
+
"pointer": "#/components/requestBodies/TestRequestBody/content",
|
|
129
|
+
"reportOnKey": true,
|
|
130
|
+
"source": "foobar.yaml",
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
"message": "Property \`content\` is not expected here.",
|
|
134
|
+
"ruleId": "spec",
|
|
135
|
+
"severity": "error",
|
|
136
|
+
"suggest": Array [],
|
|
137
|
+
},
|
|
138
|
+
]
|
|
139
|
+
`);
|
|
140
|
+
});
|
|
62
141
|
});
|