@redocly/openapi-core 1.0.0-beta.105 → 1.0.0-beta.108
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.
- package/README.md +4 -4
- package/__tests__/utils.ts +5 -5
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
- package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
- package/lib/benchmark/utils.d.ts +2 -2
- package/lib/benchmark/utils.js +2 -2
- package/lib/bundle.d.ts +2 -2
- package/lib/bundle.js +7 -4
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +3 -3
- package/lib/config/builtIn.d.ts +2 -2
- package/lib/config/builtIn.js +2 -2
- package/lib/config/config-resolvers.d.ts +5 -5
- package/lib/config/config-resolvers.js +70 -49
- package/lib/config/config.d.ts +8 -10
- package/lib/config/config.js +10 -7
- package/lib/config/load.d.ts +7 -0
- package/lib/config/load.js +18 -10
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +5 -4
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +5 -4
- package/lib/config/rules.d.ts +3 -3
- package/lib/config/rules.js +1 -1
- package/lib/config/types.d.ts +23 -19
- package/lib/config/utils.d.ts +5 -5
- package/lib/config/utils.js +48 -31
- package/lib/decorators/common/registry-dependencies.js +1 -1
- package/lib/decorators/common/remove-x-internal.js +2 -2
- package/lib/env.d.ts +3 -0
- package/lib/env.js +8 -0
- package/lib/format/codeframes.js +16 -10
- package/lib/format/format.js +29 -27
- package/lib/index.d.ts +5 -5
- package/lib/index.js +4 -2
- package/lib/js-yaml/index.js +2 -6
- package/lib/lint.d.ts +2 -2
- package/lib/lint.js +16 -6
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/index.js +10 -9
- package/lib/redocly/registry-api-types.d.ts +28 -30
- package/lib/redocly/registry-api.d.ts +4 -3
- package/lib/redocly/registry-api.js +9 -4
- package/lib/ref-utils.js +2 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +1 -1
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +7 -7
- package/lib/rules/common/assertions/asserts.js +4 -4
- package/lib/rules/common/assertions/index.js +1 -1
- package/lib/rules/common/info-license-url.d.ts +1 -1
- package/lib/rules/common/info-license-url.js +5 -10
- package/lib/rules/common/info-license.d.ts +2 -0
- package/lib/rules/common/info-license.js +17 -0
- package/lib/rules/common/no-enum-type-mismatch.js +1 -3
- package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
- package/lib/rules/common/no-invalid-schema-examples.js +3 -3
- package/lib/rules/common/operation-operationId.js +1 -1
- package/lib/rules/common/operation-security-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +1 -1
- package/lib/rules/common/paths-kebab-case.js +4 -1
- package/lib/rules/common/spec.js +3 -3
- package/lib/rules/oas2/index.js +4 -4
- package/lib/rules/oas2/remove-unused-components.js +5 -5
- package/lib/rules/oas3/index.js +6 -6
- package/lib/rules/oas3/no-empty-servers.js +1 -1
- package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
- package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
- package/lib/rules/oas3/no-unused-components.js +1 -1
- package/lib/rules/oas3/remove-unused-components.js +5 -5
- package/lib/rules/other/stats.js +43 -14
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +20 -5
- package/lib/types/index.d.ts +2 -2
- package/lib/types/redocly-yaml.js +9 -8
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +22 -5
- package/lib/visitors.d.ts +1 -1
- package/lib/visitors.js +2 -2
- package/lib/walk.d.ts +2 -1
- package/lib/walk.js +6 -3
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
- package/src/__tests__/bundle.test.ts +68 -34
- package/src/__tests__/codeframes.test.ts +13 -14
- package/src/__tests__/js-yaml.test.ts +6 -4
- package/src/__tests__/lint.test.ts +74 -6
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/login.test.ts +2 -2
- package/src/__tests__/normalizeVisitors.test.ts +4 -4
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -0
- package/src/__tests__/ref-utils.test.ts +13 -13
- package/src/__tests__/resolve-http.test.ts +1 -1
- package/src/__tests__/resolve.test.ts +14 -11
- package/src/__tests__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +7 -0
- package/src/__tests__/walk.test.ts +48 -56
- package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -2
- package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
- package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
- package/src/benchmark/benchmark.js +9 -5
- package/src/benchmark/utils.ts +5 -5
- package/src/bundle.ts +24 -20
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
- package/src/config/__tests__/config-resolvers.test.ts +123 -121
- package/src/config/__tests__/config.test.ts +111 -76
- package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
- package/src/config/__tests__/load.test.ts +79 -1
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +83 -0
- package/src/config/all.ts +5 -6
- package/src/config/builtIn.ts +5 -5
- package/src/config/config-resolvers.ts +161 -96
- package/src/config/config.ts +15 -13
- package/src/config/load.ts +34 -11
- package/src/config/minimal.ts +7 -6
- package/src/config/recommended.ts +7 -6
- package/src/config/rules.ts +6 -6
- package/src/config/types.ts +28 -19
- package/src/config/utils.ts +78 -57
- package/src/decorators/__tests__/filter-out.test.ts +8 -4
- package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
- package/src/decorators/common/filters/filter-helper.ts +1 -1
- package/src/decorators/common/info-description-override.ts +1 -1
- package/src/decorators/common/operation-description-override.ts +1 -1
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/decorators/common/remove-x-internal.ts +4 -4
- package/src/decorators/common/tag-description-override.ts +1 -1
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +18 -12
- package/src/format/format.ts +37 -42
- package/src/index.ts +8 -7
- package/src/js-yaml/index.ts +4 -8
- package/src/lint.ts +22 -18
- package/src/logger.ts +34 -0
- package/src/oas-types.ts +1 -6
- package/src/output.ts +7 -0
- package/src/redocly/__tests__/redocly-client.test.ts +25 -19
- package/src/redocly/index.ts +12 -7
- package/src/redocly/registry-api-types.ts +27 -29
- package/src/redocly/registry-api.ts +22 -12
- package/src/ref-utils.ts +4 -3
- package/src/resolve.ts +11 -8
- package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
- package/src/rules/__tests__/utils.test.ts +160 -0
- package/src/rules/ajv.ts +7 -8
- package/src/rules/common/__tests__/info-description.test.ts +3 -3
- package/src/rules/common/__tests__/info-license.test.ts +2 -2
- package/src/rules/common/__tests__/license-url.test.ts +2 -2
- package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
- package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
- package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
- package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
- package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
- package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
- package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
- package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
- package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
- package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
- package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
- package/src/rules/common/__tests__/spec.test.ts +2 -2
- package/src/rules/common/__tests__/tag-description.test.ts +2 -2
- package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
- package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
- package/src/rules/common/assertions/asserts.ts +4 -4
- package/src/rules/common/assertions/index.ts +7 -7
- package/src/rules/common/info-license-url.ts +4 -9
- package/src/rules/common/info-license.ts +15 -0
- package/src/rules/common/no-ambiguous-paths.ts +1 -1
- package/src/rules/common/no-enum-type-mismatch.ts +12 -9
- package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
- package/src/rules/common/no-invalid-schema-examples.ts +4 -4
- package/src/rules/common/operation-operationId.ts +1 -1
- package/src/rules/common/operation-parameters-unique.ts +2 -2
- package/src/rules/common/operation-security-defined.ts +1 -1
- package/src/rules/common/path-not-include-query.ts +1 -1
- package/src/rules/common/path-params-defined.ts +1 -1
- package/src/rules/common/paths-kebab-case.ts +4 -1
- package/src/rules/common/scalar-property-missing-example.ts +1 -1
- package/src/rules/common/spec.ts +12 -9
- package/src/rules/no-unresolved-refs.ts +1 -1
- package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
- package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
- package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas2/index.ts +3 -3
- package/src/rules/oas2/remove-unused-components.ts +14 -9
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
- package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
- package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
- package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
- package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
- package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
- package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
- package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
- package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
- package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
- package/src/rules/oas3/index.ts +5 -5
- package/src/rules/oas3/no-empty-servers.ts +1 -1
- package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
- package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +10 -11
- package/src/rules/oas3/no-unused-components.ts +1 -1
- package/src/rules/oas3/remove-unused-components.ts +21 -10
- package/src/rules/other/stats.ts +46 -17
- package/src/rules/utils.ts +20 -4
- package/src/types/index.ts +5 -5
- package/src/types/redocly-yaml.ts +9 -8
- package/src/typings/common.ts +9 -1
- package/src/typings/openapi.ts +1 -1
- package/src/utils.ts +26 -3
- package/src/visitors.ts +9 -9
- package/src/walk.ts +15 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/common/license-url.d.ts +0 -2
- package/lib/rules/common/license-url.js +0 -12
- package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
- package/src/rules/common/license-url.ts +0 -10
package/lib/rules/utils.js
CHANGED
|
@@ -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';
|
|
@@ -11,6 +12,9 @@ function oasTypeOf(value) {
|
|
|
11
12
|
else if (value === null) {
|
|
12
13
|
return 'null';
|
|
13
14
|
}
|
|
15
|
+
else if (Number.isInteger(value)) {
|
|
16
|
+
return 'integer';
|
|
17
|
+
}
|
|
14
18
|
else {
|
|
15
19
|
return typeof value;
|
|
16
20
|
}
|
|
@@ -25,7 +29,7 @@ exports.oasTypeOf = oasTypeOf;
|
|
|
25
29
|
*/
|
|
26
30
|
function matchesJsonSchemaType(value, type, nullable) {
|
|
27
31
|
if (nullable && value === null) {
|
|
28
|
-
return
|
|
32
|
+
return true;
|
|
29
33
|
}
|
|
30
34
|
switch (type) {
|
|
31
35
|
case 'array':
|
|
@@ -82,11 +86,11 @@ function getSuggest(given, variants) {
|
|
|
82
86
|
return distances.map((d) => d.variant);
|
|
83
87
|
}
|
|
84
88
|
exports.getSuggest = getSuggest;
|
|
85
|
-
function validateExample(example, schema, dataLoc, { resolve, location, report },
|
|
89
|
+
function validateExample(example, schema, dataLoc, { resolve, location, report }, allowAdditionalProperties) {
|
|
86
90
|
try {
|
|
87
|
-
const { valid, errors } = ajv_1.validateJsonSchema(example, schema, location.child('schema'), dataLoc.pointer, resolve,
|
|
91
|
+
const { valid, errors } = ajv_1.validateJsonSchema(example, schema, location.child('schema'), dataLoc.pointer, resolve, allowAdditionalProperties);
|
|
88
92
|
if (!valid) {
|
|
89
|
-
for (
|
|
93
|
+
for (const error of errors) {
|
|
90
94
|
report({
|
|
91
95
|
message: `Example value must conform to the schema: ${error.message}.`,
|
|
92
96
|
location: Object.assign(Object.assign({}, new ref_utils_1.Location(dataLoc.source, error.instancePath)), { reportOnKey: error.keyword === 'additionalProperties' }),
|
|
@@ -105,3 +109,14 @@ function validateExample(example, schema, dataLoc, { resolve, location, report }
|
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
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/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare type NodeType = {
|
|
|
22
22
|
items?: string;
|
|
23
23
|
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
24
24
|
requiredOneOf?: string[];
|
|
25
|
-
allowed?: (
|
|
25
|
+
allowed?: (value: any) => string[] | undefined;
|
|
26
26
|
extensionsPrefix?: string;
|
|
27
27
|
};
|
|
28
28
|
declare type PropType = string | NodeType | ScalarSchema | undefined | null;
|
|
@@ -34,7 +34,7 @@ export declare type NormalizedNodeType = {
|
|
|
34
34
|
items?: NormalizedNodeType;
|
|
35
35
|
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
36
36
|
requiredOneOf?: string[];
|
|
37
|
-
allowed?: (
|
|
37
|
+
allowed?: (value: any) => string[] | undefined;
|
|
38
38
|
extensionsPrefix?: string;
|
|
39
39
|
};
|
|
40
40
|
declare type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | undefined | null;
|
|
@@ -43,7 +43,7 @@ const builtInRulesList = [
|
|
|
43
43
|
'no-identical-paths',
|
|
44
44
|
'no-ambiguous-paths',
|
|
45
45
|
'no-undefined-server-variable',
|
|
46
|
-
'no-
|
|
46
|
+
'no-server-variables-empty-enum',
|
|
47
47
|
'no-http-verbs-in-paths',
|
|
48
48
|
'path-excludes-patterns',
|
|
49
49
|
'request-mime-type',
|
|
@@ -112,7 +112,8 @@ const ConfigRoot = {
|
|
|
112
112
|
properties: {},
|
|
113
113
|
additionalProperties: { properties: { type: 'string' } },
|
|
114
114
|
},
|
|
115
|
-
|
|
115
|
+
styleguide: 'RootConfigStyleguide',
|
|
116
|
+
lint: 'RootConfigStyleguide',
|
|
116
117
|
'features.openapi': 'ConfigReferenceDocs',
|
|
117
118
|
referenceDocs: 'ConfigReferenceDocs',
|
|
118
119
|
'features.mockServer': 'ConfigMockServer',
|
|
@@ -137,7 +138,7 @@ const ConfigApisProperties = {
|
|
|
137
138
|
type: 'string',
|
|
138
139
|
},
|
|
139
140
|
},
|
|
140
|
-
|
|
141
|
+
styleguide: 'ConfigStyleguide',
|
|
141
142
|
'features.openapi': 'ConfigReferenceDocs',
|
|
142
143
|
'features.mockServer': 'ConfigMockServer',
|
|
143
144
|
},
|
|
@@ -153,7 +154,7 @@ const ConfigHTTP = {
|
|
|
153
154
|
},
|
|
154
155
|
},
|
|
155
156
|
};
|
|
156
|
-
const
|
|
157
|
+
const ConfigStyleguide = {
|
|
157
158
|
properties: {
|
|
158
159
|
extends: {
|
|
159
160
|
type: 'array',
|
|
@@ -176,11 +177,11 @@ const ConfigLint = {
|
|
|
176
177
|
oas3_1Decorators: { type: 'object' },
|
|
177
178
|
},
|
|
178
179
|
};
|
|
179
|
-
const
|
|
180
|
+
const RootConfigStyleguide = {
|
|
180
181
|
properties: Object.assign({ plugins: {
|
|
181
182
|
type: 'array',
|
|
182
183
|
items: { type: 'string' },
|
|
183
|
-
} },
|
|
184
|
+
} }, ConfigStyleguide.properties),
|
|
184
185
|
};
|
|
185
186
|
const Rules = {
|
|
186
187
|
properties: {},
|
|
@@ -765,8 +766,8 @@ exports.ConfigTypes = {
|
|
|
765
766
|
ConfigRoot,
|
|
766
767
|
ConfigApis,
|
|
767
768
|
ConfigApisProperties,
|
|
768
|
-
|
|
769
|
-
|
|
769
|
+
RootConfigStyleguide,
|
|
770
|
+
ConfigStyleguide,
|
|
770
771
|
ConfigReferenceDocs,
|
|
771
772
|
ConfigMockServer,
|
|
772
773
|
ConfigHTTP,
|
package/lib/utils.d.ts
CHANGED
|
@@ -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;
|
package/lib/utils.js
CHANGED
|
@@ -9,14 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = 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.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.notUndefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
|
|
12
|
+
exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = 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.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 path_1 = require("path");
|
|
15
15
|
const minimatch = require("minimatch");
|
|
16
16
|
const node_fetch_1 = require("node-fetch");
|
|
17
17
|
const pluralize = require("pluralize");
|
|
18
18
|
const js_yaml_1 = require("./js-yaml");
|
|
19
|
-
const
|
|
19
|
+
const env_1 = require("./env");
|
|
20
|
+
const logger_1 = require("./logger");
|
|
20
21
|
var js_yaml_2 = require("./js-yaml");
|
|
21
22
|
Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
|
|
22
23
|
Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
|
|
@@ -58,7 +59,7 @@ function readFileFromUrl(url, config) {
|
|
|
58
59
|
for (const header of config.headers) {
|
|
59
60
|
if (match(url, header.matches)) {
|
|
60
61
|
headers[header.name] =
|
|
61
|
-
header.envVariable !== undefined ?
|
|
62
|
+
header.envVariable !== undefined ? env_1.env[header.envVariable] || '' : header.value;
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
const req = yield (config.customFetch || node_fetch_1.default)(url, {
|
|
@@ -89,7 +90,7 @@ exports.omitObjectProps = omitObjectProps;
|
|
|
89
90
|
function splitCamelCaseIntoWords(str) {
|
|
90
91
|
const camel = str
|
|
91
92
|
.split(/(?:[-._])|([A-Z][a-z]+)/)
|
|
92
|
-
.filter(
|
|
93
|
+
.filter(isTruthy)
|
|
93
94
|
.map((item) => item.toLocaleLowerCase());
|
|
94
95
|
const caps = str
|
|
95
96
|
.split(/([A-Z]{2,})/)
|
|
@@ -167,7 +168,7 @@ function isNotString(value) {
|
|
|
167
168
|
}
|
|
168
169
|
exports.isNotString = isNotString;
|
|
169
170
|
function assignExisting(target, obj) {
|
|
170
|
-
for (
|
|
171
|
+
for (const k of Object.keys(obj)) {
|
|
171
172
|
if (target.hasOwnProperty(k)) {
|
|
172
173
|
target[k] = obj[k];
|
|
173
174
|
}
|
|
@@ -188,3 +189,19 @@ function doesYamlFileExist(filePath) {
|
|
|
188
189
|
fs.existsSync(filePath));
|
|
189
190
|
}
|
|
190
191
|
exports.doesYamlFileExist = doesYamlFileExist;
|
|
192
|
+
function showWarningForDeprecatedField(deprecatedField, updatedField) {
|
|
193
|
+
logger_1.logger.warn(`The ${logger_1.colorize.red(deprecatedField)} field is deprecated. Use ${logger_1.colorize.green(updatedField)} instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
|
|
194
|
+
}
|
|
195
|
+
exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
|
|
196
|
+
function showErrorForDeprecatedField(deprecatedField, updatedField) {
|
|
197
|
+
throw new Error(`Do not use '${deprecatedField}' field. Use '${updatedField}' instead.\n`);
|
|
198
|
+
}
|
|
199
|
+
exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
|
|
200
|
+
function isTruthy(value) {
|
|
201
|
+
return !!value;
|
|
202
|
+
}
|
|
203
|
+
exports.isTruthy = isTruthy;
|
|
204
|
+
function identity(value) {
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
exports.identity = identity;
|
package/lib/visitors.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ declare type VisitObject<T> = {
|
|
|
16
16
|
};
|
|
17
17
|
declare type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
|
|
18
18
|
declare type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
|
|
19
|
-
declare type VisitorNode<T
|
|
19
|
+
declare type VisitorNode<T> = {
|
|
20
20
|
ruleId: string;
|
|
21
21
|
severity: ProblemSeverity;
|
|
22
22
|
context: VisitorLevelContext | VisitorSkippedLevelContext;
|
package/lib/visitors.js
CHANGED
|
@@ -30,7 +30,7 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
30
30
|
return;
|
|
31
31
|
stack = [...stack, from];
|
|
32
32
|
const possibleChildren = new Set();
|
|
33
|
-
for (
|
|
33
|
+
for (const type of Object.values(from.properties)) {
|
|
34
34
|
if (type === to) {
|
|
35
35
|
addWeakFromStack(ruleConf, stack);
|
|
36
36
|
continue;
|
|
@@ -55,7 +55,7 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
55
55
|
possibleChildren.add(from.items);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
for (
|
|
58
|
+
for (const fromType of Array.from(possibleChildren.values())) {
|
|
59
59
|
addWeakNodes(ruleConf, fromType, to, parentContext, stack);
|
|
60
60
|
}
|
|
61
61
|
function addWeakFromStack(ruleConf, stack) {
|
package/lib/walk.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { NormalizedOasVisitors } from './visitors';
|
|
|
4
4
|
import { ResolvedRefMap, Document, ResolveError, YamlParseError, Source } from './resolve';
|
|
5
5
|
import { OasVersion } from './oas-types';
|
|
6
6
|
import { NormalizedNodeType } from './types';
|
|
7
|
+
import type { RuleSeverity } from './config';
|
|
7
8
|
declare type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
|
|
8
9
|
export declare type ResolveResult<T extends NonUndefined> = {
|
|
9
10
|
node: T;
|
|
@@ -49,7 +50,7 @@ export declare type Problem = {
|
|
|
49
50
|
suggest?: string[];
|
|
50
51
|
location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
|
|
51
52
|
from?: LocationObject;
|
|
52
|
-
forceSeverity?:
|
|
53
|
+
forceSeverity?: RuleSeverity;
|
|
53
54
|
ruleId?: string;
|
|
54
55
|
};
|
|
55
56
|
export declare type NormalizedProblem = {
|
package/lib/walk.js
CHANGED
|
@@ -249,9 +249,12 @@ function walkDocument(opts) {
|
|
|
249
249
|
? opts.location
|
|
250
250
|
: [opts.location]
|
|
251
251
|
: [Object.assign(Object.assign({}, currentLocation), { reportOnKey: false })];
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
})
|
|
252
|
+
const ruleSeverity = opts.forceSeverity || severity;
|
|
253
|
+
if (ruleSeverity !== 'off') {
|
|
254
|
+
ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: ruleSeverity }, opts), { suggest: opts.suggest || [], location: loc.map((loc) => {
|
|
255
|
+
return Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), loc);
|
|
256
|
+
}) }));
|
|
257
|
+
}
|
|
255
258
|
}
|
|
256
259
|
function getVisitorDataFn(ruleId) {
|
|
257
260
|
ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/openapi-core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.108",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"Andriy Leliv <andriy@redoc.ly> (https://redoc.ly/)"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@redocly/ajv": "^8.6.
|
|
37
|
+
"@redocly/ajv": "^8.6.5",
|
|
38
38
|
"@types/node": "^14.11.8",
|
|
39
39
|
"colorette": "^1.2.0",
|
|
40
40
|
"js-levenshtein": "^1.1.6",
|
|
@@ -1,5 +1,146 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`bundle should add to meta ref from redocly registry 1`] = `
|
|
4
|
+
fileDependencies: {}
|
|
5
|
+
rootType:
|
|
6
|
+
properties:
|
|
7
|
+
openapi: null
|
|
8
|
+
info:
|
|
9
|
+
properties:
|
|
10
|
+
title:
|
|
11
|
+
type: string
|
|
12
|
+
version:
|
|
13
|
+
type: string
|
|
14
|
+
description:
|
|
15
|
+
type: string
|
|
16
|
+
termsOfService:
|
|
17
|
+
type: string
|
|
18
|
+
contact:
|
|
19
|
+
properties:
|
|
20
|
+
name:
|
|
21
|
+
type: string
|
|
22
|
+
url:
|
|
23
|
+
type: string
|
|
24
|
+
email:
|
|
25
|
+
type: string
|
|
26
|
+
name: Contact
|
|
27
|
+
license:
|
|
28
|
+
properties:
|
|
29
|
+
name:
|
|
30
|
+
type: string
|
|
31
|
+
url:
|
|
32
|
+
type: string
|
|
33
|
+
required:
|
|
34
|
+
- name
|
|
35
|
+
name: License
|
|
36
|
+
required:
|
|
37
|
+
- title
|
|
38
|
+
- version
|
|
39
|
+
name: Info
|
|
40
|
+
servers:
|
|
41
|
+
name: ServerList
|
|
42
|
+
properties: {}
|
|
43
|
+
items:
|
|
44
|
+
properties:
|
|
45
|
+
url:
|
|
46
|
+
type: string
|
|
47
|
+
description:
|
|
48
|
+
type: string
|
|
49
|
+
variables:
|
|
50
|
+
name: ServerVariableMap
|
|
51
|
+
properties: {}
|
|
52
|
+
required:
|
|
53
|
+
- url
|
|
54
|
+
name: Server
|
|
55
|
+
security:
|
|
56
|
+
name: SecurityRequirementList
|
|
57
|
+
properties: {}
|
|
58
|
+
items:
|
|
59
|
+
properties: {}
|
|
60
|
+
additionalProperties:
|
|
61
|
+
type: array
|
|
62
|
+
items:
|
|
63
|
+
type: string
|
|
64
|
+
name: SecurityRequirement
|
|
65
|
+
tags:
|
|
66
|
+
name: TagList
|
|
67
|
+
properties: {}
|
|
68
|
+
items:
|
|
69
|
+
properties:
|
|
70
|
+
name:
|
|
71
|
+
type: string
|
|
72
|
+
description:
|
|
73
|
+
type: string
|
|
74
|
+
externalDocs:
|
|
75
|
+
properties:
|
|
76
|
+
description:
|
|
77
|
+
type: string
|
|
78
|
+
url:
|
|
79
|
+
type: string
|
|
80
|
+
required:
|
|
81
|
+
- url
|
|
82
|
+
name: ExternalDocs
|
|
83
|
+
required:
|
|
84
|
+
- name
|
|
85
|
+
name: Tag
|
|
86
|
+
externalDocs:
|
|
87
|
+
properties:
|
|
88
|
+
description:
|
|
89
|
+
type: string
|
|
90
|
+
url:
|
|
91
|
+
type: string
|
|
92
|
+
required:
|
|
93
|
+
- url
|
|
94
|
+
name: ExternalDocs
|
|
95
|
+
paths:
|
|
96
|
+
properties: {}
|
|
97
|
+
name: PathMap
|
|
98
|
+
components:
|
|
99
|
+
properties:
|
|
100
|
+
parameters:
|
|
101
|
+
name: NamedParameters
|
|
102
|
+
properties: {}
|
|
103
|
+
schemas:
|
|
104
|
+
name: NamedSchemas
|
|
105
|
+
properties: {}
|
|
106
|
+
responses:
|
|
107
|
+
name: NamedResponses
|
|
108
|
+
properties: {}
|
|
109
|
+
examples:
|
|
110
|
+
name: NamedExamples
|
|
111
|
+
properties: {}
|
|
112
|
+
requestBodies:
|
|
113
|
+
name: NamedRequestBodies
|
|
114
|
+
properties: {}
|
|
115
|
+
headers:
|
|
116
|
+
name: NamedHeaders
|
|
117
|
+
properties: {}
|
|
118
|
+
securitySchemes:
|
|
119
|
+
name: NamedSecuritySchemes
|
|
120
|
+
properties: {}
|
|
121
|
+
links:
|
|
122
|
+
name: NamedLinks
|
|
123
|
+
properties: {}
|
|
124
|
+
callbacks:
|
|
125
|
+
name: NamedCallbacks
|
|
126
|
+
properties: {}
|
|
127
|
+
name: Components
|
|
128
|
+
x-webhooks:
|
|
129
|
+
properties: {}
|
|
130
|
+
name: WebhooksMap
|
|
131
|
+
required:
|
|
132
|
+
- openapi
|
|
133
|
+
- paths
|
|
134
|
+
- info
|
|
135
|
+
name: DefinitionRoot
|
|
136
|
+
refTypes: {}
|
|
137
|
+
visitorsData:
|
|
138
|
+
registry-dependencies:
|
|
139
|
+
links:
|
|
140
|
+
- https://api.redocly.com/registry/params
|
|
141
|
+
|
|
142
|
+
`;
|
|
143
|
+
|
|
3
144
|
exports[`bundle should bundle external refs 1`] = `
|
|
4
145
|
openapi: 3.0.0
|
|
5
146
|
paths:
|
|
@@ -2,11 +2,21 @@ import outdent from 'outdent';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
|
|
4
4
|
import { bundleDocument, bundle } from '../bundle';
|
|
5
|
-
import { parseYamlToDocument, yamlSerializer } from '../../__tests__/utils';
|
|
6
|
-
import {
|
|
5
|
+
import { parseYamlToDocument, yamlSerializer, makeConfig } from '../../__tests__/utils';
|
|
6
|
+
import { StyleguideConfig, Config, ResolvedConfig } from '../config';
|
|
7
7
|
import { BaseResolver } from '../resolve';
|
|
8
8
|
|
|
9
9
|
describe('bundle', () => {
|
|
10
|
+
const fetchMock = jest.fn(() =>
|
|
11
|
+
Promise.resolve({
|
|
12
|
+
ok: true,
|
|
13
|
+
text: () => 'External schema content',
|
|
14
|
+
headers: {
|
|
15
|
+
get: () => '',
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
|
|
10
20
|
expect.addSnapshotSerializer(yamlSerializer);
|
|
11
21
|
|
|
12
22
|
const testDocument = parseYamlToDocument(
|
|
@@ -28,14 +38,14 @@ describe('bundle', () => {
|
|
|
28
38
|
shared_a:
|
|
29
39
|
name: shared-a
|
|
30
40
|
`,
|
|
31
|
-
''
|
|
41
|
+
''
|
|
32
42
|
);
|
|
33
43
|
|
|
34
44
|
it('change nothing with only internal refs', async () => {
|
|
35
45
|
const { bundle, problems } = await bundleDocument({
|
|
36
46
|
document: testDocument,
|
|
37
47
|
externalRefResolver: new BaseResolver(),
|
|
38
|
-
config: new
|
|
48
|
+
config: new StyleguideConfig({}),
|
|
39
49
|
});
|
|
40
50
|
|
|
41
51
|
const origCopy = JSON.parse(JSON.stringify(testDocument.parsed));
|
|
@@ -60,7 +70,7 @@ describe('bundle', () => {
|
|
|
60
70
|
});
|
|
61
71
|
expect(problems).toHaveLength(1);
|
|
62
72
|
expect(problems[0].message).toEqual(
|
|
63
|
-
`Two schemas are referenced with the same name but different content. Renamed param-b to param-b-2
|
|
73
|
+
`Two schemas are referenced with the same name but different content. Renamed param-b to param-b-2.`
|
|
64
74
|
);
|
|
65
75
|
expect(res.parsed).toMatchSnapshot();
|
|
66
76
|
});
|
|
@@ -68,7 +78,7 @@ describe('bundle', () => {
|
|
|
68
78
|
it('should dereferenced correctly when used with dereference', async () => {
|
|
69
79
|
const { bundle: res, problems } = await bundleDocument({
|
|
70
80
|
externalRefResolver: new BaseResolver(),
|
|
71
|
-
config: new
|
|
81
|
+
config: new StyleguideConfig({}),
|
|
72
82
|
document: testDocument,
|
|
73
83
|
dereference: true,
|
|
74
84
|
});
|
|
@@ -98,47 +108,25 @@ describe('bundle', () => {
|
|
|
98
108
|
});
|
|
99
109
|
|
|
100
110
|
it('should pull hosted schema', async () => {
|
|
101
|
-
const fetchMock = jest.fn(
|
|
102
|
-
() => Promise.resolve({
|
|
103
|
-
ok: true,
|
|
104
|
-
text: () => 'External schema content',
|
|
105
|
-
headers: {
|
|
106
|
-
get: () => ''
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
|
|
111
111
|
const { bundle: res, problems } = await bundle({
|
|
112
112
|
config: new Config({} as ResolvedConfig),
|
|
113
113
|
externalRefResolver: new BaseResolver({
|
|
114
114
|
http: {
|
|
115
115
|
customFetch: fetchMock,
|
|
116
|
-
headers: []
|
|
117
|
-
}
|
|
116
|
+
headers: [],
|
|
117
|
+
},
|
|
118
118
|
}),
|
|
119
|
-
ref: path.join(__dirname, 'fixtures/refs/hosted.yaml')
|
|
119
|
+
ref: path.join(__dirname, 'fixtures/refs/hosted.yaml'),
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
expect(problems).toHaveLength(0);
|
|
123
|
-
expect(fetchMock).toHaveBeenCalledWith(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
headers: {}
|
|
127
|
-
}
|
|
128
|
-
);
|
|
123
|
+
expect(fetchMock).toHaveBeenCalledWith('https://someexternal.schema', {
|
|
124
|
+
headers: {},
|
|
125
|
+
});
|
|
129
126
|
expect(res.parsed).toMatchSnapshot();
|
|
130
127
|
});
|
|
131
128
|
|
|
132
129
|
it('should not bundle url refs if used with keepUrlRefs', async () => {
|
|
133
|
-
const fetchMock = jest.fn(() =>
|
|
134
|
-
Promise.resolve({
|
|
135
|
-
ok: true,
|
|
136
|
-
text: () => 'External schema content',
|
|
137
|
-
headers: {
|
|
138
|
-
get: () => '',
|
|
139
|
-
},
|
|
140
|
-
}),
|
|
141
|
-
);
|
|
142
130
|
const { bundle: res, problems } = await bundle({
|
|
143
131
|
config: new Config({} as ResolvedConfig),
|
|
144
132
|
externalRefResolver: new BaseResolver({
|
|
@@ -153,4 +141,50 @@ describe('bundle', () => {
|
|
|
153
141
|
expect(problems).toHaveLength(0);
|
|
154
142
|
expect(res.parsed).toMatchSnapshot();
|
|
155
143
|
});
|
|
144
|
+
|
|
145
|
+
it('should add to meta ref from redocly registry', async () => {
|
|
146
|
+
const testDocument = parseYamlToDocument(
|
|
147
|
+
outdent`
|
|
148
|
+
openapi: 3.0.0
|
|
149
|
+
paths:
|
|
150
|
+
/pet:
|
|
151
|
+
get:
|
|
152
|
+
operationId: get
|
|
153
|
+
parameters:
|
|
154
|
+
- $ref: '#/components/parameters/shared_a'
|
|
155
|
+
- name: get_b
|
|
156
|
+
post:
|
|
157
|
+
operationId: post
|
|
158
|
+
parameters:
|
|
159
|
+
- $ref: 'https://api.redocly.com/registry/params'
|
|
160
|
+
components:
|
|
161
|
+
parameters:
|
|
162
|
+
shared_a:
|
|
163
|
+
name: shared-a
|
|
164
|
+
`,
|
|
165
|
+
''
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const config = await makeConfig({}, { 'registry-dependencies': 'on' });
|
|
169
|
+
|
|
170
|
+
const {
|
|
171
|
+
bundle: result,
|
|
172
|
+
problems,
|
|
173
|
+
...meta
|
|
174
|
+
} = await bundleDocument({
|
|
175
|
+
document: testDocument,
|
|
176
|
+
config: config,
|
|
177
|
+
externalRefResolver: new BaseResolver({
|
|
178
|
+
http: {
|
|
179
|
+
customFetch: fetchMock,
|
|
180
|
+
headers: [],
|
|
181
|
+
},
|
|
182
|
+
}),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const parsedMeta = JSON.parse(JSON.stringify(meta));
|
|
186
|
+
|
|
187
|
+
expect(problems).toHaveLength(0);
|
|
188
|
+
expect(parsedMeta).toMatchSnapshot();
|
|
189
|
+
});
|
|
156
190
|
});
|