@redocly/openapi-core 1.0.0-beta.109 → 1.0.0-beta.111

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.
Files changed (88) hide show
  1. package/README.md +2 -2
  2. package/lib/config/config-resolvers.js +44 -25
  3. package/lib/config/config.d.ts +1 -0
  4. package/lib/config/config.js +1 -0
  5. package/lib/config/load.d.ts +8 -2
  6. package/lib/config/load.js +4 -2
  7. package/lib/config/types.d.ts +10 -0
  8. package/lib/config/utils.js +2 -2
  9. package/lib/rules/ajv.d.ts +1 -1
  10. package/lib/rules/ajv.js +5 -5
  11. package/lib/rules/common/assertions/asserts.d.ts +3 -5
  12. package/lib/rules/common/assertions/asserts.js +137 -97
  13. package/lib/rules/common/assertions/index.js +2 -6
  14. package/lib/rules/common/assertions/utils.d.ts +12 -6
  15. package/lib/rules/common/assertions/utils.js +33 -20
  16. package/lib/rules/common/no-ambiguous-paths.js +1 -1
  17. package/lib/rules/common/no-identical-paths.js +4 -4
  18. package/lib/rules/common/operation-2xx-response.js +2 -2
  19. package/lib/rules/common/operation-4xx-response.js +2 -2
  20. package/lib/rules/common/path-not-include-query.js +1 -1
  21. package/lib/rules/common/path-params-defined.js +7 -2
  22. package/lib/rules/common/response-contains-header.js +2 -2
  23. package/lib/rules/common/security-defined.js +10 -5
  24. package/lib/rules/common/spec.js +14 -12
  25. package/lib/rules/oas3/request-mime-type.js +1 -1
  26. package/lib/rules/oas3/response-mime-type.js +1 -1
  27. package/lib/rules/other/stats.d.ts +1 -1
  28. package/lib/rules/other/stats.js +1 -1
  29. package/lib/rules/utils.d.ts +1 -0
  30. package/lib/rules/utils.js +18 -2
  31. package/lib/types/oas2.js +6 -6
  32. package/lib/types/oas3.js +11 -11
  33. package/lib/types/oas3_1.js +3 -3
  34. package/lib/types/redocly-yaml.js +30 -5
  35. package/lib/utils.d.ts +1 -0
  36. package/lib/utils.js +13 -1
  37. package/lib/visitors.d.ts +7 -6
  38. package/lib/visitors.js +11 -3
  39. package/package.json +3 -5
  40. package/src/__tests__/__snapshots__/bundle.test.ts.snap +1 -1
  41. package/src/__tests__/lint.test.ts +88 -0
  42. package/src/__tests__/utils.test.ts +11 -0
  43. package/src/__tests__/walk.test.ts +2 -2
  44. package/src/config/__tests__/config-resolvers.test.ts +62 -1
  45. package/src/config/__tests__/config.test.ts +5 -0
  46. package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +16 -0
  47. package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +16 -0
  48. package/src/config/__tests__/fixtures/resolve-config/plugin.js +11 -0
  49. package/src/config/__tests__/load.test.ts +1 -1
  50. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  51. package/src/config/config-resolvers.ts +30 -6
  52. package/src/config/config.ts +2 -0
  53. package/src/config/load.ts +10 -4
  54. package/src/config/types.ts +13 -0
  55. package/src/config/utils.ts +1 -0
  56. package/src/rules/ajv.ts +4 -4
  57. package/src/rules/common/__tests__/operation-2xx-response.test.ts +37 -0
  58. package/src/rules/common/__tests__/operation-4xx-response.test.ts +37 -0
  59. package/src/rules/common/__tests__/path-params-defined.test.ts +69 -0
  60. package/src/rules/common/__tests__/security-defined.test.ts +6 -6
  61. package/src/rules/common/__tests__/spec.test.ts +125 -0
  62. package/src/rules/common/assertions/__tests__/asserts.test.ts +491 -428
  63. package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
  64. package/src/rules/common/assertions/asserts.ts +155 -97
  65. package/src/rules/common/assertions/index.ts +2 -11
  66. package/src/rules/common/assertions/utils.ts +66 -36
  67. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  68. package/src/rules/common/no-identical-paths.ts +4 -4
  69. package/src/rules/common/operation-2xx-response.ts +2 -2
  70. package/src/rules/common/operation-4xx-response.ts +2 -2
  71. package/src/rules/common/path-not-include-query.ts +1 -1
  72. package/src/rules/common/path-params-defined.ts +9 -2
  73. package/src/rules/common/response-contains-header.ts +6 -1
  74. package/src/rules/common/security-defined.ts +10 -5
  75. package/src/rules/common/spec.ts +15 -11
  76. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +51 -2
  77. package/src/rules/oas3/__tests__/response-contains-header.test.ts +116 -0
  78. package/src/rules/oas3/request-mime-type.ts +1 -1
  79. package/src/rules/oas3/response-mime-type.ts +1 -1
  80. package/src/rules/other/stats.ts +1 -1
  81. package/src/rules/utils.ts +24 -1
  82. package/src/types/oas2.ts +6 -6
  83. package/src/types/oas3.ts +11 -11
  84. package/src/types/oas3_1.ts +3 -3
  85. package/src/types/redocly-yaml.ts +30 -4
  86. package/src/utils.ts +13 -0
  87. package/src/visitors.ts +25 -10
  88. package/tsconfig.tsbuildinfo +1 -1
