@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.
- package/README.md +4 -4
- package/__tests__/utils.ts +8 -6
- 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 +2 -2
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +1 -1
- 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 +39 -36
- package/lib/config/config.d.ts +6 -5
- package/lib/config/config.js +27 -20
- package/lib/config/load.js +6 -7
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +3 -2
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +3 -2
- package/lib/config/rules.d.ts +2 -2
- 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 +43 -26
- package/lib/decorators/common/remove-x-internal.js +2 -2
- package/lib/format/format.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -2
- package/lib/js-yaml/index.js +1 -6
- package/lib/lint.d.ts +2 -2
- package/lib/lint.js +16 -6
- package/lib/redocly/registry-api.d.ts +1 -1
- package/lib/redocly/registry-api.js +2 -2
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +6 -6
- 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/path-not-include-query.js +1 -1
- package/lib/rules/common/paths-kebab-case.js +4 -1
- package/lib/rules/common/spec.js +1 -1
- package/lib/rules/oas2/index.js +4 -4
- package/lib/rules/oas2/remove-unused-components.js +3 -3
- package/lib/rules/oas3/index.js +4 -4
- 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/remove-unused-components.js +2 -2
- package/lib/rules/other/stats.js +43 -14
- package/lib/rules/utils.d.ts +3 -2
- package/lib/rules/utils.js +19 -4
- package/lib/types/index.d.ts +2 -2
- package/lib/types/redocly-yaml.js +8 -7
- package/lib/utils.d.ts +5 -2
- package/lib/utils.js +20 -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__/fixtures/.redocly.lint-ignore.yaml +5 -0
- package/src/__tests__/js-yaml.test.ts +6 -4
- package/src/__tests__/lint.test.ts +127 -12
- package/src/__tests__/login.test.ts +2 -2
- package/src/__tests__/normalizeVisitors.test.ts +4 -4
- 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.test.ts +42 -1
- 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 -1
- 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 +18 -17
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +3 -1
- package/src/config/__tests__/config-resolvers.test.ts +123 -121
- package/src/config/__tests__/config.test.ts +76 -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 +2 -2
- package/src/config/__tests__/resolve-plugins.test.ts +3 -3
- package/src/config/__tests__/utils.test.ts +83 -0
- package/src/config/all.ts +3 -4
- package/src/config/builtIn.ts +5 -5
- package/src/config/config-resolvers.ts +122 -83
- package/src/config/config.ts +36 -32
- package/src/config/load.ts +13 -16
- package/src/config/minimal.ts +5 -4
- package/src/config/recommended.ts +5 -4
- package/src/config/rules.ts +6 -6
- package/src/config/types.ts +28 -19
- package/src/config/utils.ts +74 -54
- 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/remove-x-internal.ts +4 -4
- package/src/decorators/common/tag-description-override.ts +1 -1
- package/src/format/codeframes.ts +4 -4
- package/src/format/format.ts +10 -10
- package/src/index.ts +3 -4
- package/src/js-yaml/index.ts +3 -8
- package/src/lint.ts +22 -18
- package/src/oas-types.ts +1 -6
- package/src/redocly/__tests__/redocly-client.test.ts +25 -19
- package/src/redocly/index.ts +6 -4
- package/src/redocly/registry-api.ts +6 -6
- package/src/ref-utils.ts +2 -2
- package/src/resolve.ts +7 -4
- 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/index.ts +6 -6
- 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/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 +10 -7
- 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 +13 -8
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
- 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 +3 -3
- 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 +9 -10
- package/src/rules/oas3/remove-unused-components.ts +18 -7
- package/src/rules/other/stats.ts +46 -17
- package/src/rules/utils.ts +19 -3
- package/src/types/index.ts +5 -5
- package/src/types/redocly-yaml.ts +8 -7
- package/src/typings/common.ts +9 -1
- package/src/typings/openapi.ts +1 -1
- package/src/utils.ts +31 -8
- package/src/visitors.ts +4 -4
- 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/src/rules/common/license-url.ts +0 -10
package/lib/rules/oas2/index.js
CHANGED
|
@@ -6,8 +6,8 @@ const no_invalid_schema_examples_1 = require("../common/no-invalid-schema-exampl
|
|
|
6
6
|
const no_invalid_parameter_examples_1 = require("../common/no-invalid-parameter-examples");
|
|
7
7
|
const info_description_1 = require("../common/info-description");
|
|
8
8
|
const info_contact_1 = require("../common/info-contact");
|
|
9
|
+
const info_license_1 = require("../common/info-license");
|
|
9
10
|
const info_license_url_1 = require("../common/info-license-url");
|
|
10
|
-
const license_url_1 = require("../common/license-url");
|
|
11
11
|
const boolean_parameter_prefixes_1 = require("./boolean-parameter-prefixes");
|
|
12
12
|
const tag_description_1 = require("../common/tag-description");
|
|
13
13
|
const tags_alphabetical_1 = require("../common/tags-alphabetical");
|
|
@@ -48,8 +48,8 @@ exports.rules = {
|
|
|
48
48
|
'no-invalid-parameter-examples': no_invalid_parameter_examples_1.NoInvalidParameterExamples,
|
|
49
49
|
'info-description': info_description_1.InfoDescription,
|
|
50
50
|
'info-contact': info_contact_1.InfoContact,
|
|
51
|
-
'info-license':
|
|
52
|
-
'info-license-url':
|
|
51
|
+
'info-license': info_license_1.InfoLicense,
|
|
52
|
+
'info-license-url': info_license_url_1.InfoLicenseUrl,
|
|
53
53
|
'tag-description': tag_description_1.TagDescription,
|
|
54
54
|
'tags-alphabetical': tags_alphabetical_1.TagsAlphabetical,
|
|
55
55
|
'paths-kebab-case': paths_kebab_case_1.PathsKebabCase,
|
|
@@ -58,7 +58,7 @@ exports.rules = {
|
|
|
58
58
|
'no-path-trailing-slash': no_path_trailing_slash_1.NoPathTrailingSlash,
|
|
59
59
|
'operation-2xx-response': operation_2xx_response_1.Operation2xxResponse,
|
|
60
60
|
'operation-4xx-response': operation_4xx_response_1.Operation4xxResponse,
|
|
61
|
-
|
|
61
|
+
assertions: assertions_1.Assertions,
|
|
62
62
|
'operation-operationId-unique': operation_operationId_unique_1.OperationIdUnique,
|
|
63
63
|
'operation-parameters-unique': operation_parameters_unique_1.OperationParametersUnique,
|
|
64
64
|
'path-parameters-defined': path_params_defined_1.PathParamsDefined,
|
|
@@ -24,14 +24,14 @@ const RemoveUnusedComponents = () => {
|
|
|
24
24
|
name: key.toString(),
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
28
|
},
|
|
29
29
|
DefinitionRoot: {
|
|
30
30
|
leave(root, ctx) {
|
|
31
31
|
const data = ctx.getVisitorData();
|
|
32
32
|
data.removedCount = 0;
|
|
33
33
|
let rootComponents = new Set();
|
|
34
|
-
components.forEach(usageInfo => {
|
|
34
|
+
components.forEach((usageInfo) => {
|
|
35
35
|
const { used, name, componentType } = usageInfo;
|
|
36
36
|
if (!used && componentType) {
|
|
37
37
|
rootComponents.add(componentType);
|
|
@@ -67,7 +67,7 @@ const RemoveUnusedComponents = () => {
|
|
|
67
67
|
SecurityScheme(_securityScheme, { location, key }) {
|
|
68
68
|
registerComponent(location, 'securityDefinitions', key.toString());
|
|
69
69
|
},
|
|
70
|
-
}
|
|
70
|
+
},
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
73
|
exports.RemoveUnusedComponents = RemoveUnusedComponents;
|
package/lib/rules/oas3/index.js
CHANGED
|
@@ -20,13 +20,13 @@ const no_server_trailing_slash_1 = require("./no-server-trailing-slash");
|
|
|
20
20
|
const info_description_1 = require("../common/info-description");
|
|
21
21
|
const tag_description_1 = require("../common/tag-description");
|
|
22
22
|
const info_contact_1 = require("../common/info-contact");
|
|
23
|
+
const info_license_1 = require("../common/info-license");
|
|
23
24
|
const info_license_url_1 = require("../common/info-license-url");
|
|
24
25
|
const operation_description_1 = require("../common/operation-description");
|
|
25
26
|
const no_unused_components_1 = require("./no-unused-components");
|
|
26
27
|
const path_not_include_query_1 = require("../common/path-not-include-query");
|
|
27
28
|
const parameter_description_1 = require("../common/parameter-description");
|
|
28
29
|
const operation_singular_tag_1 = require("../common/operation-singular-tag");
|
|
29
|
-
const license_url_1 = require("../common/license-url");
|
|
30
30
|
const operation_security_defined_1 = require("../common/operation-security-defined");
|
|
31
31
|
const no_unresolved_refs_1 = require("../no-unresolved-refs");
|
|
32
32
|
const boolean_parameter_prefixes_1 = require("./boolean-parameter-prefixes");
|
|
@@ -54,11 +54,11 @@ exports.rules = {
|
|
|
54
54
|
spec: spec_1.OasSpec,
|
|
55
55
|
'info-description': info_description_1.InfoDescription,
|
|
56
56
|
'info-contact': info_contact_1.InfoContact,
|
|
57
|
-
'info-license':
|
|
58
|
-
'info-license-url':
|
|
57
|
+
'info-license': info_license_1.InfoLicense,
|
|
58
|
+
'info-license-url': info_license_url_1.InfoLicenseUrl,
|
|
59
59
|
'operation-2xx-response': operation_2xx_response_1.Operation2xxResponse,
|
|
60
60
|
'operation-4xx-response': operation_4xx_response_1.Operation4xxResponse,
|
|
61
|
-
|
|
61
|
+
assertions: assertions_1.Assertions,
|
|
62
62
|
'operation-operationId-unique': operation_operationId_unique_1.OperationIdUnique,
|
|
63
63
|
'operation-parameters-unique': operation_parameters_unique_1.OperationParametersUnique,
|
|
64
64
|
'path-parameters-defined': path_params_defined_1.PathParamsDefined,
|
|
@@ -5,7 +5,7 @@ const ref_utils_1 = require("../../ref-utils");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const ValidContentExamples = (opts) => {
|
|
7
7
|
var _a;
|
|
8
|
-
const
|
|
8
|
+
const allowAdditionalProperties = (_a = utils_1.getAdditionalPropertiesOption(opts)) !== null && _a !== void 0 ? _a : false;
|
|
9
9
|
return {
|
|
10
10
|
MediaType: {
|
|
11
11
|
leave(mediaType, ctx) {
|
|
@@ -28,7 +28,7 @@ const ValidContentExamples = (opts) => {
|
|
|
28
28
|
location = isMultiple ? resolved.location.child('value') : resolved.location;
|
|
29
29
|
example = resolved.node;
|
|
30
30
|
}
|
|
31
|
-
utils_1.validateExample(isMultiple ? example.value : example, mediaType.schema, location, ctx,
|
|
31
|
+
utils_1.validateExample(isMultiple ? example.value : example, mediaType.schema, location, ctx, allowAdditionalProperties);
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
},
|
|
@@ -24,13 +24,13 @@ const RemoveUnusedComponents = () => {
|
|
|
24
24
|
name: key.toString(),
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
28
|
},
|
|
29
29
|
DefinitionRoot: {
|
|
30
30
|
leave(root, ctx) {
|
|
31
31
|
const data = ctx.getVisitorData();
|
|
32
32
|
data.removedCount = 0;
|
|
33
|
-
components.forEach(usageInfo => {
|
|
33
|
+
components.forEach((usageInfo) => {
|
|
34
34
|
const { used, componentType, name } = usageInfo;
|
|
35
35
|
if (!used && componentType) {
|
|
36
36
|
let componentChild = root.components[componentType];
|
package/lib/rules/other/stats.js
CHANGED
|
@@ -3,10 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Stats = void 0;
|
|
4
4
|
const Stats = (statsAccumulator) => {
|
|
5
5
|
return {
|
|
6
|
-
ExternalDocs: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
ExternalDocs: {
|
|
7
|
+
leave() {
|
|
8
|
+
statsAccumulator.externalDocs.total++;
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
ref: {
|
|
12
|
+
enter(ref) {
|
|
13
|
+
statsAccumulator.refs.items.add(ref['$ref']);
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
Tag: {
|
|
17
|
+
leave(tag) {
|
|
18
|
+
statsAccumulator.tags.items.add(tag.name);
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
Link: {
|
|
22
|
+
leave(link) {
|
|
23
|
+
statsAccumulator.links.items.add(link.operationId);
|
|
24
|
+
},
|
|
25
|
+
},
|
|
10
26
|
DefinitionRoot: {
|
|
11
27
|
leave() {
|
|
12
28
|
statsAccumulator.parameters.total = statsAccumulator.parameters.items.size;
|
|
@@ -18,27 +34,40 @@ const Stats = (statsAccumulator) => {
|
|
|
18
34
|
WebhooksMap: {
|
|
19
35
|
Operation: {
|
|
20
36
|
leave(operation) {
|
|
21
|
-
operation.tags.forEach((tag) => {
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
operation.tags.forEach((tag) => {
|
|
38
|
+
statsAccumulator.tags.items.add(tag);
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
},
|
|
24
42
|
},
|
|
25
43
|
PathMap: {
|
|
26
44
|
PathItem: {
|
|
27
|
-
leave() {
|
|
45
|
+
leave() {
|
|
46
|
+
statsAccumulator.pathItems.total++;
|
|
47
|
+
},
|
|
28
48
|
Operation: {
|
|
29
49
|
leave(operation) {
|
|
30
50
|
statsAccumulator.operations.total++;
|
|
31
|
-
operation.tags &&
|
|
32
|
-
|
|
51
|
+
operation.tags &&
|
|
52
|
+
operation.tags.forEach((tag) => {
|
|
53
|
+
statsAccumulator.tags.items.add(tag);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
33
56
|
},
|
|
34
|
-
Parameter: {
|
|
57
|
+
Parameter: {
|
|
58
|
+
leave(parameter) {
|
|
35
59
|
statsAccumulator.parameters.items.add(parameter.name);
|
|
36
|
-
}
|
|
60
|
+
},
|
|
61
|
+
},
|
|
37
62
|
},
|
|
38
63
|
},
|
|
39
64
|
NamedSchemas: {
|
|
40
|
-
Schema: {
|
|
41
|
-
|
|
65
|
+
Schema: {
|
|
66
|
+
leave() {
|
|
67
|
+
statsAccumulator.schemas.total++;
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
42
71
|
};
|
|
43
72
|
};
|
|
44
73
|
exports.Stats = Stats;
|
package/lib/rules/utils.d.ts
CHANGED
|
@@ -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" | "array" | "null";
|
|
4
|
+
export declare function oasTypeOf(value: unknown): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "integer" | "array" | "null";
|
|
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,
|
|
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;
|
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,9 +86,9 @@ 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
93
|
for (let error of errors) {
|
|
90
94
|
report({
|
|
@@ -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;
|
|
@@ -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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserContext } from './walk';
|
|
2
|
-
import
|
|
2
|
+
import { HttpResolveConfig } from './config';
|
|
3
3
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
4
4
|
export declare type StackFrame<T> = {
|
|
5
5
|
prev: StackFrame<T> | null;
|
|
@@ -38,5 +38,8 @@ export declare function isNotEmptyObject(obj: any): boolean;
|
|
|
38
38
|
export declare function isString(value: unknown): value is string;
|
|
39
39
|
export declare function isNotString<T>(value: string | T): value is T;
|
|
40
40
|
export declare function assignExisting<T>(target: Record<string, T>, obj: Record<string, T>): void;
|
|
41
|
-
export declare
|
|
41
|
+
export declare function getMatchingStatusCodeRange(code: number | string): string;
|
|
42
42
|
export declare function isCustomRuleId(id: string): boolean;
|
|
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;
|
package/lib/utils.js
CHANGED
|
@@ -9,13 +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.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.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
|
+
const path_1 = require("path");
|
|
14
15
|
const minimatch = require("minimatch");
|
|
15
16
|
const node_fetch_1 = require("node-fetch");
|
|
16
17
|
const pluralize = require("pluralize");
|
|
17
18
|
const js_yaml_1 = require("./js-yaml");
|
|
18
19
|
const config_1 = require("./config");
|
|
20
|
+
const colorette_1 = require("colorette");
|
|
19
21
|
var js_yaml_2 = require("./js-yaml");
|
|
20
22
|
Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
|
|
21
23
|
Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
|
|
@@ -173,9 +175,25 @@ function assignExisting(target, obj) {
|
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
177
|
exports.assignExisting = assignExisting;
|
|
176
|
-
|
|
178
|
+
function getMatchingStatusCodeRange(code) {
|
|
179
|
+
return `${code}`.replace(/^(\d)\d\d$/, (_, firstDigit) => `${firstDigit}XX`);
|
|
180
|
+
}
|
|
177
181
|
exports.getMatchingStatusCodeRange = getMatchingStatusCodeRange;
|
|
178
182
|
function isCustomRuleId(id) {
|
|
179
183
|
return id.includes('/');
|
|
180
184
|
}
|
|
181
185
|
exports.isCustomRuleId = isCustomRuleId;
|
|
186
|
+
function doesYamlFileExist(filePath) {
|
|
187
|
+
return ((path_1.extname(filePath) === '.yaml' || path_1.extname(filePath) === '.yml') &&
|
|
188
|
+
fs.hasOwnProperty('existsSync') &&
|
|
189
|
+
fs.existsSync(filePath));
|
|
190
|
+
}
|
|
191
|
+
exports.doesYamlFileExist = doesYamlFileExist;
|
|
192
|
+
function showWarningForDeprecatedField(deprecatedField, updatedField) {
|
|
193
|
+
process.stderr.write(`The ${colorette_1.yellow(deprecatedField)} field is deprecated. Use ${colorette_1.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;
|
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.107",
|
|
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:
|