@redocly/openapi-core 1.0.0-beta.49 → 1.0.0-beta.53

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 (136) hide show
  1. package/__tests__/normalizeVisitors.test.ts +1 -1
  2. package/__tests__/utils.ts +1 -1
  3. package/__tests__/walk.test.ts +77 -4
  4. package/lib/benchmark/benches/recommended-oas3.bench.js +2 -1
  5. package/lib/benchmark/utils.d.ts +1 -1
  6. package/lib/bundle.d.ts +1 -1
  7. package/lib/bundle.js +10 -10
  8. package/lib/config/builtIn.d.ts +2 -1
  9. package/lib/config/builtIn.js +9 -1
  10. package/lib/config/config.d.ts +5 -7
  11. package/lib/config/config.js +40 -100
  12. package/lib/config/load.d.ts +2 -0
  13. package/lib/config/load.js +65 -0
  14. package/lib/config/rules.d.ts +1 -1
  15. package/lib/format/codeframes.js +1 -1
  16. package/lib/index.d.ts +4 -3
  17. package/lib/index.js +13 -11
  18. package/lib/lint.d.ts +6 -19
  19. package/lib/lint.js +13 -43
  20. package/lib/oas-types.d.ts +19 -0
  21. package/lib/oas-types.js +42 -0
  22. package/lib/resolve.d.ts +6 -2
  23. package/lib/resolve.js +18 -5
  24. package/lib/rules/ajv.d.ts +3 -3
  25. package/lib/rules/ajv.js +21 -18
  26. package/lib/rules/common/info-contact.js +2 -1
  27. package/lib/rules/common/info-description.js +2 -1
  28. package/lib/rules/common/info-license-url.js +2 -1
  29. package/lib/rules/common/license-url.js +2 -1
  30. package/lib/rules/common/no-ambiguous-paths.js +2 -1
  31. package/lib/rules/common/no-enum-type-mismatch.js +2 -1
  32. package/lib/rules/common/no-identical-paths.js +2 -1
  33. package/lib/rules/common/no-path-trailing-slash.js +2 -1
  34. package/lib/rules/common/operation-2xx-response.js +2 -1
  35. package/lib/rules/common/operation-description.js +2 -1
  36. package/lib/rules/common/operation-operationId-unique.js +2 -1
  37. package/lib/rules/common/operation-operationId-url-safe.js +2 -1
  38. package/lib/rules/common/operation-operationId.js +9 -4
  39. package/lib/rules/common/operation-parameters-unique.js +2 -1
  40. package/lib/rules/common/operation-security-defined.js +2 -1
  41. package/lib/rules/common/operation-singular-tag.js +2 -1
  42. package/lib/rules/common/operation-summary.js +2 -1
  43. package/lib/rules/common/operation-tag-defined.js +2 -1
  44. package/lib/rules/common/parameter-description.js +2 -1
  45. package/lib/rules/common/path-declaration-must-exist.js +2 -1
  46. package/lib/rules/common/path-http-verbs-order.js +2 -1
  47. package/lib/rules/common/path-not-include-query.js +2 -1
  48. package/lib/rules/common/path-params-defined.js +3 -2
  49. package/lib/rules/common/paths-kebab-case.js +2 -1
  50. package/lib/rules/common/registry-dependencies.js +2 -1
  51. package/lib/rules/common/spec.js +5 -2
  52. package/lib/rules/common/tag-description.js +2 -1
  53. package/lib/rules/common/tags-alphabetical.js +2 -1
  54. package/lib/rules/no-unresolved-refs.js +2 -1
  55. package/lib/rules/oas2/boolean-parameter-prefixes.js +2 -1
  56. package/lib/rules/oas2/index.d.ts +1 -1
  57. package/lib/rules/oas2/index.js +1 -1
  58. package/lib/rules/oas3/boolean-parameter-prefixes.js +2 -1
  59. package/lib/rules/oas3/index.d.ts +2 -1
  60. package/lib/rules/oas3/index.js +2 -2
  61. package/lib/rules/oas3/no-empty-servers.js +2 -1
  62. package/lib/rules/oas3/no-example-value-and-externalValue.js +2 -1
  63. package/lib/rules/oas3/no-invalid-media-type-examples.js +20 -10
  64. package/lib/rules/oas3/no-server-example.com.js +2 -1
  65. package/lib/rules/oas3/no-server-trailing-slash.js +2 -1
  66. package/lib/rules/oas3/no-servers-empty-enum.js +2 -1
  67. package/lib/rules/oas3/no-undefined-server-variable.js +2 -1
  68. package/lib/rules/oas3/no-unused-components.js +2 -1
  69. package/lib/rules/other/stats.js +2 -1
  70. package/lib/types/oas2.js +1 -1
  71. package/lib/types/oas3.js +1 -1
  72. package/lib/types/oas3_1.js +1 -1
  73. package/lib/utils.d.ts +1 -1
  74. package/lib/visitors.d.ts +3 -1
  75. package/lib/visitors.js +4 -4
  76. package/lib/walk.d.ts +1 -1
  77. package/lib/walk.js +11 -2
  78. package/package.json +7 -7
  79. package/src/__tests__/lint.test.ts +44 -0
  80. package/src/benchmark/benches/recommended-oas3.bench.ts +2 -1
  81. package/src/benchmark/benchmark.js +3 -1
  82. package/src/benchmark/utils.ts +1 -1
  83. package/src/bundle.ts +2 -2
  84. package/src/config/__tests__/resolve-plugins.test.ts +1 -1
  85. package/src/config/builtIn.ts +11 -1
  86. package/src/config/config.ts +30 -78
  87. package/src/config/load.ts +60 -0
  88. package/src/config/rules.ts +1 -1
  89. package/src/format/codeframes.ts +1 -1
  90. package/src/index.ts +4 -3
  91. package/src/lint.ts +19 -56
  92. package/src/oas-types.ts +58 -0
  93. package/src/resolve.ts +17 -4
  94. package/src/rules/__tests__/config.ts +10 -0
  95. package/src/rules/__tests__/no-unresolved-refs.test.ts +9 -21
  96. package/src/rules/ajv.ts +27 -23
  97. package/src/rules/common/__tests__/info-description.test.ts +8 -16
  98. package/src/rules/common/__tests__/info-license.test.ts +3 -3
  99. package/src/rules/common/__tests__/license-url.test.ts +3 -3
  100. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +2 -2
  101. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +50 -5
  102. package/src/rules/common/__tests__/no-identical-paths.test.ts +2 -2
  103. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +4 -4
  104. package/src/rules/common/__tests__/operation-2xx-response.test.ts +4 -4
  105. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +3 -3
  106. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +2 -5
  107. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +5 -17
  108. package/src/rules/common/__tests__/operation-security-defined.test.ts +3 -3
  109. package/src/rules/common/__tests__/operation-singular-tag.test.ts +3 -3
  110. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +3 -3
  111. package/src/rules/common/__tests__/path-not-include-query.test.ts +3 -3
  112. package/src/rules/common/__tests__/path-params-defined.test.ts +4 -4
  113. package/src/rules/common/__tests__/paths-kebab-case.test.ts +3 -3
  114. package/src/rules/common/__tests__/tag-description.test.ts +3 -3
  115. package/src/rules/common/__tests__/tags-alphabetical.test.ts +3 -3
  116. package/src/rules/common/operation-operationId.ts +7 -3
  117. package/src/rules/common/spec.ts +4 -1
  118. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +7 -10
  119. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +3 -6
  120. package/src/rules/oas2/__tests__/spec/utils.ts +2 -0
  121. package/src/rules/oas2/index.ts +1 -10
  122. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +7 -10
  123. package/src/rules/oas3/__tests__/fixtures/common.yaml +11 -0
  124. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +7 -7
  125. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +3 -9
  126. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +103 -29
  127. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +3 -3
  128. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  129. package/src/rules/oas3/__tests__/no-unused-components.test.ts +2 -2
  130. package/src/rules/oas3/__tests__/spec/spec.test.ts +3 -1
  131. package/src/rules/oas3/__tests__/spec/utils.ts +2 -0
  132. package/src/rules/oas3/index.ts +3 -4
  133. package/src/rules/oas3/no-invalid-media-type-examples.ts +27 -19
  134. package/src/visitors.ts +12 -8
  135. package/src/walk.ts +24 -8
  136. package/tsconfig.tsbuildinfo +1 -3084