@@ -139,3 +139,128 @@ describe('Oas3 spec', () => {
139
139
  `);
140
140
  });
141
141
  });
142
+
143
+ describe('Oas3.1 spec', () => {
144
+ it('should report with "type can be one of the following only"', async () => {
145
+ const document = parseYamlToDocument(
146
+ outdent`
147
+ openapi: 3.1.0
148
+ info:
149
+ version: 1.0.0
150
+ title: Example.com
151
+ description: info,
152
+ license:
153
+ name: Apache 2.0
154
+ url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
155
+ components:
156
+ schemas:
157
+ TestSchema:
158
+ title: TestSchema
159
+ description: Property name's description
160
+ type: test
161
+ `
162
+ );
163
+
164
+ const results = await lintDocument({
165
+ externalRefResolver: new BaseResolver(),
166
+ document,
167
+ config: await makeConfig({ spec: 'error' }),
168
+ });
169
+
170
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
171
+ Array [
172
+ Object {
173
+ "from": undefined,
174
+ "location": Array [
175
+ Object {
176
+ "pointer": "#/components/schemas/TestSchema/type",
177
+ "reportOnKey": false,
178
+ "source": "",
179
+ },
180
+ ],
181
+ "message": "\`type\` can be one of the following only: \\"object\\", \\"array\\", \\"string\\", \\"number\\", \\"integer\\", \\"boolean\\", \\"null\\".",
182
+ "ruleId": "spec",
183
+ "severity": "error",
184
+ "suggest": Array [],
185
+ },
186
+ ]
187
+ `);
188
+ });
189
+
190
+ it('should report with unknown type in type`s list', async () => {
191
+ const document = parseYamlToDocument(
192
+ outdent`
193
+ openapi: 3.1.0
194
+ info:
195
+ version: 1.0.0
196
+ title: Example.com
197
+ description: info,
198
+ license:
199
+ name: Apache 2.0
200
+ url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
201
+ components:
202
+ schemas:
203
+ TestSchema:
204
+ title: TestSchema
205
+ description: Property name's description
206
+ type:
207
+ - string
208
+ - foo
209
+ `
210
+ );
211
+
212
+ const results = await lintDocument({
213
+ externalRefResolver: new BaseResolver(),
214
+ document,
215
+ config: await makeConfig({ spec: 'error' }),
216
+ });
217
+
218
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
219
+ Array [
220
+ Object {
221
+ "from": undefined,
222
+ "location": Array [
223
+ Object {
224
+ "pointer": "#/components/schemas/TestSchema/type/1",
225
+ "reportOnKey": false,
226
+ "source": "",
227
+ },
228
+ ],
229
+ "message": "\`type\` can be one of the following only: \\"object\\", \\"array\\", \\"string\\", \\"number\\", \\"integer\\", \\"boolean\\", \\"null\\".",
230
+ "ruleId": "spec",
231
+ "severity": "error",
232
+ "suggest": Array [],
233
+ },
234
+ ]
235
+ `);
236
+ });
237
+
238
+ it('should not report about unknown type', async () => {
239
+ const document = parseYamlToDocument(
240
+ outdent`
241
+ openapi: 3.1.0
242
+ info:
243
+ version: 1.0.0
244
+ title: Example.com
245
+ description: info,
246
+ license:
247
+ name: Apache 2.0
248
+ url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
249
+ components:
250
+ schemas:
251
+ TestSchema:
252
+ title: TestSchema
253
+ description: Property name's description
254
+ type: null
255
+ `
256
+ );
257
+
258
+ const results = await lintDocument({
259
+ externalRefResolver: new BaseResolver(),
260
+ document,
261
+ config: await makeConfig({ spec: 'error' }),
262
+ });
263
+
264
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
265
+ });
266
+ });