@redocly/openapi-core 1.0.0-beta.93 → 1.0.0-beta.96

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 (127) hide show
  1. package/README.md +1 -1
  2. package/__tests__/bundle.test.ts +6 -6
  3. package/__tests__/fixtures/extension.js +1 -1
  4. package/__tests__/login.test.ts +2 -2
  5. package/__tests__/normalizeVisitors.test.ts +1 -1
  6. package/__tests__/ref-utils.test.ts +1 -1
  7. package/__tests__/utils.ts +30 -18
  8. package/__tests__/walk.test.ts +6 -6
  9. package/lib/benchmark/benches/recommended-oas3.bench.js +2 -3
  10. package/lib/benchmark/utils.d.ts +2 -1
  11. package/lib/benchmark/utils.js +10 -7
  12. package/lib/bundle.d.ts +2 -2
  13. package/lib/config/all.d.ts +2 -2
  14. package/lib/config/builtIn.d.ts +1 -1
  15. package/lib/config/config-resolvers.d.ts +16 -0
  16. package/lib/config/config-resolvers.js +213 -0
  17. package/lib/config/config.d.ts +14 -129
  18. package/lib/config/config.js +17 -234
  19. package/lib/config/index.d.ts +7 -0
  20. package/lib/config/index.js +19 -0
  21. package/lib/config/load.d.ts +2 -1
  22. package/lib/config/load.js +20 -13
  23. package/lib/config/minimal.d.ts +2 -2
  24. package/lib/config/recommended.d.ts +2 -2
  25. package/lib/config/types.d.ts +113 -0
  26. package/lib/config/types.js +2 -0
  27. package/lib/config/utils.d.ts +13 -0
  28. package/lib/config/utils.js +160 -0
  29. package/lib/format/format.d.ts +1 -1
  30. package/lib/format/format.js +28 -0
  31. package/lib/index.d.ts +1 -2
  32. package/lib/index.js +5 -6
  33. package/lib/lint.d.ts +1 -1
  34. package/lib/lint.js +5 -7
  35. package/lib/redocly/index.d.ts +1 -1
  36. package/lib/redocly/index.js +1 -1
  37. package/lib/redocly/redocly-client-types.d.ts +1 -1
  38. package/lib/redocly/registry-api.d.ts +1 -1
  39. package/lib/resolve.d.ts +1 -1
  40. package/lib/resolve.js +1 -2
  41. package/lib/rules/common/assertions/index.js +1 -1
  42. package/lib/rules/common/assertions/utils.d.ts +1 -1
  43. package/lib/rules/common/assertions/utils.js +6 -2
  44. package/lib/types/index.js +2 -2
  45. package/lib/types/oas3_1.js +31 -5
  46. package/lib/utils.d.ts +4 -1
  47. package/lib/utils.js +18 -1
  48. package/package.json +7 -4
  49. package/src/__tests__/lint.test.ts +1 -1
  50. package/src/benchmark/benches/recommended-oas3.bench.ts +2 -3
  51. package/src/benchmark/benchmark.js +1 -1
  52. package/src/benchmark/utils.ts +13 -8
  53. package/src/bundle.ts +2 -1
  54. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +140 -0
  55. package/src/config/__tests__/config-resolvers.test.ts +398 -0
  56. package/src/config/__tests__/config.test.ts +244 -0
  57. package/src/config/__tests__/fixtures/plugin.js +1 -1
  58. package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +7 -0
  59. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +67 -0
  60. package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +8 -0
  61. package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +12 -0
  62. package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +10 -0
  63. package/src/config/__tests__/fixtures/resolve-config/plugin.js +66 -0
  64. package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +4 -0
  65. package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +5 -0
  66. package/src/config/__tests__/load.test.ts +8 -1
  67. package/src/config/all.ts +3 -2
  68. package/src/config/builtIn.ts +2 -1
  69. package/src/config/config-resolvers.ts +304 -0
  70. package/src/config/config.ts +40 -457
  71. package/src/config/index.ts +7 -0
  72. package/src/config/load.ts +37 -31
  73. package/src/config/minimal.ts +2 -2
  74. package/src/config/recommended.ts +2 -2
  75. package/src/config/types.ts +168 -0
  76. package/src/config/utils.ts +208 -0
  77. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  78. package/src/format/format.ts +36 -6
  79. package/src/index.ts +6 -2
  80. package/src/lint.ts +4 -5
  81. package/src/redocly/__tests__/redocly-client.test.ts +7 -0
  82. package/src/redocly/index.ts +4 -2
  83. package/src/redocly/redocly-client-types.ts +1 -1
  84. package/src/redocly/registry-api.ts +3 -1
  85. package/src/resolve.ts +2 -4
  86. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  87. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  88. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  89. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  90. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  91. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +5 -5
  92. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  93. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  94. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  95. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  96. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  97. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  98. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  99. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  100. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  101. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  102. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  103. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  104. package/src/rules/common/__tests__/paths-kebab-case.test.ts +3 -3
  105. package/src/rules/common/__tests__/spec.test.ts +1 -1
  106. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  107. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  108. package/src/rules/common/assertions/index.ts +1 -1
  109. package/src/rules/common/assertions/utils.ts +5 -2
  110. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  111. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -1
  112. package/src/rules/oas2/__tests__/spec/utils.ts +10 -7
  113. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  114. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +6 -6
  115. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  116. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +8 -8
  117. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  118. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  119. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  120. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +23 -14
  121. package/src/rules/oas3/__tests__/spec/servers.test.ts +1 -1
  122. package/src/rules/oas3/__tests__/spec/spec.test.ts +4 -4
  123. package/src/rules/oas3/__tests__/spec/utils.ts +10 -7
  124. package/src/types/index.ts +2 -2
  125. package/src/types/oas3_1.ts +32 -7
  126. package/src/utils.ts +18 -2
  127. package/tsconfig.tsbuildinfo +1 -1