@@ -2,10 +2,10 @@ import path = require('path');
2
2
  import { outdent } from 'outdent';
3
3
 
4
4
  import { lintDocument } from '../../lint';
5
- import { LintConfig } from '../..';
6
5
  import { BaseResolver } from '../../resolve';
7
6
 
8
7
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../__tests__/utils';
8
+ import { makeConfig } from './config';
9
9
 
10
10
  describe('oas3 boolean-parameter-prefixes', () => {
11
11
  it('should report on unresolved $ref', async () => {
@@ -24,11 +24,8 @@ describe('oas3 boolean-parameter-prefixes', () => {
24
24
  const results = await lintDocument({
25
25
  externalRefResolver: new BaseResolver(),
26
26
  document,
27
- config: new LintConfig({
28
- extends: [],
29
- rules: {
30
- 'no-unresolved-refs': 'error',
31
- },
27
+ config: makeConfig({
28
+ 'no-unresolved-refs': 'error',
32
29
  }),
33
30
  });
34
31
 
@@ -67,11 +64,8 @@ describe('oas3 boolean-parameter-prefixes', () => {
67
64
  const results = await lintDocument({
68
65
  externalRefResolver: new BaseResolver(),
69
66
  document,
70
- config: new LintConfig({
71
- extends: [],
72
- rules: {
73
- 'no-unresolved-refs': 'error',
74
- },
67
+ config: makeConfig({
68
+ 'no-unresolved-refs': 'error',
75
69
  }),
76
70
  });
77
71
 
@@ -127,11 +121,8 @@ describe('oas3 boolean-parameter-prefixes', () => {
127
121
  const results = await lintDocument({
128
122
  externalRefResolver: new BaseResolver(),
129
123
  document,
130
- config: new LintConfig({
131
- extends: [],
132
- rules: {
133
- 'no-unresolved-refs': 'error',
134
- },
124
+ config: makeConfig({
125
+ 'no-unresolved-refs': 'error',
135
126
  }),
136
127
  });
137
128
 
@@ -154,11 +145,8 @@ describe('oas3 boolean-parameter-prefixes', () => {
154
145
  const results = await lintDocument({
155
146
  externalRefResolver: new BaseResolver(),
156
147
  document,
157
- config: new LintConfig({
158
- extends: [],
159
- rules: {
160
- 'no-unresolved-refs': 'error',
161
- },
148
+ config: makeConfig({
149
+ 'no-unresolved-refs': 'error',
162
150
  }),
163
151
  });
164
152
 
package/src/rules/ajv.ts CHANGED
@@ -1,11 +1,8 @@
1
- // @ts-ignore
2
- import * as Ajv from '@redocly/ajv';
3
- // import * as jsonSpecV4 from 'ajv/lib/refs/json-schema-draft-04.json';
4
- // import { OasVersion } from '../validate';
1
+ import Ajv, { ValidateFunction, ErrorObject } from '@redocly/ajv';
5
2
  import { Location, escapePointer } from '../ref-utils';
6
3
  import { ResolveFn } from '../walk';
7
4
 
8
- let ajvInstance: Ajv.Ajv | null = null;
5
+ let ajvInstance: Ajv | null = null;
9
6
 
10
7
  export function releaseAjvInstance() {
11
8
  ajvInstance = null;
@@ -14,20 +11,20 @@ export function releaseAjvInstance() {
14
11
  function getAjv(resolve: ResolveFn<any>, disallowAdditionalProperties: boolean) {
15
12
  if (!ajvInstance) {
16
13
  ajvInstance = new Ajv({
17
- schemaId: 'auto',
14
+ schemaId: '$id',
18
15
  meta: true,
19
16
  allErrors: true,
20
- jsonPointers: true,
21
- unknownFormats: 'ignore',
22
- nullable: true,
23
- missingRefs: 'ignore',
17
+ strictSchema: false,
24
18
  inlineRefs: false,
25
19
  validateSchema: false,
20
+ discriminator: true,
21
+ allowUnionTypes: true,
22
+ validateFormats: false, // TODO: fix it
26
23
  defaultAdditionalProperties: !disallowAdditionalProperties,
27
- loadSchemaSync(base: string, $ref: string, id: string) {
28
- const resolvedRef = resolve({ $ref }, base.replace(/#$/, ''));
24
+ loadSchemaSync(base: string, $ref: string) {
25
+ const resolvedRef = resolve({ $ref }, base.split('#')[0]);
29
26
  if (!resolvedRef || !resolvedRef.location) return undefined;
30
- return { id, ...resolvedRef.node };
27
+ return { $id: resolvedRef.location.absolutePointer, ...resolvedRef.node };
31
28
  },
32
29
  logger: false,
33
30
  });
@@ -40,11 +37,11 @@ function getAjvValidator(
40
37
  loc: Location,
41
38
  resolve: ResolveFn<any>,
42
39
  disallowAdditionalProperties: boolean,
43
- ): Ajv.ValidateFunction | undefined {
40
+ ): ValidateFunction | undefined {
44
41
  const ajv = getAjv(resolve, disallowAdditionalProperties);
45
42
 
46
43
  if (!ajv.getSchema(loc.absolutePointer)) {
47
- ajv.addSchema({ id: loc.absolutePointer, ...schema }, loc.absolutePointer);
44
+ ajv.addSchema({ $id: loc.absolutePointer, ...schema }, loc.absolutePointer);
48
45
  }
49
46
 
50
47
  return ajv.getSchema(loc.absolutePointer);
@@ -54,23 +51,30 @@ export function validateJsonSchema(
54
51
  data: any,
55
52
  schema: any,
56
53
  schemaLoc: Location,
57
- dataPath: string,
54
+ instancePath: string,
58
55
  resolve: ResolveFn<any>,
59
56
  disallowAdditionalProperties: boolean,
60
- ): { valid: boolean; errors: (Ajv.ErrorObject & { suggest?: string[] })[] } {
57
+ ): { valid: boolean; errors: (ErrorObject & { suggest?: string[] })[] } {
61
58
  const validate = getAjvValidator(schema, schemaLoc, resolve, disallowAdditionalProperties);
62
59
  if (!validate) return { valid: true, errors: [] }; // unresolved refs are reported
63
60
 
64
- const valid = validate(data, dataPath);
61
+ const valid = validate(data, {
62
+ instancePath,
63
+ parentData: { fake: {} },
64
+ parentDataProperty: 'fake',
65
+ rootData: {},
66
+ dynamicAnchors: {},
67
+ });
68
+
65
69
  return {
66
70
  valid: !!valid,
67
71
  errors: (validate.errors || []).map(beatifyErrorMessage),
68
72
  };
69
73
 
70
- function beatifyErrorMessage(error: Ajv.ErrorObject) {
74
+ function beatifyErrorMessage(error: ErrorObject) {
71
75
  let message = error.message;
72
76
  let suggest =
73
- error.keyword === 'enum' ? (error.params as Ajv.EnumParams).allowedValues : undefined;
77
+ error.keyword === 'enum' ? error.params.allowedValues : undefined;
74
78
  if (suggest) {
75
79
  message += ` ${suggest.map((e: any) => `"${e}"`).join(', ')}`;
76
80
  }
@@ -79,15 +83,15 @@ export function validateJsonSchema(
79
83
  message = `type ${message}`;
80
84
  }
81
85
 
82
- const relativePath = error.dataPath.substring(dataPath.length + 1);
86
+ const relativePath = error.instancePath.substring(instancePath.length + 1);
83
87
  const propName = relativePath.substring(relativePath.lastIndexOf('/') + 1);
84
88
  if (propName) {
85
89
  message = `\`${propName}\` property ${message}`;
86
90
  }
87
91
  if (error.keyword === 'additionalProperties') {
88
- const property = (error.params as Ajv.AdditionalPropertiesParams).additionalProperty;
92
+ const property = error.params.additionalProperty;
89
93
  message = `${message} \`${property}\``;
90
- error.dataPath += '/' + escapePointer(property);
94
+ error.instancePath += '/' + escapePointer(property);
91
95
  }
92
96
 
93
97
  return {
@@ -1,9 +1,10 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { LintConfig } from '../../../config/config';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
6
+ import { makeConfig } from '../../__tests__/config';
7
+
7
8
  describe('Oas3 info-description', () => {
8
9
  it('should report on info with no description', async () => {
9
10
  const document = parseYamlToDocument(
@@ -18,11 +19,8 @@ describe('Oas3 info-description', () => {
18
19
  const results = await lintDocument({
19
20
  externalRefResolver: new BaseResolver(),
20
21
  document,
21
- config: new LintConfig({
22
- extends: [],
23
- rules: {
24
- 'info-description': 'error',
25
- },
22
+ config: makeConfig({
23
+ 'info-description': 'error',
26
24
  }),
27
25
  });
28
26
 
@@ -59,11 +57,8 @@ describe('Oas3 info-description', () => {
59
57
  const results = await lintDocument({
60
58
  externalRefResolver: new BaseResolver(),
61
59
  document,
62
- config: new LintConfig({
63
- extends: [],
64
- rules: {
65
- 'info-description': 'error',
66
- },
60
+ config: makeConfig({
61
+ 'info-description': 'error',
67
62
  }),
68
63
  });
69
64
 
@@ -99,11 +94,8 @@ describe('Oas3 info-description', () => {
99
94
  const results = await lintDocument({
100
95
  externalRefResolver: new BaseResolver(),
101
96
  document,
102
- config: new LintConfig({
103
- extends: [],
104
- rules: {
105
- 'info-description': 'error',
106
- },
97
+ config: makeConfig({
98
+ 'info-description': 'error',
107
99
  }),
108
100
  });
109
101
 
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('Oas3 info-license', () => {
@@ -18,7 +18,7 @@ describe('Oas3 info-license', () => {
18
18
  const results = await lintDocument({
19
19
  externalRefResolver: new BaseResolver(),
20
20
  document,
21
- config: new LintConfig({ extends: [], rules: { 'info-license': 'error' } }),
21
+ config: makeConfig({ 'info-license': 'error' }),
22
22
  });
23
23
 
24
24
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -55,7 +55,7 @@ describe('Oas3 info-license', () => {
55
55
  const results = await lintDocument({
56
56
  externalRefResolver: new BaseResolver(),
57
57
  document,
58
- config: new LintConfig({ extends: [], rules: { 'info-license': 'error' } }),
58
+ config: makeConfig({ 'info-license': 'error' }),
59
59
  });
60
60
 
61
61
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('Oas3 license-url', () => {
@@ -19,7 +19,7 @@ describe('Oas3 license-url', () => {
19
19
  const results = await lintDocument({
20
20
  externalRefResolver: new BaseResolver(),
21
21
  document,
22
- config: new LintConfig({ extends: [], rules: { 'info-license-url': 'error' } }),
22
+ config: makeConfig({ 'info-license-url': 'error' }),
23
23
  });
24
24
 
25
25
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -56,7 +56,7 @@ describe('Oas3 license-url', () => {
56
56
  const results = await lintDocument({
57
57
  externalRefResolver: new BaseResolver(),
58
58
  document,
59
- config: new LintConfig({ extends: [], rules: { 'info-license-url': 'error' } }),
59
+ config: makeConfig({ 'info-license-url': 'error' }),
60
60
  });
61
61
 
62
62
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('no-ambiguous-paths', () => {
@@ -47,7 +47,7 @@ describe('no-ambiguous-paths', () => {
47
47
  const results = await lintDocument({
48
48
  externalRefResolver: new BaseResolver(),
49
49
  document,
50
- config: new LintConfig({ extends: [], rules: { 'no-ambiguous-paths': 'error' } }),
50
+ config: makeConfig({ 'no-ambiguous-paths': 'error' }),
51
51
  });
52
52
 
53
53
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('Oas3 typed enum', () => {
@@ -30,7 +30,7 @@ describe('Oas3 typed enum', () => {
30
30
  const results = await lintDocument({
31
31
  externalRefResolver: new BaseResolver(),
32
32
  document,
33
- config: new LintConfig({ extends: [], rules: { 'no-enum-type-mismatch': 'error' } }),
33
+ config: makeConfig({ 'no-enum-type-mismatch': 'error' }),
34
34
  });
35
35
 
36
36
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -63,7 +63,7 @@ describe('Oas3 typed enum', () => {
63
63
  const results = await lintDocument({
64
64
  externalRefResolver: new BaseResolver(),
65
65
  document,
66
- config: new LintConfig({ extends: [], rules: { 'no-enum-type-mismatch': 'error' } }),
66
+ config: makeConfig({ 'no-enum-type-mismatch': 'error' }),
67
67
  });
68
68
 
69
69
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -93,7 +93,7 @@ describe('Oas3 typed enum', () => {
93
93
  const results = await lintDocument({
94
94
  externalRefResolver: new BaseResolver(),
95
95
  document,
96
- config: new LintConfig({ extends: [], rules: { 'no-enum-type-mismatch': 'error' } }),
96
+ config: makeConfig({ 'no-enum-type-mismatch': 'error' }),
97
97
  });
98
98
 
99
99
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -141,7 +141,7 @@ describe('Oas3 typed enum', () => {
141
141
  const results = await lintDocument({
142
142
  externalRefResolver: new BaseResolver(),
143
143
  document,
144
- config: new LintConfig({ extends: [], rules: { 'no-enum-type-mismatch': 'error' } }),
144
+ config: makeConfig({ 'no-enum-type-mismatch': 'error' }),
145
145
  });
146
146
 
147
147
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -162,4 +162,49 @@ describe('Oas3 typed enum', () => {
162
162
  ]
163
163
  `);
164
164
  });
165
+
166
+ it('should not crash on null schema when there is spec rule', async () => {
167
+ const document = parseYamlToDocument(
168
+ outdent`
169
+ openapi: 3.0.0
170
+ info:
171
+ title: test
172
+ version: 1.2.3
173
+ paths:
174
+ /some:
175
+ get:
176
+ responses:
177
+ '200':
178
+ description: test
179
+ content:
180
+ application/json:
181
+ schema: null
182
+ `,
183
+ 'foobar.yaml',
184
+ );
185
+
186
+ const results = await lintDocument({
187
+ externalRefResolver: new BaseResolver(),
188
+ document,
189
+ config: makeConfig({ 'spec': 'error', 'no-enum-type-mismatch': 'error' }),
190
+ });
191
+
192
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
193
+ Array [
194
+ Object {
195
+ "location": Array [
196
+ Object {
197
+ "pointer": "#/paths/~1some/get/responses/200/content/application~1json/schema",
198
+ "reportOnKey": false,
199
+ "source": "foobar.yaml",
200
+ },
201
+ ],
202
+ "message": "Expected type \`Schema\` (object) but got \`null\`",
203
+ "ruleId": "spec",
204
+ "severity": "error",
205
+ "suggest": Array [],
206
+ },
207
+ ]
208
+ `);
209
+ });
165
210
  });
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('no-identical-paths', () => {
@@ -35,7 +35,7 @@ describe('no-identical-paths', () => {
35
35
  const results = await lintDocument({
36
36
  externalRefResolver: new BaseResolver(),
37
37
  document,
38
- config: new LintConfig({ extends: [], rules: { 'no-identical-paths': 'error' } }),
38
+ config: makeConfig({ 'no-identical-paths': 'error' }),
39
39
  });
40
40
 
41
41
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('no-path-trailing-slash', () => {
@@ -20,7 +20,7 @@ describe('no-path-trailing-slash', () => {
20
20
  const results = await lintDocument({
21
21
  externalRefResolver: new BaseResolver(),
22
22
  document,
23
- config: new LintConfig({ extends: [], rules: { 'no-path-trailing-slash': 'error' } }),
23
+ config: makeConfig({ 'no-path-trailing-slash': 'error' }),
24
24
  });
25
25
 
26
26
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -57,7 +57,7 @@ describe('no-path-trailing-slash', () => {
57
57
  const results = await lintDocument({
58
58
  externalRefResolver: new BaseResolver(),
59
59
  document,
60
- config: new LintConfig({ extends: [], rules: { 'no-path-trailing-slash': 'error' } }),
60
+ config: makeConfig({ 'no-path-trailing-slash': 'error' }),
61
61
  });
62
62
 
63
63
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -78,7 +78,7 @@ describe('no-path-trailing-slash', () => {
78
78
  const results = await lintDocument({
79
79
  externalRefResolver: new BaseResolver(),
80
80
  document,
81
- config: new LintConfig({ extends: [], rules: { 'no-path-trailing-slash': 'error' } }),
81
+ config: makeConfig({ 'no-path-trailing-slash': 'error' }),
82
82
  });
83
83
 
84
84
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('Oas3 operation-2xx-response', () => {
@@ -22,7 +22,7 @@ describe('Oas3 operation-2xx-response', () => {
22
22
  const results = await lintDocument({
23
23
  externalRefResolver: new BaseResolver(),
24
24
  document,
25
- config: new LintConfig({ extends: [], rules: { 'operation-2xx-response': 'error' } }),
25
+ config: makeConfig({ 'operation-2xx-response': 'error' }),
26
26
  });
27
27
 
28
28
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -61,7 +61,7 @@ describe('Oas3 operation-2xx-response', () => {
61
61
  const results = await lintDocument({
62
62
  externalRefResolver: new BaseResolver(),
63
63
  document,
64
- config: new LintConfig({ extends: [], rules: { 'operation-2xx-response': 'error' } }),
64
+ config: makeConfig({ 'operation-2xx-response': 'error' }),
65
65
  });
66
66
 
67
67
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -84,7 +84,7 @@ describe('Oas3 operation-2xx-response', () => {
84
84
  const results = await lintDocument({
85
85
  externalRefResolver: new BaseResolver(),
86
86
  document,
87
- config: new LintConfig({ extends: [], rules: { 'operation-2xx-response': 'error' } }),
87
+ config: makeConfig({ 'operation-2xx-response': 'error' }),
88
88
  });
89
89
 
90
90
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('Oas3 operation-operationId-unique', () => {
@@ -27,7 +27,7 @@ describe('Oas3 operation-operationId-unique', () => {
27
27
  const results = await lintDocument({
28
28
  externalRefResolver: new BaseResolver(),
29
29
  document,
30
- config: new LintConfig({ extends: [], rules: { 'operation-operationId-unique': 'error' } }),
30
+ config: makeConfig({ 'operation-operationId-unique': 'error' }),
31
31
  });
32
32
 
33
33
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -69,7 +69,7 @@ describe('Oas3 operation-operationId-unique', () => {
69
69
  const results = await lintDocument({
70
70
  externalRefResolver: new BaseResolver(),
71
71
  document,
72
- config: new LintConfig({ extends: [], rules: { 'peration-operationId-unique': 'error' } }),
72
+ config: makeConfig({ 'peration-operationId-unique': 'error' }),
73
73
  });
74
74
 
75
75
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('Oas3 operation-operationId-url-safe', () => {
@@ -22,10 +22,7 @@ describe('Oas3 operation-operationId-url-safe', () => {
22
22
  const results = await lintDocument({
23
23
  externalRefResolver: new BaseResolver(),
24
24
  document,
25
- config: new LintConfig({
26
- extends: [],
27
- rules: { 'operation-operationId-url-safe': 'error' },
28
- }),
25
+ config: makeConfig({ 'operation-operationId-url-safe': 'error' }),
29
26
  });
30
27
 
31
28
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('Oas3 operation-parameters-unique', () => {
@@ -23,10 +23,7 @@ describe('Oas3 operation-parameters-unique', () => {
23
23
  const results = await lintDocument({
24
24
  externalRefResolver: new BaseResolver(),
25
25
  document,
26
- config: new LintConfig({
27
- extends: [],
28
- rules: { 'operation-parameters-unique': 'error' },
29
- }),
26
+ config: makeConfig({ 'operation-parameters-unique': 'error' }),
30
27
  });
31
28
 
32
29
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -69,10 +66,7 @@ describe('Oas3 operation-parameters-unique', () => {
69
66
  const results = await lintDocument({
70
67
  externalRefResolver: new BaseResolver(),
71
68
  document,
72
- config: new LintConfig({
73
- extends: [],
74
- rules: { 'operation-parameters-unique': 'error' },
75
- }),
69
+ config: makeConfig({ 'operation-parameters-unique': 'error' }),
76
70
  });
77
71
 
78
72
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -102,10 +96,7 @@ describe('Oas3 operation-parameters-unique', () => {
102
96
  const results = await lintDocument({
103
97
  externalRefResolver: new BaseResolver(),
104
98
  document,
105
- config: new LintConfig({
106
- extends: [],
107
- rules: { 'operation-parameters-unique': 'error' },
108
- }),
99
+ config: makeConfig({ 'operation-parameters-unique': 'error' }),
109
100
  });
110
101
 
111
102
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -153,10 +144,7 @@ describe('Oas3 operation-parameters-unique', () => {
153
144
  const results = await lintDocument({
154
145
  externalRefResolver: new BaseResolver(),
155
146
  document,
156
- config: new LintConfig({
157
- extends: [],
158
- rules: { 'operation-parameters-unique': 'error' },
159
- }),
147
+ config: makeConfig({ 'operation-parameters-unique': 'error' }),
160
148
  });
161
149
 
162
150
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('Oas3 operation-security-defined', () => {
@@ -20,7 +20,7 @@ describe('Oas3 operation-security-defined', () => {
20
20
  const results = await lintDocument({
21
21
  externalRefResolver: new BaseResolver(),
22
22
  document,
23
- config: new LintConfig({ extends: [], rules: { 'operation-security-defined': 'error' } }),
23
+ config: makeConfig({ 'operation-security-defined': 'error' }),
24
24
  });
25
25
 
26
26
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -62,7 +62,7 @@ describe('Oas3 operation-security-defined', () => {
62
62
  const results = await lintDocument({
63
63
  externalRefResolver: new BaseResolver(),
64
64
  document,
65
- config: new LintConfig({ extends: [], rules: { 'operation-security-defined': 'error' } }),
65
+ config: makeConfig({ 'operation-security-defined': 'error' }),
66
66
  });
67
67
 
68
68
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -1,7 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { LintConfig } from '../../../config/config';
3
2
  import { lintDocument } from '../../../lint';
4
3
  import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
+ import { makeConfig } from '../../__tests__/config';
5
5
  import { BaseResolver } from '../../../resolve';
6
6
 
7
7
  describe('Oas3 operation-singular-tag', () => {
@@ -25,7 +25,7 @@ describe('Oas3 operation-singular-tag', () => {
25
25
  const results = await lintDocument({
26
26
  externalRefResolver: new BaseResolver(),
27
27
  document,
28
- config: new LintConfig({ extends: [], rules: { 'operation-singular-tag': 'error' } }),
28
+ config: makeConfig({ 'operation-singular-tag': 'error' }),
29
29
  });
30
30
 
31
31
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
@@ -65,7 +65,7 @@ describe('Oas3 operation-singular-tag', () => {
65
65
  const results = await lintDocument({
66
66
  externalRefResolver: new BaseResolver(),
67
67
  document,
68
- config: new LintConfig({ extends: [], rules: { 'operation-singular-tag': 'error' } }),
68
+ config: makeConfig({ 'operation-singular-tag': 'error' }),
69
69
  });
70
70
 
71
71
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);