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

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 (193) hide show
  1. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  2. package/lib/benchmark/benches/resolve-with-no-external.bench.js +1 -1
  3. package/lib/bundle.d.ts +1 -1
  4. package/lib/bundle.js +9 -6
  5. package/lib/config/all.js +5 -3
  6. package/lib/config/config-resolvers.js +32 -14
  7. package/lib/config/config.d.ts +3 -5
  8. package/lib/config/config.js +7 -4
  9. package/lib/config/load.d.ts +7 -0
  10. package/lib/config/load.js +14 -6
  11. package/lib/config/minimal.js +7 -4
  12. package/lib/config/recommended.js +7 -4
  13. package/lib/config/rules.d.ts +1 -1
  14. package/lib/config/rules.js +1 -1
  15. package/lib/config/types.d.ts +7 -0
  16. package/lib/config/utils.d.ts +2 -2
  17. package/lib/config/utils.js +49 -11
  18. package/lib/decorators/common/registry-dependencies.js +2 -2
  19. package/lib/env.d.ts +3 -0
  20. package/lib/env.js +8 -0
  21. package/lib/format/codeframes.js +16 -10
  22. package/lib/format/format.d.ts +1 -1
  23. package/lib/format/format.js +49 -26
  24. package/lib/index.d.ts +5 -5
  25. package/lib/index.js +3 -1
  26. package/lib/js-yaml/index.js +1 -0
  27. package/lib/lint.js +2 -2
  28. package/lib/logger.d.ts +10 -0
  29. package/lib/logger.js +31 -0
  30. package/lib/output.d.ts +3 -0
  31. package/lib/output.js +9 -0
  32. package/lib/redocly/index.js +10 -9
  33. package/lib/redocly/registry-api-types.d.ts +28 -30
  34. package/lib/redocly/registry-api.d.ts +3 -3
  35. package/lib/redocly/registry-api.js +7 -1
  36. package/lib/ref-utils.js +2 -1
  37. package/lib/resolve.d.ts +1 -1
  38. package/lib/resolve.js +4 -2
  39. package/lib/rules/ajv.d.ts +1 -1
  40. package/lib/rules/ajv.js +7 -7
  41. package/lib/rules/common/assertions/asserts.js +4 -4
  42. package/lib/rules/common/assertions/index.js +1 -1
  43. package/lib/rules/common/no-ambiguous-paths.js +1 -1
  44. package/lib/rules/common/no-identical-paths.js +1 -1
  45. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  46. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  47. package/lib/rules/common/operation-2xx-response.js +1 -1
  48. package/lib/rules/common/operation-4xx-response.js +1 -1
  49. package/lib/rules/common/operation-operationId.js +1 -1
  50. package/lib/rules/common/operation-tag-defined.js +1 -1
  51. package/lib/rules/common/path-not-include-query.js +1 -1
  52. package/lib/rules/common/security-defined.d.ts +2 -0
  53. package/lib/rules/common/{operation-security-defined.js → security-defined.js} +19 -5
  54. package/lib/rules/common/spec.js +14 -3
  55. package/lib/rules/common/tags-alphabetical.js +1 -1
  56. package/lib/rules/oas2/index.d.ts +1 -1
  57. package/lib/rules/oas2/index.js +2 -2
  58. package/lib/rules/oas2/remove-unused-components.js +3 -3
  59. package/lib/rules/oas2/request-mime-type.js +1 -1
  60. package/lib/rules/oas2/response-mime-type.js +1 -1
  61. package/lib/rules/oas3/index.js +8 -4
  62. package/lib/rules/oas3/no-empty-servers.js +1 -1
  63. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  64. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  65. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +5 -5
  66. package/lib/rules/oas3/no-unused-components.js +2 -2
  67. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
  68. package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
  69. package/lib/rules/oas3/remove-unused-components.js +4 -4
  70. package/lib/rules/oas3/request-mime-type.js +1 -1
  71. package/lib/rules/oas3/response-mime-type.js +1 -1
  72. package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
  73. package/lib/rules/oas3/spec-components-invalid-map-name.js +46 -0
  74. package/lib/rules/other/stats.d.ts +2 -2
  75. package/lib/rules/other/stats.js +2 -2
  76. package/lib/rules/utils.d.ts +3 -2
  77. package/lib/rules/utils.js +16 -4
  78. package/lib/types/oas2.js +5 -5
  79. package/lib/types/oas3.js +27 -20
  80. package/lib/types/oas3_1.js +3 -3
  81. package/lib/types/redocly-yaml.js +47 -56
  82. package/lib/utils.d.ts +6 -1
  83. package/lib/utils.js +24 -7
  84. package/lib/visitors.d.ts +12 -12
  85. package/lib/visitors.js +15 -3
  86. package/lib/walk.d.ts +2 -1
  87. package/lib/walk.js +6 -3
  88. package/package.json +2 -2
  89. package/src/__tests__/__snapshots__/bundle.test.ts.snap +3 -3
  90. package/src/__tests__/fixtures/extension.js +3 -3
  91. package/src/__tests__/format.test.ts +76 -0
  92. package/src/__tests__/lint.test.ts +106 -131
  93. package/src/__tests__/logger-browser.test.ts +53 -0
  94. package/src/__tests__/logger.test.ts +47 -0
  95. package/src/__tests__/output-browser.test.ts +18 -0
  96. package/src/__tests__/output.test.ts +15 -0
  97. package/src/__tests__/resolve-http.test.ts +1 -1
  98. package/src/__tests__/resolve.test.ts +9 -9
  99. package/src/__tests__/utils-browser.test.ts +11 -0
  100. package/src/__tests__/utils.test.ts +7 -0
  101. package/src/__tests__/walk.test.ts +78 -10
  102. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
  103. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  104. package/src/bundle.ts +10 -7
  105. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +12 -6
  106. package/src/config/__tests__/config.test.ts +35 -0
  107. package/src/config/__tests__/fixtures/plugin-config.yaml +2 -3
  108. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -12
  109. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -8
  110. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -19
  111. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -10
  112. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -4
  113. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -5
  114. package/src/config/__tests__/load.test.ts +76 -1
  115. package/src/config/__tests__/utils.test.ts +64 -4
  116. package/src/config/all.ts +5 -3
  117. package/src/config/config-resolvers.ts +45 -19
  118. package/src/config/config.ts +10 -8
  119. package/src/config/load.ts +31 -7
  120. package/src/config/minimal.ts +7 -4
  121. package/src/config/recommended.ts +7 -4
  122. package/src/config/rules.ts +2 -2
  123. package/src/config/types.ts +11 -0
  124. package/src/config/utils.ts +115 -25
  125. package/src/decorators/common/registry-dependencies.ts +2 -2
  126. package/src/env.ts +5 -0
  127. package/src/format/codeframes.ts +15 -9
  128. package/src/format/format.ts +59 -34
  129. package/src/index.ts +6 -4
  130. package/src/js-yaml/index.ts +1 -0
  131. package/src/lint.ts +2 -2
  132. package/src/logger.ts +34 -0
  133. package/src/output.ts +7 -0
  134. package/src/redocly/index.ts +7 -4
  135. package/src/redocly/registry-api-types.ts +27 -29
  136. package/src/redocly/registry-api.ts +18 -7
  137. package/src/ref-utils.ts +2 -1
  138. package/src/resolve.ts +7 -5
  139. package/src/rules/__tests__/utils.test.ts +39 -1
  140. package/src/rules/ajv.ts +7 -7
  141. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -0
  142. package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -1
  143. package/src/rules/common/__tests__/operation-4xx-response.test.ts +26 -3
  144. package/src/rules/common/__tests__/security-defined.test.ts +175 -0
  145. package/src/rules/common/__tests__/spec.test.ts +79 -0
  146. package/src/rules/common/assertions/__tests__/utils.test.ts +2 -2
  147. package/src/rules/common/assertions/asserts.ts +4 -4
  148. package/src/rules/common/assertions/index.ts +1 -1
  149. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  150. package/src/rules/common/no-identical-paths.ts +1 -1
  151. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  152. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  153. package/src/rules/common/operation-2xx-response.ts +1 -1
  154. package/src/rules/common/operation-4xx-response.ts +1 -1
  155. package/src/rules/common/operation-operationId.ts +1 -1
  156. package/src/rules/common/operation-tag-defined.ts +1 -1
  157. package/src/rules/common/path-not-include-query.ts +1 -1
  158. package/src/rules/common/{operation-security-defined.ts → security-defined.ts} +20 -5
  159. package/src/rules/common/spec.ts +17 -3
  160. package/src/rules/common/tags-alphabetical.ts +1 -1
  161. package/src/rules/oas2/index.ts +2 -2
  162. package/src/rules/oas2/remove-unused-components.ts +3 -3
  163. package/src/rules/oas2/request-mime-type.ts +1 -1
  164. package/src/rules/oas2/response-mime-type.ts +1 -1
  165. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  166. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +5 -5
  167. package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
  168. package/src/rules/oas3/__tests__/spec/spec.test.ts +10 -0
  169. package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +217 -0
  170. package/src/rules/oas3/index.ts +8 -4
  171. package/src/rules/oas3/no-empty-servers.ts +1 -1
  172. package/src/rules/oas3/no-invalid-media-type-examples.ts +3 -3
  173. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +3 -3
  174. package/src/rules/oas3/no-unused-components.ts +2 -2
  175. package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +36 -0
  176. package/src/rules/oas3/remove-unused-components.ts +5 -5
  177. package/src/rules/oas3/request-mime-type.ts +1 -1
  178. package/src/rules/oas3/response-mime-type.ts +1 -1
  179. package/src/rules/oas3/spec-components-invalid-map-name.ts +53 -0
  180. package/src/rules/other/stats.ts +2 -2
  181. package/src/rules/utils.ts +17 -3
  182. package/src/types/index.ts +2 -2
  183. package/src/types/oas2.ts +5 -5
  184. package/src/types/oas3.ts +27 -20
  185. package/src/types/oas3_1.ts +3 -3
  186. package/src/types/redocly-yaml.ts +53 -41
  187. package/src/utils.ts +31 -4
  188. package/src/visitors.ts +34 -18
  189. package/src/walk.ts +15 -11
  190. package/tsconfig.tsbuildinfo +1 -1
  191. package/lib/rules/common/operation-security-defined.d.ts +0 -2
  192. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  193. package/src/rules/common/__tests__/operation-security-defined.test.ts +0 -69
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RemoveUnusedComponents = void 0;
4
4
  const utils_1 = require("../../utils");