package/lib/utils.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.match = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
12
+ exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.match = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
13
13
  const fs = require("fs");
14
14
  const minimatch = require("minimatch");
15
15
  const node_fetch_1 = require("node-fetch");
@@ -156,3 +156,20 @@ function isNotEmptyObject(obj) {
156
156
  return !!obj && Object.keys(obj).length > 0;
157
157
  }
158
158
  exports.isNotEmptyObject = isNotEmptyObject;
159
+ // TODO: use it everywhere
160
+ function isString(value) {
161
+ return typeof value === 'string';
162
+ }
163
+ exports.isString = isString;
164
+ function isNotString(value) {
165
+ return !isString(value);
166
+ }
167
+ exports.isNotString = isNotString;
168
+ function assignExisting(target, obj) {
169
+ for (let k of Object.keys(obj)) {
170
+ if (target.hasOwnProperty(k)) {
171
+ target[k] = obj[k];
172
+ }
173
+ }
174
+ }
175
+ exports.assignExisting = assignExisting;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "1.0.0-beta.93",
3
+ "version": "1.0.0-beta.96",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "engines": {
@@ -10,12 +10,15 @@
10
10
  "license": "MIT",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/Redocly/openapi-cli.git"
13
+ "url": "https://github.com/Redocly/redocly-cli.git"
14
14
  },
15
15
  "browser": {
16
- "fs": false
16
+ "fs": false,
17
+ "path": "path-browserify",
18
+ "os": false,
19
+ "node-fetch": false
17
20
  },
