@redocly/openapi-core 1.0.0-beta.104 → 1.0.0-beta.107

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 (203) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +8 -6
  3. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  4. package/lib/benchmark/utils.d.ts +2 -2
  5. package/lib/benchmark/utils.js +2 -2
  6. package/lib/bundle.d.ts +2 -2
  7. package/lib/bundle.js +2 -2
  8. package/lib/config/all.d.ts +2 -2
  9. package/lib/config/all.js +1 -1
  10. package/lib/config/builtIn.d.ts +2 -2
  11. package/lib/config/builtIn.js +2 -2
  12. package/lib/config/config-resolvers.d.ts +5 -5
  13. package/lib/config/config-resolvers.js +39 -36
  14. package/lib/config/config.d.ts +6 -5
  15. package/lib/config/config.js +27 -20
  16. package/lib/config/load.js +6 -7
  17. package/lib/config/minimal.d.ts +2 -2
  18. package/lib/config/minimal.js +3 -2
  19. package/lib/config/recommended.d.ts +2 -2
  20. package/lib/config/recommended.js +3 -2
  21. package/lib/config/rules.d.ts +2 -2
  22. package/lib/config/rules.js +1 -1
  23. package/lib/config/types.d.ts +23 -19
  24. package/lib/config/utils.d.ts +5 -5
  25. package/lib/config/utils.js +43 -26
  26. package/lib/decorators/common/remove-x-internal.js +2 -2
  27. package/lib/format/format.js +1 -1
  28. package/lib/index.d.ts +2 -2
  29. package/lib/index.js +3 -2
  30. package/lib/js-yaml/index.js +1 -6
  31. package/lib/lint.d.ts +2 -2
  32. package/lib/lint.js +16 -6
  33. package/lib/redocly/registry-api.d.ts +1 -1
  34. package/lib/redocly/registry-api.js +2 -2
  35. package/lib/rules/ajv.d.ts +1 -1
  36. package/lib/rules/ajv.js +6 -6
  37. package/lib/rules/common/info-license-url.d.ts +1 -1
  38. package/lib/rules/common/info-license-url.js +5 -10
  39. package/lib/rules/common/info-license.d.ts +2 -0
  40. package/lib/rules/common/info-license.js +17 -0
  41. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  42. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  43. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  44. package/lib/rules/common/operation-operationId.js +1 -1
  45. package/lib/rules/common/path-not-include-query.js +1 -1
  46. package/lib/rules/common/paths-kebab-case.js +4 -1
  47. package/lib/rules/common/spec.js +1 -1
  48. package/lib/rules/oas2/index.js +4 -4
  49. package/lib/rules/oas2/remove-unused-components.js +3 -3
  50. package/lib/rules/oas3/index.js +4 -4
  51. package/lib/rules/oas3/no-empty-servers.js +1 -1
  52. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  53. package/lib/rules/oas3/remove-unused-components.js +2 -2
  54. package/lib/rules/other/stats.js +43 -14
  55. package/lib/rules/utils.d.ts +3 -2
  56. package/lib/rules/utils.js +19 -4
  57. package/lib/types/index.d.ts +2 -2
  58. package/lib/types/redocly-yaml.js +8 -7
  59. package/lib/utils.d.ts +5 -2
  60. package/lib/utils.js +20 -2
  61. package/lib/walk.d.ts +2 -1
  62. package/lib/walk.js +6 -3
  63. package/package.json +2 -2
  64. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  65. package/src/__tests__/bundle.test.ts +68 -34
  66. package/src/__tests__/codeframes.test.ts +13 -14
  67. package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +5 -0
  68. package/src/__tests__/js-yaml.test.ts +6 -4
  69. package/src/__tests__/lint.test.ts +127 -12
  70. package/src/__tests__/login.test.ts +2 -2
  71. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  72. package/src/__tests__/ref-utils.test.ts +13 -13
  73. package/src/__tests__/resolve-http.test.ts +1 -1
  74. package/src/__tests__/resolve.test.ts +14 -11
  75. package/src/__tests__/utils.test.ts +42 -1
  76. package/src/__tests__/walk.test.ts +48 -56
  77. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  78. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  79. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  80. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -1
  81. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  82. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  83. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  84. package/src/benchmark/benchmark.js +9 -5
  85. package/src/benchmark/utils.ts +5 -5
  86. package/src/bundle.ts +18 -17
  87. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +3 -1
  88. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  89. package/src/config/__tests__/config.test.ts +76 -76
  90. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  91. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  92. package/src/config/__tests__/load.test.ts +2 -2
  93. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  94. package/src/config/__tests__/utils.test.ts +83 -0
  95. package/src/config/all.ts +3 -4
  96. package/src/config/builtIn.ts +5 -5
  97. package/src/config/config-resolvers.ts +122 -83
  98. package/src/config/config.ts +36 -32
  99. package/src/config/load.ts +13 -16
  100. package/src/config/minimal.ts +5 -4
  101. package/src/config/recommended.ts +5 -4
  102. package/src/config/rules.ts +6 -6
  103. package/src/config/types.ts +28 -19
  104. package/src/config/utils.ts +74 -54
  105. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  106. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  107. package/src/decorators/common/filters/filter-helper.ts +1 -1
  108. package/src/decorators/common/info-description-override.ts +1 -1
  109. package/src/decorators/common/operation-description-override.ts +1 -1
  110. package/src/decorators/common/remove-x-internal.ts +4 -4
  111. package/src/decorators/common/tag-description-override.ts +1 -1
  112. package/src/format/codeframes.ts +4 -4
  113. package/src/format/format.ts +10 -10
  114. package/src/index.ts +3 -4
  115. package/src/js-yaml/index.ts +3 -8
  116. package/src/lint.ts +22 -18
  117. package/src/oas-types.ts +1 -6
  118. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  119. package/src/redocly/index.ts +6 -4
  120. package/src/redocly/registry-api.ts +6 -6
  121. package/src/ref-utils.ts +2 -2
  122. package/src/resolve.ts +7 -4
  123. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  124. package/src/rules/__tests__/utils.test.ts +160 -0
  125. package/src/rules/ajv.ts +7 -8
  126. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  127. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  128. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  129. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  130. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  131. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  132. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  133. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  134. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  135. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  136. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  137. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  138. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  139. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  140. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  141. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  142. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  143. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  144. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  145. package/src/rules/common/__tests__/spec.test.ts +2 -2
  146. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  147. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  148. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  149. package/src/rules/common/assertions/index.ts +6 -6
  150. package/src/rules/common/info-license-url.ts +4 -9
  151. package/src/rules/common/info-license.ts +15 -0
  152. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  153. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  154. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  155. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  156. package/src/rules/common/operation-operationId.ts +1 -1
  157. package/src/rules/common/operation-parameters-unique.ts +2 -2
  158. package/src/rules/common/path-not-include-query.ts +1 -1
  159. package/src/rules/common/path-params-defined.ts +1 -1
  160. package/src/rules/common/paths-kebab-case.ts +4 -1
  161. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  162. package/src/rules/common/spec.ts +10 -7
  163. package/src/rules/no-unresolved-refs.ts +1 -1
  164. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  165. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  166. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  167. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  168. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  169. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  170. package/src/rules/oas2/index.ts +3 -3
  171. package/src/rules/oas2/remove-unused-components.ts +13 -8
  172. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  173. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  174. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
  175. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  176. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  177. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  178. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  179. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  180. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  181. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  182. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  183. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  184. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  185. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  186. package/src/rules/oas3/index.ts +3 -3
  187. package/src/rules/oas3/no-empty-servers.ts +1 -1
  188. package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
  189. package/src/rules/oas3/no-servers-empty-enum.ts +9 -10
  190. package/src/rules/oas3/remove-unused-components.ts +18 -7
  191. package/src/rules/other/stats.ts +46 -17
  192. package/src/rules/utils.ts +19 -3
  193. package/src/types/index.ts +5 -5
  194. package/src/types/redocly-yaml.ts +8 -7
  195. package/src/typings/common.ts +9 -1
  196. package/src/typings/openapi.ts +1 -1
  197. package/src/utils.ts +31 -8
  198. package/src/visitors.ts +4 -4
  199. package/src/walk.ts +15 -11
  200. package/tsconfig.tsbuildinfo +1 -1
  201. package/lib/rules/common/license-url.d.ts +0 -2
  202. package/lib/rules/common/license-url.js +0 -12
  203. package/src/rules/common/license-url.ts +0 -10