5
5
  const RemoveUnusedComponents = () => {
6
- let components = new Map();
6
+ const components = new Map();
7
7
  function registerComponent(location, componentType, name) {
8
8
  var _a;
9
9
  components.set(location.absolutePointer, {
@@ -26,14 +26,14 @@ const RemoveUnusedComponents = () => {
26
26
  }
27
27
  },
28
28
  },
29
- DefinitionRoot: {
29
+ Root: {
30
30
  leave(root, ctx) {
31
31
  const data = ctx.getVisitorData();
32
32
  data.removedCount = 0;
33
33
  components.forEach((usageInfo) => {
34
34
  const { used, componentType, name } = usageInfo;
35
- if (!used && componentType) {
36
- let componentChild = root.components[componentType];
35
+ if (!used && componentType && root.components) {
36
+ const componentChild = root.components[componentType];
37
37
  delete componentChild[name];
38
38
  data.removedCount++;
39
39
  if (utils_1.isEmptyObject(componentChild)) {
@@ -4,7 +4,7 @@ exports.RequestMimeType = void 0;
4
4
  const utils_1 = require("../../utils");
5
5
  const RequestMimeType = ({ allowedValues }) => {
6
6
  return {
7
- PathMap: {
7
+ PathsMap: {
8
8
  RequestBody: {
9
9
  leave(requestBody, ctx) {
10
10
  utils_1.validateMimeTypeOAS3({ type: 'consumes', value: requestBody }, ctx, allowedValues);
@@ -4,7 +4,7 @@ exports.ResponseMimeType = void 0;
4
4
  const utils_1 = require("../../utils");
5
5
  const ResponseMimeType = ({ allowedValues }) => {
6
6
  return {
7
- PathMap: {
7
+ PathsMap: {
8
8
  Response: {
9
9
  leave(response, ctx) {
10
10
  utils_1.validateMimeTypeOAS3({ type: 'produces', value: response }, ctx, allowedValues);
@@ -0,0 +1,2 @@
1
+ import { Oas3Rule } from '../../visitors';
2
+ export declare const SpecComponentsInvalidMapName: Oas3Rule;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpecComponentsInvalidMapName = void 0;
4
+ const SpecComponentsInvalidMapName = () => {
5
+ const KEYS_REGEX = '^[a-zA-Z0-9\\.\\-_]+$';
6
+ function validateKey(key, report, location, component) {
7
+ if (!new RegExp(KEYS_REGEX).test(key)) {
8
+ report({
9
+ message: `The map key in ${component} "${key}" does not match the regular expression "${KEYS_REGEX}"`,
10
+ location: location.key(),
11
+ });
12
+ }
13
+ }
14
+ return {
15
+ Components: {
16
+ Parameter(_node, { key, report, location }) {
17
+ validateKey(key, report, location, 'parameters');
18
+ },
19
+ Response(_node, { key, report, location }) {
20
+ validateKey(key, report, location, 'responses');
21
+ },
22
+ Schema(_node, { key, report, location }) {
23
+ validateKey(key, report, location, 'schemas');
24
+ },
25
+ Example(_node, { key, report, location }) {
26
+ validateKey(key, report, location, 'examples');
27
+ },
28
+ RequestBody(_node, { key, report, location }) {
29
+ validateKey(key, report, location, 'requestBodies');
30
+ },
31
+ Header(_node, { key, report, location }) {
32
+ validateKey(key, report, location, 'headers');
33
+ },
34
+ SecurityScheme(_node, { key, report, location }) {
35
+ validateKey(key, report, location, 'securitySchemas');
36
+ },
37
+ Link(_node, { key, report, location }) {
38
+ validateKey(key, report, location, 'links');
39
+ },
40
+ Callback(_node, { key, report, location }) {
41
+ validateKey(key, report, location, 'callbacks');
42
+ },
43
+ },
44
+ };
45
+ };
46
+ exports.SpecComponentsInvalidMapName = SpecComponentsInvalidMapName;
@@ -14,7 +14,7 @@ export declare const Stats: (statsAccumulator: StatsAccumulator) => {
14
14
  Link: {
15
15
  leave(link: any): void;
16
16
  };
17
- DefinitionRoot: {
17
+ Root: {
18
18
  leave(): void;
19
19
  };
20
20
  WebhooksMap: {
@@ -22,7 +22,7 @@ export declare const Stats: (statsAccumulator: StatsAccumulator) => {
22
22
  leave(operation: any): void;
23
23
  };
24
24
  };
25
- PathMap: {
25
+ PathsMap: {
26
26
  PathItem: {
27
27
  leave(): void;
28
28
  Operation: {
@@ -23,7 +23,7 @@ const Stats = (statsAccumulator) => {
23
23
  statsAccumulator.links.items.add(link.operationId);
24
24
  },
25
25
  },
26
- DefinitionRoot: {
26
+ Root: {
27
27
  leave() {
28
28
  statsAccumulator.parameters.total = statsAccumulator.parameters.items.size;
29
29
  statsAccumulator.refs.total = statsAccumulator.refs.items.size;
@@ -40,7 +40,7 @@ const Stats = (statsAccumulator) => {
40
40
  },
41
41
  },
42
42
  },
43
- PathMap: {
43
+ PathsMap: {
44
44
  PathItem: {
45
45
  leave() {
46
46
  statsAccumulator.pathItems.total++;
@@ -1,7 +1,7 @@
1
1
  import { UserContext } from '../walk';
2
2
  import { Location } from '../ref-utils';
3
3
  import { Oas3Schema, Referenced } from '../typings/openapi';
4
- export declare function oasTypeOf(value: unknown): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "integer" | "array" | "null";
4
+ export declare function oasTypeOf(value: unknown): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null" | "integer" | "array";
5
5
  /**
6
6
  * Checks if value matches specified JSON schema type
7
7
  *
@@ -14,4 +14,5 @@ export declare function missingRequiredField(type: string, field: string): strin
14
14
  export declare function fieldNonEmpty(type: string, field: string): string;
15
15
  export declare function validateDefinedAndNonEmpty(fieldName: string, value: any, ctx: UserContext): void;
16
16
  export declare function getSuggest(given: string, variants: string[]): string[];
17
- export declare function validateExample(example: any, schema: Referenced<Oas3Schema>, dataLoc: Location, { resolve, location, report }: UserContext, disallowAdditionalProperties: boolean): void;
17
+ export declare function validateExample(example: any, schema: Referenced<Oas3Schema>, dataLoc: Location, { resolve, location, report }: UserContext, allowAdditionalProperties: boolean): void;
18
+ export declare function getAdditionalPropertiesOption(opts: Record<string, any>): boolean;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateExample = exports.getSuggest = exports.validateDefinedAndNonEmpty = exports.fieldNonEmpty = exports.missingRequiredField = exports.matchesJsonSchemaType = exports.oasTypeOf = void 0;
3
+ exports.getAdditionalPropertiesOption = exports.validateExample = exports.getSuggest = exports.validateDefinedAndNonEmpty = exports.fieldNonEmpty = exports.missingRequiredField = exports.matchesJsonSchemaType = exports.oasTypeOf = void 0;
4
4
  const levenshtein = require("js-levenshtein");
5
5
  const ref_utils_1 = require("../ref-utils");
6
6
  const ajv_1 = require("./ajv");
7
+ const utils_1 = require("../utils");
7
8
  function oasTypeOf(value) {
8
9
  if (Array.isArray(value)) {
9
10
  return 'array';
@@ -85,11 +86,11 @@ function getSuggest(given, variants) {
85
86
  return distances.map((d) => d.variant);
86
87
  }
87
88
  exports.getSuggest = getSuggest;
88
- function validateExample(example, schema, dataLoc, { resolve, location, report }, disallowAdditionalProperties) {
89
+ function validateExample(example, schema, dataLoc, { resolve, location, report }, allowAdditionalProperties) {
89
90
  try {
90
- const { valid, errors } = ajv_1.validateJsonSchema(example, schema, location.child('schema'), dataLoc.pointer, resolve, disallowAdditionalProperties);
91
+ const { valid, errors } = ajv_1.validateJsonSchema(example, schema, location.child('schema'), dataLoc.pointer, resolve, allowAdditionalProperties);
91
92
  if (!valid) {
92
- for (let error of errors) {
93
+ for (const error of errors) {
93
94
  report({
94
95
  message: `Example value must conform to the schema: ${error.message}.`,
95
96
  location: Object.assign(Object.assign({}, new ref_utils_1.Location(dataLoc.source, error.instancePath)), { reportOnKey: error.keyword === 'additionalProperties' }),
@@ -108,3 +109,14 @@ function validateExample(example, schema, dataLoc, { resolve, location, report }
108
109
  }
109
110
  }
110
111
  exports.validateExample = validateExample;
112
+ function getAdditionalPropertiesOption(opts) {
113
+ if (opts.disallowAdditionalProperties === undefined) {
114
+ return opts.allowAdditionalProperties;
115
+ }
116
+ if (opts.allowAdditionalProperties !== undefined) {
117
+ utils_1.showErrorForDeprecatedField('disallowAdditionalProperties', 'allowAdditionalProperties');
118
+ }
119
+ utils_1.showWarningForDeprecatedField('disallowAdditionalProperties', 'allowAdditionalProperties');
120
+ return !opts.disallowAdditionalProperties;
121
+ }
122
+ exports.getAdditionalPropertiesOption = getAdditionalPropertiesOption;
package/lib/types/oas2.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Oas2Types = void 0;
4
4
  const _1 = require(".");
5
5
  const responseCodeRegexp = /^[0-9][0-9Xx]{2}$/;
6
- const DefinitionRoot = {
6
+ const Root = {
7
7
  properties: {
8
8
  swagger: { type: 'string' },
9
9
  info: 'Info',
@@ -12,7 +12,7 @@ const DefinitionRoot = {
12
12
  schemes: { type: 'array', items: { type: 'string' } },
13
13
  consumes: { type: 'array', items: { type: 'string' } },
14
14
  produces: { type: 'array', items: { type: 'string' } },
15
- paths: 'PathMap',
15
+ paths: 'PathsMap',
16
16
  definitions: 'NamedSchemas',
17
17
  parameters: 'NamedParameters',
18
18
  responses: 'NamedResponses',
@@ -48,7 +48,7 @@ const License = {
48
48
  },
49
49
  required: ['name'],
50
50
  };
51
- const PathMap = {
51
+ const PathsMap = {
52
52
  properties: {},
53
53
  additionalProperties: (_value, key) => key.startsWith('/') ? 'PathItem' : undefined,
54
54
  };
@@ -352,14 +352,14 @@ const SecurityRequirement = {
352
352
  additionalProperties: { type: 'array', items: { type: 'string' } },
353
353
  };
354
354
  exports.Oas2Types = {
355
- DefinitionRoot,
355
+ Root,
356
356
  Tag,
357
357
  ExternalDocs,
358
358
  SecurityRequirement,
359
359
  Info,
360
360
  Contact,
361
361
  License,
362
- PathMap,
362
+ PathsMap,
363
363
  PathItem,
364
364
  Parameter,
365
365
  ParameterItems,
package/lib/types/oas3.js CHANGED
@@ -4,7 +4,7 @@ exports.Oas3Types = void 0;
4
4
  const _1 = require(".");
5
5
  const ref_utils_1 = require("../ref-utils");
6
6
  const responseCodeRegexp = /^[0-9][0-9Xx]{2}$/;
7
- const DefinitionRoot = {
7
+ const Root = {
8
8
  properties: {
9
9
  openapi: null,
10
10
  info: 'Info',
@@ -12,7 +12,7 @@ const DefinitionRoot = {
12
12
  security: _1.listOf('SecurityRequirement'),
13
13
  tags: _1.listOf('Tag'),
14
14
  externalDocs: 'ExternalDocs',
15
- paths: 'PathMap',
15
+ paths: 'PathsMap',
16
16
  components: 'Components',
17
17
  'x-webhooks': 'WebhooksMap',
18
18
  },
@@ -37,7 +37,7 @@ const Server = {
37
37
  properties: {
38
38
  url: { type: 'string' },
39
39
  description: { type: 'string' },
40
- variables: _1.mapOf('ServerVariable'),
40
+ variables: 'ServerVariablesMap',
41
41
  },
42
42
  required: ['url'],
43
43
  };
@@ -81,7 +81,7 @@ const License = {
81
81
  },
82
82
  required: ['name'],
83
83
  };
84
- const PathMap = {
84
+ const PathsMap = {
85
85
  properties: {},
86
86
  additionalProperties: (_value, key) => key.startsWith('/') ? 'PathItem' : undefined,
87
87
  };
@@ -121,8 +121,8 @@ const Parameter = {
121
121
  allowReserved: { type: 'boolean' },
122
122
  schema: 'Schema',
123
123
  example: { isExample: true },
124
- examples: _1.mapOf('Example'),
125
- content: 'MediaTypeMap',
124
+ examples: 'ExamplesMap',
125
+ content: 'MediaTypesMap',
126
126
  },
127
127
  required: ['name', 'in'],
128
128
  requiredOneOf: ['schema', 'content'],
@@ -143,7 +143,7 @@ const Operation = {
143
143
  requestBody: 'RequestBody',
144
144
  responses: 'ResponsesMap',
145
145
  deprecated: { type: 'boolean' },
146
- callbacks: _1.mapOf('Callback'),
146
+ callbacks: 'CallbacksMap',
147
147
  'x-codeSamples': _1.listOf('XCodeSample'),
148
148
  'x-code-samples': _1.listOf('XCodeSample'),
149
149
  'x-hideTryItPanel': { type: 'boolean' },
@@ -161,11 +161,11 @@ const RequestBody = {
161
161
  properties: {
162
162
  description: { type: 'string' },
163
163
  required: { type: 'boolean' },
164
- content: 'MediaTypeMap',
164
+ content: 'MediaTypesMap',
165
165
  },
166
166
  required: ['content'],
167
167
  };
168
- const MediaTypeMap = {
168
+ const MediaTypesMap = {
169
169
  properties: {},
170
170
  additionalProperties: 'MediaType',
171
171
  };
@@ -173,8 +173,8 @@ const MediaType = {
173
173
  properties: {
174
174
  schema: 'Schema',
175
175
  example: { isExample: true },
176
- examples: _1.mapOf('Example'),
177
- encoding: _1.mapOf('Encoding'),
176
+ examples: 'ExamplesMap',
177
+ encoding: 'EncodingsMap',
178
178
  },
179
179
  };
180
180
  const Example = {
@@ -188,7 +188,7 @@ const Example = {
188
188
  const Encoding = {
189
189
  properties: {
190
190
  contentType: { type: 'string' },
191
- headers: _1.mapOf('Header'),
191
+ headers: 'HeadersMap',
192
192
  style: {
193
193
  enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
194
194
  },
@@ -209,9 +209,10 @@ const Header = {
209
209
  allowReserved: { type: 'boolean' },
210
210
  schema: 'Schema',
211
211
  example: { isExample: true },
212
- examples: _1.mapOf('Example'),
213
- content: 'MediaTypeMap',
212
+ examples: 'ExamplesMap',
213
+ content: 'MediaTypesMap',
214
214
  },
215
+ requiredOneOf: ['schema', 'content'],
215
216
  };
216
217
  const ResponsesMap = {
217
218
  properties: { default: 'Response' },
@@ -220,9 +221,9 @@ const ResponsesMap = {
220
221
  const Response = {
221
222
  properties: {
222
223
  description: { type: 'string' },
223
- headers: _1.mapOf('Header'),
224
- content: 'MediaTypeMap',
225
- links: _1.mapOf('Link'),
224
+ headers: 'HeadersMap',
225
+ content: 'MediaTypesMap',
226
+ links: 'LinksMap',
226
227
  },
227
228
  required: ['description'],
228
229
  };
@@ -427,26 +428,31 @@ const SecurityScheme = {
427
428
  extensionsPrefix: 'x-',
428
429
  };
429
430
  exports.Oas3Types = {
430
- DefinitionRoot,
431
+ Root,
431
432
  Tag,
432
433
  ExternalDocs,
433
434
  Server,
434
435
  ServerVariable,
436
+ ServerVariablesMap: _1.mapOf('ServerVariable'),
435
437
  SecurityRequirement,
436
438
  Info,
437
439
  Contact,
438
440
  License,
439
- PathMap,
441
+ PathsMap,
440
442
  PathItem,
441
443
  Parameter,
442
444
  Operation,
443
445
  Callback: _1.mapOf('PathItem'),
446
+ CallbacksMap: _1.mapOf('Callback'),
444
447
  RequestBody,
445
- MediaTypeMap,
448
+ MediaTypesMap,
446
449
  MediaType,
447
450
  Example,
451
+ ExamplesMap: _1.mapOf('Example'),
448
452
  Encoding,
453
+ EncodingsMap: _1.mapOf('Encoding'),
449
454
  Header,
455
+ HeadersMap: _1.mapOf('Header'),
450
456
  ResponsesMap,
451
457
  Response,
452
458
  Link,
@@ -456,6 +462,7 @@ exports.Oas3Types = {
456
462
  DiscriminatorMapping,
457
463
  Discriminator,
458
464
  Components,
465
+ LinksMap: _1.mapOf('Link'),
459
466
  NamedSchemas: _1.mapOf('Schema'),
460
467
  NamedResponses: _1.mapOf('Response'),
461
468
  NamedParameters: _1.mapOf('Parameter'),
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Oas3_1Types = void 0;
4
4
  const _1 = require(".");
5
5
  const oas3_1 = require("./oas3");
6
- const DefinitionRoot = {
6
+ const Root = {
7
7
  properties: {
8
8
  openapi: null,
9
9
  info: 'Info',
@@ -11,7 +11,7 @@ const DefinitionRoot = {
11
11
  security: _1.listOf('SecurityRequirement'),
12
12
  tags: _1.listOf('Tag'),
13
13
  externalDocs: 'ExternalDocs',
14
- paths: 'PathMap',
14
+ paths: 'PathsMap',
15
15
  webhooks: 'WebhooksMap',
16
16
  components: 'Components',
17
17
  jsonSchemaDialect: { type: 'string' },
@@ -237,7 +237,7 @@ const SecurityScheme = {
237
237
  extensionsPrefix: 'x-',
238
238
  };
239
239
  exports.Oas3_1Types = Object.assign(Object.assign({}, oas3_1.Oas3Types), { Info,
240
- DefinitionRoot,
240
+ Root,
241
241
  Schema,
242
242
  License,
243
243
  Components, NamedPathItems: _1.mapOf('PathItem'), SecurityScheme,
@@ -11,6 +11,7 @@ const builtInRulesList = [
11
11
  'info-license-url',
12
12
  'operation-2xx-response',
13
13
  'operation-4xx-response',
14
+ 'operation-4xx-problem-details-rfc7807',
14
15
  'assertions',
15
16
  'operation-operationId-unique',
16
17
  'operation-parameters-unique',
@@ -34,7 +35,7 @@ const builtInRulesList = [
34
35
  'path-params-defined',
35
36
  'parameter-description',
36
37
  'operation-singular-tag',
37
- 'operation-security-defined',
38
+ 'security-defined',
38
39
  'no-unresolved-refs',
39
40
  'paths-kebab-case',
40
41
  'boolean-parameter-prefixes',
@@ -43,7 +44,7 @@ const builtInRulesList = [
43
44
  'no-identical-paths',
44
45
  'no-ambiguous-paths',
45
46
  'no-undefined-server-variable',
46
- 'no-servers-empty-enum',
47
+ 'no-server-variables-empty-enum',
47
48
  'no-http-verbs-in-paths',
48
49
  'path-excludes-patterns',
49
50
  'request-mime-type',
@@ -54,31 +55,38 @@ const builtInRulesList = [
54
55
  'response-contains-header',
55
56
  'response-contains-property',
56
57
  'scalar-property-missing-example',
58
+ 'spec-components-invalid-map-name',
57
59
  ];
58
60
  const nodeTypesList = [
59
- 'DefinitionRoot',
61
+ 'Root',
60
62
  'Tag',
61
63
  'ExternalDocs',
62
64
  'Server',
63
65
  'ServerVariable',
66
+ 'ServerVariablesMap',
64
67
  'SecurityRequirement',
65
68
  'Info',
66
69
  'Contact',
67
70
  'License',
68
- 'PathMap',
71
+ 'PathsMap',
69
72
  'PathItem',
70
73
  'Parameter',
71
74
  'Operation',
72
75
  'Callback',
76
+ 'CallbacksMap',
73
77
  'RequestBody',
74
- 'MediaTypeMap',
78
+ 'MediaTypesMap',
75
79
  'MediaType',
76
80
  'Example',
81
+ 'ExamplesMap',
77
82
  'Encoding',
83
+ 'EncodingsMap',
78
84
  'Header',
85
+ 'HeadersMap',
79
86
  'ResponsesMap',
80
87
  'Response',
81
88
  'Link',
89
+ 'LinksMap',
82
90
  'Schema',
83
91
  'Xml',
84
92
  'SchemaProperties',
@@ -103,45 +111,57 @@ const nodeTypesList = [
103
111
  'XCodeSample',
104
112
  'WebhooksMap',
105
113
  ];
106
- const ConfigRoot = {
114
+ const ConfigStyleguide = {
107
115
  properties: {
108
- organization: { type: 'string' },
109
- apis: 'ConfigApis',
110
- apiDefinitions: {
116
+ extends: {
117
+ type: 'array',
118
+ items: {
119
+ type: 'string',
120
+ },
121
+ },
122
+ rules: 'Rules',
123
+ oas2Rules: 'Rules',
124
+ oas3_0Rules: 'Rules',
125
+ oas3_1Rules: 'Rules',
126
+ preprocessors: { type: 'object' },
127
+ oas2Preprocessors: { type: 'object' },
128
+ oas3_0Preprocessors: { type: 'object' },
129
+ oas3_1Preprocessors: { type: 'object' },
130
+ decorators: { type: 'object' },
131
+ oas2Decorators: { type: 'object' },
132
+ oas3_0Decorators: { type: 'object' },
133
+ oas3_1Decorators: { type: 'object' },
134
+ },
135
+ };
136
+ const RootConfigStyleguide = {
137
+ properties: Object.assign({ plugins: {
138
+ type: 'array',
139
+ items: { type: 'string' },
140
+ } }, ConfigStyleguide.properties),
141
+ };
142
+ const ConfigRoot = {
143
+ properties: Object.assign(Object.assign({ organization: { type: 'string' }, apis: 'ConfigApis', apiDefinitions: {
111
144
  type: 'object',
112
145
  properties: {},
113
146
  additionalProperties: { properties: { type: 'string' } },
114
- },
115
- styleguide: 'RootConfigStyleguide',
116
- lint: 'RootConfigStyleguide',
117
- 'features.openapi': 'ConfigReferenceDocs',
118
- referenceDocs: 'ConfigReferenceDocs',
119
- 'features.mockServer': 'ConfigMockServer',
120
- region: { enum: ['us', 'eu'] },
121
- resolve: {
147
+ } }, RootConfigStyleguide.properties), { styleguide: 'RootConfigStyleguide', lint: 'RootConfigStyleguide', 'features.openapi': 'ConfigReferenceDocs', referenceDocs: 'ConfigReferenceDocs', 'features.mockServer': 'ConfigMockServer', region: { enum: ['us', 'eu'] }, resolve: {
122
148
  properties: {
123
149
  http: 'ConfigHTTP',
150
+ doNotResolveExamples: { type: 'boolean' },
124
151
  },
125
- },
126
- },
152
+ } }),
127
153
  };
128
154
  const ConfigApis = {
129
155
  properties: {},
130
156
  additionalProperties: 'ConfigApisProperties',
131
157
  };
132
158
  const ConfigApisProperties = {
133
- properties: {
134
- root: { type: 'string' },
135
- labels: {
159
+ properties: Object.assign(Object.assign({ root: { type: 'string' }, labels: {
136
160
  type: 'array',
137
161
  items: {
138
162
  type: 'string',
139
163
  },
140
- },
141
- styleguide: 'ConfigStyleguide',
142
- 'features.openapi': 'ConfigReferenceDocs',
143
- 'features.mockServer': 'ConfigMockServer',
144
- },
164
+ }, lint: 'ConfigStyleguide', styleguide: 'ConfigStyleguide' }, ConfigStyleguide.properties), { 'features.openapi': 'ConfigReferenceDocs', 'features.mockServer': 'ConfigMockServer' }),
145
165
  required: ['root'],
146
166
  };
147
167
  const ConfigHTTP = {
@@ -154,35 +174,6 @@ const ConfigHTTP = {
154
174
  },
155
175
  },
156
176
  };
157
- const ConfigStyleguide = {
158
- properties: {
159
- extends: {
160
- type: 'array',
161
- items: {
162
- type: 'string',
163
- },
164
- },
165
- doNotResolveExamples: { type: 'boolean' },
166
- rules: 'Rules',
167
- oas2Rules: 'Rules',
168
- oas3_0Rules: 'Rules',
169
- oas3_1Rules: 'Rules',
170
- preprocessors: { type: 'object' },
171
- oas2Preprocessors: { type: 'object' },
172
- oas3_0Preprocessors: { type: 'object' },
173
- oas3_1Preprocessors: { type: 'object' },
174
- decorators: { type: 'object' },
175
- oas2Decorators: { type: 'object' },
176
- oas3_0Decorators: { type: 'object' },
177
- oas3_1Decorators: { type: 'object' },
178
- },
179
- };
180
- const RootConfigStyleguide = {
181
- properties: Object.assign({ plugins: {
182
- type: 'array',
183
- items: { type: 'string' },
184
- } }, ConfigStyleguide.properties),
185
- };
186
177
  const Rules = {
187
178
  properties: {},
188
179
  additionalProperties: (value, key) => {
package/lib/utils.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare function pushStack<T, P extends Stack<T> = Stack<T>>(head: P, val
14
14
  export declare function popStack<T, P extends Stack<T>>(head: P): StackFrame<T> | null;
15
15
  export declare type BundleOutputFormat = 'json' | 'yml' | 'yaml';
16
16
  export declare function loadYaml<T>(filename: string): Promise<T>;
17
- export declare function notUndefined<T>(x: T | undefined): x is T;
17
+ export declare function isDefined<T>(x: T | undefined): x is T;
18
18
  export declare function isPlainObject(value: any): value is object;
19
19
  export declare function isEmptyObject(value: any): value is object;
20
20
  export declare function isEmptyArray(value: any): boolean;
@@ -41,3 +41,8 @@ export declare function assignExisting<T>(target: Record<string, T>, obj: Record
41
41
  export declare function getMatchingStatusCodeRange(code: number | string): string;
42
42
  export declare function isCustomRuleId(id: string): boolean;
43
43
  export declare function doesYamlFileExist(filePath: string): boolean;
44
+ export declare function showWarningForDeprecatedField(deprecatedField: string, updatedField?: string): void;
45
+ export declare function showErrorForDeprecatedField(deprecatedField: string, updatedField?: string): void;
46
+ export declare type Falsy = undefined | null | false | '' | 0;
47
+ export declare function isTruthy<Truthy>(value: Truthy | Falsy): value is Truthy;
48
+ export declare function identity<T>(value: T): T;