18
- "homepage": "https://github.com/Redocly/openapi-cli",
21
+ "homepage": "https://github.com/Redocly/redocly-cli",
19
22
  "keywords": [
20
23
  "linter",
21
24
  "OpenAPI",
@@ -174,7 +174,7 @@ describe('lint', () => {
174
174
  const results = await lintDocument({
175
175
  externalRefResolver: new BaseResolver(),
176
176
  document,
177
- config: makeConfig({ spec: 'error' }),
177
+ config: await makeConfig({ spec: 'error' }),
178
178
  });
179
179
 
180
180
  expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
@@ -1,10 +1,9 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import { join as pathJoin, resolve as pathResolve } from 'path';
3
3
  import { lintDocument } from '../../lint';
4
- import { LintConfig } from '../../config/config';
4
+ import { LintConfig, defaultPlugin, resolvePreset } from '../../config';
5
5
  import { BaseResolver } from '../../resolve';
6
6
  import { parseYamlToDocument } from '../utils';
7
- import { defaultPlugin } from '../../config/builtIn';
8
7
 
9
8
  export const name = 'Validate with recommended rules';
10
9
  export const count = 10;
@@ -18,6 +17,6 @@ export function measureAsync() {
18
17
  return lintDocument({
19
18
  externalRefResolver: new BaseResolver(),
20
19
  document: rebillyDocument,
21
- config: new LintConfig({ plugins: [defaultPlugin] }),
20
+ config: new LintConfig(resolvePreset('recommended', [defaultPlugin])),
22
21
  });
23
22
  }
@@ -29,7 +29,7 @@ function prepareRevision(revision) {
29
29
 
30
30
  // Returns the complete git hash for a given git revision reference.
31
31
  const hash = exec(`git rev-parse "${revision}"`);
32
- const dir = path.join(os.tmpdir(), 'openapi-cli-benchmark', hash);
32
+ const dir = path.join(os.tmpdir(), 'redocly-cli-benchmark', hash);
33
33
  if (fs.existsSync(dir)) {
34
34
  fs.rmdirSync(dir, { recursive: true});
35
35
  }
@@ -1,7 +1,9 @@
1
1
  import { parseYaml } from '../js-yaml';
2
2
  import { Document, Source } from '../resolve';
3
3
  import { Oas3RuleSet } from '../oas-types';
4
- import { RuleConfig, LintConfig, Plugin } from '../config/config';
4
+ import { LintConfig, mergeExtends, resolvePlugins } from '../config';
5
+
6
+ import type { RuleConfig, Plugin, ResolvedLintConfig } from '../config/types';
5
7
 
6
8
  export function parseYamlToDocument(body: string, absoluteRef: string = ''): Document {
7
9
  return {
@@ -16,16 +18,19 @@ export function makeConfigForRuleset(rules: Oas3RuleSet, plugin?: Partial<Plugin
16
18
  Object.keys(rules).forEach((name) => {
17
19
  rulesConf[`${ruleId}/${name}`] = 'error';
18
20
  });
19
-
20
- return new LintConfig({
21
- plugins: [
21
+ const extendConfigs = [
22
+ resolvePlugins([
22
23
  {
23
24
  ...plugin,
24
25
  id: ruleId,
25
26
  rules: { oas3: rules },
26
27
  },
27
- ],
28
- extends: [],
29
- rules: rulesConf,
30
- });
28
+ ]) as ResolvedLintConfig,
29
+ ];
30
+ if (rules) {
31
+ extendConfigs.push({ rules });
32
+ }
33
+ const lint = mergeExtends(extendConfigs);
34
+
35
+ return new LintConfig(lint);
31
36
  }
package/src/bundle.ts CHANGED
@@ -8,7 +8,6 @@ import { NormalizedNodeType, normalizeTypes, NodeType } from './types';
8
8
  import { WalkContext, walkDocument, UserContext, ResolveResult } from './walk';
9
9
  import { detectOpenAPI, openAPIMajor, OasMajorVersion } from './oas-types';
10
10
  import { isRef, Location, refBaseName } from './ref-utils';
11
- import type { Config, LintConfig } from './config/config';
12
11
  import { initRules } from './config/rules';
13
12
  import { reportUnresolvedRef } from './rules/no-unresolved-refs';
14
13
  import { isPlainObject } from './utils';
@@ -17,6 +16,8 @@ import { isRedoclyRegistryURL } from './redocly';
17
16
  import { RemoveUnusedComponents as RemoveUnusedComponentsOas2 } from './rules/oas2/remove-unused-components';
18
17
  import { RemoveUnusedComponents as RemoveUnusedComponentsOas3 } from './rules/oas3/remove-unused-components';
19
18
 
19
+ import type { Config, LintConfig } from './config';
20
+
20
21
  export type Oas3RuleSet = Record<string, Oas3Rule>;
21
22
 
22
23
  export enum OasVersion {
@@ -0,0 +1,140 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`resolveConfig should ignore minimal from the root and read local file 1`] = `
4
+ Object {
5
+ "decorators": Object {},
6
+ "doNotResolveExamples": undefined,
7
+ "oas2Decorators": Object {},
8
+ "oas2Preprocessors": Object {},
9
+ "oas2Rules": Object {},
10
+ "oas3_0Decorators": Object {},
11
+ "oas3_0Preprocessors": Object {},
12
+ "oas3_0Rules": Object {
13
+ "no-empty-servers": "error",
14
+ "no-example-value-and-externalValue": "error",
15
+ "no-invalid-media-type-examples": "error",
16
+ "no-server-example.com": "warn",
17
+ "no-server-trailing-slash": "error",
18
+ "no-servers-empty-enum": "error",
19
+ "no-undefined-server-variable": "error",
20
+ "no-unused-components": "warn",
21
+ },
22
+ "oas3_1Decorators": Object {},
23
+ "oas3_1Preprocessors": Object {},
24
+ "oas3_1Rules": Object {
25
+ "no-empty-servers": "error",
26
+ "no-example-value-and-externalValue": "error",
27
+ "no-server-example.com": "warn",
28
+ "no-server-trailing-slash": "error",
29
+ "no-servers-empty-enum": "error",
30
+ "no-undefined-server-variable": "error",
31
+ "no-unused-components": "warn",
32
+ },
33
+ "preprocessors": Object {},
34
+ "recommendedFallback": false,
35
+ "rules": Object {
36
+ "assertions": "warn",
37
+ "boolean-parameter-prefixes": "error",
38
+ "info-contact": "off",
39
+ "info-description": "warn",
40
+ "info-license": "warn",
41
+ "info-license-url": "warn",
42
+ "local/operation-id-not-test": "error",
43
+ "no-ambiguous-paths": "warn",
44
+ "no-enum-type-mismatch": "error",
45
+ "no-identical-paths": "error",
46
+ "no-invalid-media-type-examples": "error",
47
+ "no-path-trailing-slash": "error",
48
+ "no-unresolved-refs": "error",
49
+ "operation-2xx-response": "warn",
50
+ "operation-4xx-response": "error",
51
+ "operation-description": "error",
52
+ "operation-operationId": "warn",
53
+ "operation-operationId-unique": "error",
54
+ "operation-operationId-url-safe": "error",
55
+ "operation-parameters-unique": "error",
56
+ "operation-security-defined": "error",
57
+ "operation-singular-tag": "off",
58
+ "operation-summary": "error",
59
+ "operation-tag-defined": "off",
60
+ "parameter-description": "off",
61
+ "path-declaration-must-exist": "error",
62
+ "path-http-verbs-order": "error",
63
+ "path-not-include-query": "error",
64
+ "path-parameters-defined": "error",
65
+ "paths-kebab-case": "off",
66
+ "spec": "error",
67
+ "tag-description": "warn",
68
+ "tags-alphabetical": "off",
69
+ },
70
+ }
71
+ `;
72
+
73
+ exports[`resolveLint should resolve extends with local file config witch contains path to nested config 1`] = `
74
+ Object {
75
+ "decorators": Object {},
76
+ "doNotResolveExamples": undefined,
77
+ "oas2Decorators": Object {},
78
+ "oas2Preprocessors": Object {},
79
+ "oas2Rules": Object {},
80
+ "oas3_0Decorators": Object {},
81
+ "oas3_0Preprocessors": Object {},
82
+ "oas3_0Rules": Object {
83
+ "no-empty-servers": "error",
84
+ "no-example-value-and-externalValue": "error",
85
+ "no-invalid-media-type-examples": "warn",
86
+ "no-server-example.com": "warn",
87
+ "no-server-trailing-slash": "error",
88
+ "no-servers-empty-enum": "error",
89
+ "no-undefined-server-variable": "error",
90
+ "no-unused-components": "warn",
91
+ },
92
+ "oas3_1Decorators": Object {},
93
+ "oas3_1Preprocessors": Object {},
94
+ "oas3_1Rules": Object {
95
+ "no-empty-servers": "error",
96
+ "no-example-value-and-externalValue": "error",
97
+ "no-server-example.com": "warn",
98
+ "no-server-trailing-slash": "error",
99
+ "no-servers-empty-enum": "error",
100
+ "no-undefined-server-variable": "error",
101
+ "no-unused-components": "warn",
102
+ },
103
+ "preprocessors": Object {},
104
+ "recommendedFallback": undefined,
105
+ "rules": Object {
106
+ "assertions": "warn",
107
+ "boolean-parameter-prefixes": "error",
108
+ "info-contact": "off",
109
+ "info-description": "warn",
110
+ "info-license": "warn",
111
+ "info-license-url": "warn",
112
+ "local/operation-id-not-test": "error",
113
+ "no-ambiguous-paths": "warn",
114
+ "no-enum-type-mismatch": "error",
115
+ "no-identical-paths": "error",
116
+ "no-invalid-media-type-examples": "warn",
117
+ "no-path-trailing-slash": "error",
118
+ "no-unresolved-refs": "error",
119
+ "operation-2xx-response": "error",
120
+ "operation-4xx-response": "off",
121
+ "operation-description": "off",
122
+ "operation-operationId": "warn",
123
+ "operation-operationId-unique": "error",
124
+ "operation-operationId-url-safe": "error",
125
+ "operation-parameters-unique": "error",
126
+ "operation-security-defined": "error",
127
+ "operation-singular-tag": "off",
128
+ "operation-summary": "error",
129
+ "operation-tag-defined": "off",
130
+ "parameter-description": "off",
131
+ "path-declaration-must-exist": "error",
132
+ "path-not-include-query": "error",
133
+ "path-parameters-defined": "error",
134
+ "paths-kebab-case": "off",
135
+ "spec": "error",
136
+ "tag-description": "warn",
137
+ "tags-alphabetical": "off",
138
+ },
139
+ }
140
+ `;