@@ -11,7 +11,7 @@ export const Assertions: Oas3Rule | Oas2Rule = (opts: object) => {
11
11
  // that is why we need to iterate through 'opts' values;
12
12
  // before - filter only object 'opts' values
13
13
  const assertions: any[] = Object.values(opts).filter(
14
- (opt: unknown) => typeof opt === 'object' && opt !== null,
14
+ (opt: unknown) => typeof opt === 'object' && opt !== null
15
15
  );
16
16
 
17
17
  for (const [index, assertion] of assertions.entries()) {
@@ -42,21 +42,21 @@ export const Assertions: Oas3Rule | Oas2Rule = (opts: object) => {
42
42
  });
43
43
 
44
44
  const shouldRunOnKeys: AssertToApply | undefined = assertsToApply.find(
45
- (assert: AssertToApply) => assert.runsOnKeys && !assert.runsOnValues,
45
+ (assert: AssertToApply) => assert.runsOnKeys && !assert.runsOnValues
46
46
  );
47
47
  const shouldRunOnValues: AssertToApply | undefined = assertsToApply.find(
48
- (assert: AssertToApply) => assert.runsOnValues && !assert.runsOnKeys,
48
+ (assert: AssertToApply) => assert.runsOnValues && !assert.runsOnKeys
49
49
  );
50
50
 
51
51
  if (shouldRunOnValues && !assertion.property) {
52
52
  throw new Error(
53
- `${shouldRunOnValues.name} can't be used on all keys. Please provide a single property.`,
53
+ `${shouldRunOnValues.name} can't be used on all keys. Please provide a single property.`
54
54
  );
55
55
  }
56
56
 
57
57
  if (shouldRunOnKeys && assertion.property) {
58
58
  throw new Error(
59
- `${shouldRunOnKeys.name} can't be used on a single property. Please use 'property'.`,
59
+ `${shouldRunOnKeys.name} can't be used on a single property. Please use 'property'.`
60
60
  );
61
61
  }
62
62
 
@@ -64,7 +64,7 @@ export const Assertions: Oas3Rule | Oas2Rule = (opts: object) => {
64
64
  const subjectVisitor = buildSubjectVisitor(
65
65
  assertion.property,
66
66
  assertsToApply,
67
- assertion.context,
67
+ assertion.context
68
68
  );
69
69
  const visitorObject = buildVisitorObject(subject, assertion.context, subjectVisitor);
70
70
  visitors.push(visitorObject);
@@ -1,15 +1,10 @@
1
1
  import { Oas3Rule, Oas2Rule } from '../../visitors';
2
- import { missingRequiredField } from '../utils';
2
+ import { validateDefinedAndNonEmpty } from '../utils';
3
3
 
4
- export const InfoLicense: Oas3Rule | Oas2Rule = () => {
4
+ export const InfoLicenseUrl: Oas3Rule | Oas2Rule = () => {
5
5
  return {
6
- Info(info, { report }) {
7
- if (!info.license) {
8
- report({
9
- message: missingRequiredField('Info', 'license'),
10
- location: { reportOnKey: true }
11
- });
12
- }
6
+ License(license, ctx) {
7
+ validateDefinedAndNonEmpty('url', license, ctx);
13
8
  },
14
9
  };
15
10
  };
@@ -0,0 +1,15 @@
1
+ import { Oas3Rule, Oas2Rule } from '../../visitors';
2
+ import { missingRequiredField } from '../utils';
3
+
4
+ export const InfoLicense: Oas3Rule | Oas2Rule = () => {
5
+ return {
6
+ Info(info, { report }) {
7
+ if (!info.license) {
8
+ report({
9
+ message: missingRequiredField('Info', 'license'),
10
+ location: { reportOnKey: true },
11
+ });
12
+ }
13
+ },
14
+ };
15
+ };
@@ -10,7 +10,7 @@ export const NoAmbiguousPaths: Oas3Rule | Oas2Rule = () => {
10
10
 
11
11
  for (const currentPath of Object.keys(pathMap)) {
12
12
  const ambiguousPath = seenPaths.find((seenPath) =>
13
- arePathsAmbiguous(seenPath, currentPath),
13
+ arePathsAmbiguous(seenPath, currentPath)
14
14
  );
15
15
  if (ambiguousPath) {
16
16
  report({
@@ -10,7 +10,7 @@ export const NoEnumTypeMismatch: Oas3Rule | Oas2Rule = () => {
10
10
  if (schema.enum && !Array.isArray(schema.enum)) return;
11
11
  if (schema.enum && schema.type && !Array.isArray(schema.type)) {
12
12
  const typeMismatchedValues = schema.enum.filter(
13
- (item) => !matchesJsonSchemaType(item, schema.type as string, schema.nullable as boolean),
13
+ (item) => !matchesJsonSchemaType(item, schema.type as string, schema.nullable as boolean)
14
14
  );
15
15
  for (const mismatchedValue of typeMismatchedValues) {
16
16
  report({
@@ -23,26 +23,29 @@ export const NoEnumTypeMismatch: Oas3Rule | Oas2Rule = () => {
23
23
  }
24
24
 
25
25
  if (schema.enum && schema.type && Array.isArray(schema.type)) {
26
- const mismatchedResults: { [key: string]: string[]; } = {};
26
+ const mismatchedResults: { [key: string]: string[] } = {};
27
27
  for (const enumValue of schema.enum) {
28
28
  mismatchedResults[enumValue] = [];
29
29
 
30
30
  for (const type of schema.type) {
31
- const valid = matchesJsonSchemaType(enumValue, type as string, schema.nullable as boolean);
32
- if (!valid)
33
- mismatchedResults[enumValue].push(type);
31
+ const valid = matchesJsonSchemaType(
32
+ enumValue,
33
+ type as string,
34
+ schema.nullable as boolean
35
+ );
36
+ if (!valid) mismatchedResults[enumValue].push(type);
34
37
  }
35
38
 
36
- if(mismatchedResults[enumValue].length !== schema.type.length)
39
+ if (mismatchedResults[enumValue].length !== schema.type.length)
37
40
  delete mismatchedResults[enumValue];
38
- };
41
+ }
39
42
 
40
43
  for (const mismatchedKey of Object.keys(mismatchedResults)) {
41
44
  report({
42
- message: `Enum value \`${mismatchedKey}\` must be of one type. Allowed types: \`${schema.type}\`.`,
45
+ message: `Enum value \`${mismatchedKey}\` must be of allowed types: \`${schema.type}\`.`,
43
46
  location: location.child(['enum', schema.enum.indexOf(mismatchedKey)]),
44
47
  });
45
- };
48
+ }
46
49
  }
47
50
  },
48
51
  };
@@ -1,9 +1,9 @@
1
1
  import { UserContext } from '../../walk';
2
2
  import { Oas3Parameter } from '../../typings/openapi';
3
- import { validateExample } from '../utils';
3
+ import { getAdditionalPropertiesOption, validateExample } from '../utils';
4
4
 
5
5
  export const NoInvalidParameterExamples: any = (opts: any) => {
6
- const disallowAdditionalProperties = opts.disallowAdditionalProperties ?? true;
6
+ const allowAdditionalProperties = getAdditionalPropertiesOption(opts) ?? false;
7
7
  return {
8
8
  Parameter: {
9
9
  leave(parameter: Oas3Parameter, ctx: UserContext) {
@@ -13,7 +13,7 @@ export const NoInvalidParameterExamples: any = (opts: any) => {
13
13
  parameter.schema!,
14
14
  ctx.location.child('example'),
15
15
  ctx,
16
- disallowAdditionalProperties,
16
+ allowAdditionalProperties
17
17
  );
18
18
  }
19
19
 
@@ -25,7 +25,7 @@ export const NoInvalidParameterExamples: any = (opts: any) => {
25
25
  parameter.schema!,
26
26
  ctx.location.child(['examples', key]),
27
27
  ctx,
28
- false,
28
+ true
29
29
  );
30
30
  }
31
31
  }
@@ -1,9 +1,9 @@
1
1
  import { UserContext } from '../../walk';
2
2
  import { Oas3_1Schema } from '../../typings/openapi';
3
- import { validateExample } from '../utils';
3
+ import { getAdditionalPropertiesOption, validateExample } from '../utils';
4
4
 
5
5
  export const NoInvalidSchemaExamples: any = (opts: any) => {
6
- const disallowAdditionalProperties = opts.disallowAdditionalProperties ?? true;
6
+ const allowAdditionalProperties = getAdditionalPropertiesOption(opts) ?? false;
7
7
  return {
8
8
  Schema: {
9
9
  leave(schema: Oas3_1Schema, ctx: UserContext) {
@@ -14,12 +14,12 @@ export const NoInvalidSchemaExamples: any = (opts: any) => {
14
14
  schema,
15
15
  ctx.location.child(['examples', schema.examples.indexOf(example)]),
16
16
  ctx,
17
- disallowAdditionalProperties,
17
+ allowAdditionalProperties
18
18
  );
19
19
  }
20
20
  }
21
21
  if (schema.example) {
22
- validateExample(schema.example, schema, ctx.location.child('example'), ctx, false);
22
+ validateExample(schema.example, schema, ctx.location.child('example'), ctx, true);
23
23
  }
24
24
  },
25
25
  },
@@ -12,6 +12,6 @@ export const OperationOperationId: Oas3Rule | Oas2Rule = () => {
12
12
  validateDefinedAndNonEmpty('operationId', operation, ctx);
13
13
  },
14
14
  },
15
- }
15
+ },
16
16
  };
17
17
  };
@@ -14,7 +14,7 @@ export const OperationParametersUnique: Oas3Rule | Oas2Rule = () => {
14
14
  },
15
15
  Parameter(
16
16
  parameter: Oas2Parameter | Oas3Parameter,
17
- { report, key, parentLocations }: UserContext,
17
+ { report, key, parentLocations }: UserContext
18
18
  ) {
19
19
  const paramId = `${parameter.in}___${parameter.name}`;
20
20
  if (seenPathParams.has(paramId)) {
@@ -31,7 +31,7 @@ export const OperationParametersUnique: Oas3Rule | Oas2Rule = () => {
31
31
  },
32
32
  Parameter(
33
33
  parameter: Oas2Parameter | Oas3Parameter,
34
- { report, key, parentLocations }: UserContext,
34
+ { report, key, parentLocations }: UserContext
35
35
  ) {
36
36
  const paramId = `${parameter.in}___${parameter.name}`;
37
37
  if (seenOperationParams.has(paramId)) {
@@ -12,6 +12,6 @@ export const PathNotIncludeQuery: Oas3Rule | Oas2Rule = () => {
12
12
  });
13
13
  }
14
14
  },
15
- }
15
+ },
16
16
  };
17
17
  };
@@ -16,7 +16,7 @@ export const PathParamsDefined: Oas3Rule | Oas2Rule = () => {
16
16
  definedPathParams = new Set();
17
17
  currentPath = key as string;
18
18
  pathTemplateParams = new Set(
19
- Array.from(key!.toString().matchAll(pathRegex)).map((m) => m[1]),
19
+ Array.from(key!.toString().matchAll(pathRegex)).map((m) => m[1])
20
20
  );
21
21
  },
22
22
  Parameter(parameter: Oas2Parameter | Oas3Parameter, { report, location }: UserContext) {
@@ -4,7 +4,10 @@ import { UserContext } from '../../walk';
4
4
  export const PathsKebabCase: Oas3Rule | Oas2Rule = () => {
5
5
  return {
6
6
  PathItem(_path: object, { report, key }: UserContext) {
7
- const segments = (key as string).substr(1).split('/').filter(s => s !== ''); // filter out empty segments
7
+ const segments = (key as string)
8
+ .substr(1)
9
+ .split('/')
10
+ .filter((s) => s !== ''); // filter out empty segments
8
11
  if (!segments.every((segment) => /^{.+}$/.test(segment) || /^[a-z0-9-.]+$/.test(segment))) {
9
12
  report({
10
13
  message: `\`${key}\` does not use kebab-case.`,
@@ -10,7 +10,7 @@ export const ScalarPropertyMissingExample: Oas3Rule | Oas2Rule = () => {
10
10
  return {
11
11
  SchemaProperties(
12
12
  properties: { [name: string]: Oas2Schema | Oas3Schema | Oas3_1Schema },
13
- { report, location, oasVersion, resolve }: UserContext,
13
+ { report, location, oasVersion, resolve }: UserContext
14
14
  ) {
15
15
  for (const propName of Object.keys(properties)) {
16
16
  const propSchema = resolve(properties[propName]).node;
@@ -6,7 +6,7 @@ import { isPlainObject } from '../../utils';
6
6
 
7
7
  export const OasSpec: Oas3Rule | Oas2Rule = () => {
8
8
  return {
9
- any(node: any, { report, type, location, key, resolve, ignoreNextVisitorsOnNode } ) {
9
+ any(node: any, { report, type, location, key, resolve, ignoreNextVisitorsOnNode }) {
10
10
  const nodeType = oasTypeOf(node);
11
11
 
12
12
  if (type.items) {
@@ -40,15 +40,16 @@ export const OasSpec: Oas3Rule | Oas2Rule = () => {
40
40
  const allowed = type.allowed?.(node);
41
41
  if (allowed && isPlainObject(node)) {
42
42
  for (const propName in node) {
43
- if (allowed.includes(propName) ||
44
- (type.extensionsPrefix && propName.startsWith(type.extensionsPrefix)) ||
45
- !Object.keys(type.properties).includes(propName)
43
+ if (
44
+ allowed.includes(propName) ||
45
+ (type.extensionsPrefix && propName.startsWith(type.extensionsPrefix)) ||
46
+ !Object.keys(type.properties).includes(propName)
46
47
  ) {
47
48
  continue;
48
49
  }
49
50
  report({
50
51
  message: `The field \`${propName}\` is not allowed here.`,
51
- location: location.child([propName]).key()
52
+ location: location.child([propName]).key(),
52
53
  });
53
54
  }
54
55
  }
@@ -63,7 +64,9 @@ export const OasSpec: Oas3Rule | Oas2Rule = () => {
63
64
  }
64
65
  if (!hasProperty)
65
66
  report({
66
- message: `Must contain at least one of the following fields: ${type.requiredOneOf?.join(', ')}.`,
67
+ message: `Must contain at least one of the following fields: ${type.requiredOneOf?.join(
68
+ ', '
69
+ )}.`,
67
70
  location: [{ reportOnKey: true }],
68
71
  });
69
72
  }
@@ -134,7 +137,7 @@ export const OasSpec: Oas3Rule | Oas2Rule = () => {
134
137
  report({
135
138
  message: `The value of the ${propName} field must be greater than or equal to ${propSchema.minimum}`,
136
139
  location: location.child([propName]),
137
- })
140
+ });
138
141
  }
139
142
  }
140
143
  }
@@ -25,7 +25,7 @@ export const NoUnresolvedRefs: Oas3Rule = () => {
25
25
  export function reportUnresolvedRef(
26
26
  resolved: ResolveResult<any>,
27
27
  report: (m: Problem) => void,
28
- location: Location,
28
+ location: Location
29
29
  ) {
30
30
  const error = resolved.error;
31
31
  if (error instanceof YamlParseError) {
@@ -15,7 +15,7 @@ describe('oas2 boolean-parameter-prefixes', () => {
15
15
  in: path
16
16
  type: boolean
17
17
  `,
18
- 'foobar.yaml',
18
+ 'foobar.yaml'
19
19
  );
20
20
 
21
21
  const results = await lintDocument({
@@ -67,7 +67,7 @@ describe('oas2 boolean-parameter-prefixes', () => {
67
67
  schema:
68
68
  type: boolean
69
69
  `,
70
- 'foobar.yaml',
70
+ 'foobar.yaml'
71
71
  );
72
72
 
73
73
  const results = await lintDocument({
@@ -91,7 +91,7 @@ describe('oas2 boolean-parameter-prefixes', () => {
91
91
  schema:
92
92
  type: boolean
93
93
  `,
94
- 'foobar.yaml',
94
+ 'foobar.yaml'
95
95
  );
96
96
 
97
97
  const results = await lintDocument({
@@ -20,7 +20,7 @@ describe('OpenAPI Schema 2.0', () => {
20
20
  expect(
21
21
  await lintDoc(source, {
22
22
  spec: 'error',
23
- }),
23
+ })
24
24
  ).toMatchInlineSnapshot(`
25
25
  Array [
26
26
  Object {
@@ -50,7 +50,7 @@ describe('OpenAPI Schema 2.0', () => {
50
50
  expect(
51
51
  await lintDoc(source, {
52
52
  spec: 'error',
53
- }),
53
+ })
54
54
  ).toMatchInlineSnapshot(`
55
55
  Array [
56
56
  Object {
@@ -80,7 +80,7 @@ describe('OpenAPI Schema 2.0', () => {
80
80
  expect(
81
81
  await lintDoc(source, {
82
82
  spec: 'error',
83
- }),
83
+ })
84
84
  ).toMatchInlineSnapshot(`
85
85
  Array [
86
86
  Object {
@@ -114,7 +114,7 @@ describe('OpenAPI Schema 2.0', () => {
114
114
  expect(
115
115
  await lintDoc(source, {
116
116
  spec: 'error',
117
- }),
117
+ })
118
118
  ).toMatchInlineSnapshot(`Array []`);
119
119
  });
120
120
 
@@ -140,7 +140,7 @@ describe('OpenAPI Schema 2.0', () => {
140
140
  expect(
141
141
  await lintDoc(source, {
142
142
  spec: 'error',
143
- }),
143
+ })
144
144
  ).toMatchInlineSnapshot(`
145
145
  Array [
146
146
  Object {
@@ -173,7 +173,7 @@ describe('OpenAPI Schema 2.0', () => {
173
173
  expect(
174
174
  await lintDoc(source, {
175
175
  spec: 'error',
176
- }),
176
+ })
177
177
  ).toMatchInlineSnapshot(`
178
178
  Array [
179
179
  Object {
@@ -205,7 +205,7 @@ describe('OpenAPI Schema 2.0', () => {
205
205
  expect(
206
206
  await lintDoc(source, {
207
207
  spec: 'error',
208
- }),
208
+ })
209
209
  ).toMatchInlineSnapshot(`Array []`);
210
210
  });
211
211
 
@@ -229,7 +229,7 @@ describe('OpenAPI Schema 2.0', () => {
229
229
  expect(
230
230
  await lintDoc(source, {
231
231
  spec: 'error',
232
- }),
232
+ })
233
233
  ).toMatchInlineSnapshot(`
234
234
  Array [
235
235
  Object {
@@ -261,7 +261,7 @@ describe('OpenAPI Schema 2.0', () => {
261
261
  expect(
262
262
  await lintDoc(source, {
263
263
  spec: 'error',
264
- }),
264
+ })
265
265
  ).toMatchInlineSnapshot(`
266
266
  Array [
267
267
  Object {
@@ -292,7 +292,7 @@ describe('OpenAPI Schema 2.0', () => {
292
292
  expect(
293
293
  await lintDoc(source, {
294
294
  spec: 'error',
295
- }),
295
+ })
296
296
  ).toMatchInlineSnapshot(`Array []`);
297
297
  });
298
298
 
@@ -313,7 +313,7 @@ describe('OpenAPI Schema 2.0', () => {
313
313
  expect(
314
314
  await lintDoc(source, {
315
315
  spec: 'error',
316
- }),
316
+ })
317
317
  ).toMatchInlineSnapshot(`
318
318
  Array [
319
319
  Object {
@@ -342,7 +342,7 @@ describe('OpenAPI Schema 2.0', () => {
342
342
  expect(
343
343
  await lintDoc(source, {
344
344
  spec: 'error',
345
- }),
345
+ })
346
346
  ).toMatchInlineSnapshot(`
347
347
  Array [
348
348
  Object {
@@ -20,7 +20,7 @@ describe('OpenAPI Schema 2.0', () => {
20
20
  expect(
21
21
  await lintDoc(source, {
22
22
  spec: 'error',
23
- }),
23
+ })
24
24
  ).toMatchInlineSnapshot(`Array []`);
25
25
  });
26
26
 
@@ -47,7 +47,7 @@ describe('OpenAPI Schema 2.0', () => {
47
47
  expect(
48
48
  await lintDoc(source, {
49
49
  spec: 'error',
50
- }),
50
+ })
51
51
  ).toMatchInlineSnapshot(`Array []`);
52
52
  });
53
53
 
@@ -81,7 +81,7 @@ describe('OpenAPI Schema 2.0', () => {
81
81
  expect(
82
82
  await lintDoc(source, {
83
83
  spec: 'error',
84
- }),
84
+ })
85
85
  ).toMatchInlineSnapshot(`Array []`);
86
86
  });
87
87
 
@@ -117,7 +117,7 @@ describe('OpenAPI Schema 2.0', () => {
117
117
  expect(
118
118
  await lintDoc(source, {
119
119
  spec: 'error',
120
- }),
120
+ })
121
121
  ).toMatchInlineSnapshot(`Array []`);
122
122
  });
123
123
  });
@@ -20,7 +20,7 @@ describe('OpenAPI Schema', () => {
20
20
  expect(
21
21
  await lintDoc(source, {
22
22
  spec: 'error',
23
- }),
23
+ })
24
24
  ).toMatchInlineSnapshot(`Array []`);
25
25
  });
26
26
 
@@ -37,7 +37,7 @@ describe('OpenAPI Schema', () => {
37
37
  expect(
38
38
  await lintDoc(source, {
39
39
  spec: 'error',
40
- }),
40
+ })
41
41
  ).toMatchInlineSnapshot(`Array []`);
42
42
  });
43
43
 
@@ -52,7 +52,7 @@ describe('OpenAPI Schema', () => {
52
52
  expect(
53
53
  await lintDoc(source, {
54
54
  spec: 'error',
55
- }),
55
+ })
56
56
  ).toMatchInlineSnapshot(`
57
57
  Array [
58
58
  Object {
@@ -76,7 +76,7 @@ describe('OpenAPI Schema', () => {
76
76
  expect(
77
77
  await lintDoc(source, {
78
78
  spec: 'error',
79
- }),
79
+ })
80
80
  ).toMatchInlineSnapshot(`Array []`);
81
81
  });
82
82
 
@@ -99,7 +99,7 @@ describe('OpenAPI Schema', () => {
99
99
  expect(
100
100
  await lintDoc(source, {
101
101
  spec: 'error',
102
- }),
102
+ })
103
103
  ).toMatchInlineSnapshot(`
104
104
  Array [
105
105
  Object {
@@ -133,7 +133,7 @@ describe('OpenAPI Schema', () => {
133
133
  expect(
134
134
  await lintDoc(source, {
135
135
  'paths-identical': 'error',
136
- }),
136
+ })
137
137
  ).toMatchInlineSnapshot(`Array []`);
138
138
  });
139
139
 
@@ -160,7 +160,7 @@ describe('OpenAPI Schema', () => {
160
160
  expect(
161
161
  await lintDoc(source, {
162
162
  spec: 'error',
163
- }),
163
+ })
164
164
  ).toMatchInlineSnapshot(`Array []`);
165
165
  });
166
166
 
@@ -187,7 +187,7 @@ describe('OpenAPI Schema', () => {
187
187
  expect(
188
188
  await lintDoc(source, {
189
189
  spec: 'error',
190
- }),
190
+ })
191
191
  ).toMatchInlineSnapshot(`Array []`);
192
192
  });
193
193
 
@@ -205,7 +205,7 @@ describe('OpenAPI Schema', () => {
205
205
  expect(
206
206
  await lintDoc(source, {
207
207
  spec: 'error',
208
- }),
208
+ })
209
209
  ).toMatchInlineSnapshot(`Array []`);
210
210
  });
211
211
 
@@ -239,7 +239,7 @@ describe('OpenAPI Schema', () => {
239
239
  expect(
240
240
  await lintDoc(source, {
241
241
  spec: 'error',
242
- }),
242
+ })
243
243
  ).toMatchInlineSnapshot(`Array []`);
244
244
  });
245
245
  });
@@ -1,5 +1,9 @@
1
1
  import { outdent } from 'outdent';
2
- import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../../__tests__/utils';
2
+ import {
3
+ parseYamlToDocument,
4
+ replaceSourceWithRef,
5
+ makeConfig,
6
+ } from '../../../../../__tests__/utils';
3
7
  import { lintDocument } from '../../../../lint';
4
8
  import { BaseResolver } from '../../../../resolve';
5
9
 
@@ -15,7 +19,7 @@ describe('Referenceable scalars', () => {
15
19
  $ref: fixtures/description.md
16
20
  paths: {}
17
21
  `,
18
- __dirname + '/foobar.yaml',
22
+ __dirname + '/foobar.yaml'
19
23
  );
20
24
 
21
25
  const results = await lintDocument({
@@ -1,25 +1,25 @@
1
- import { LintConfig, RuleConfig, resolveLint } from '../../../../config';
1
+ import { StyleguideConfig, RuleConfig, resolveStyleguideConfig } from '../../../../config';
2
2
  import { parseYamlToDocument } from '../../../../../__tests__/utils';
3
3
  import { lintDocument } from '../../../../lint';
4
4
  import { BaseResolver } from '../../../../resolve';
5
5
 
6
6
  export async function lintDoc(
7
7
  source: string,
8
- rules: Record<string, RuleConfig> = { spec: 'error' },
8
+ rules: Record<string, RuleConfig> = { spec: 'error' }
9
9
  ) {
10
10
  const document = parseYamlToDocument(source, 'foobar.yaml');
11
11
 
12
12
  const results = await lintDocument({
13
13
  externalRefResolver: new BaseResolver(),
14
14
  document,
15
- config: new LintConfig(
16
- await resolveLint({
17
- lintConfig: {
15
+ config: new StyleguideConfig(
16
+ await resolveStyleguideConfig({
17
+ styleguideConfig: {
18
18
  plugins: [],
19
19
  extends: [],
20
20
  rules,
21
21
  },
22
- }),
22
+ })
23
23
  ),
24
24
  });
25
25
 
@@ -4,8 +4,8 @@ import { NoInvalidSchemaExamples } from '../common/no-invalid-schema-examples';
4
4
  import { NoInvalidParameterExamples } from '../common/no-invalid-parameter-examples';
5
5
  import { InfoDescription } from '../common/info-description';
6
6
  import { InfoContact } from '../common/info-contact';
7
- import { InfoLicense } from '../common/info-license-url';
8
- import { InfoLicenseUrl } from '../common/license-url';
7
+ import { InfoLicense } from '../common/info-license';
8
+ import { InfoLicenseUrl } from '../common/info-license-url';
9
9
  import { BooleanParameterPrefixes } from './boolean-parameter-prefixes';
10
10
  import { TagDescription } from '../common/tag-description';
11
11
  import { TagsAlphabetical } from '../common/tags-alphabetical';
@@ -57,7 +57,7 @@ export const rules = {
57
57
  'no-path-trailing-slash': NoPathTrailingSlash as Oas2Rule,
58
58
  'operation-2xx-response': Operation2xxResponse as Oas2Rule,
59
59
  'operation-4xx-response': Operation4xxResponse as Oas2Rule,
60
- 'assertions': Assertions as Oas2Rule,
60
+ assertions: Assertions as Oas2Rule,
61
61
  'operation-operationId-unique': OperationIdUnique as Oas2Rule,
62
62
  'operation-parameters-unique': OperationParametersUnique as Oas2Rule,
63
63
  'path-parameters-defined': PathParamsDefined as Oas2Rule,