@redocly/openapi-core 1.0.0-beta.126 → 1.0.0-beta.127
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/lib/bundle.js +5 -2
- package/lib/rules/common/spec.js +1 -0
- package/lib/rules/oas2/request-mime-type.d.ts +1 -1
- package/lib/rules/oas2/response-mime-type.d.ts +1 -1
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +2 -2
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +3 -3
- package/lib/rules/oas3/request-mime-type.d.ts +1 -1
- package/lib/rules/oas3/response-mime-type.d.ts +1 -1
- package/lib/walk.d.ts +6 -5
- package/lib/walk.js +23 -27
- package/package.json +1 -1
- package/__tests__/utils.ts +0 -88
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +0 -437
- package/src/__tests__/bundle.test.ts +0 -236
- package/src/__tests__/codeframes.test.ts +0 -530
- package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +0 -5
- package/src/__tests__/fixtures/extension.js +0 -24
- package/src/__tests__/fixtures/refs/definitions.yaml +0 -3
- package/src/__tests__/fixtures/refs/examples.yaml +0 -8
- package/src/__tests__/fixtures/refs/external-request-body.yaml +0 -13
- package/src/__tests__/fixtures/refs/externalref.yaml +0 -35
- package/src/__tests__/fixtures/refs/hosted.yaml +0 -35
- package/src/__tests__/fixtures/refs/openapi-with-external-refs-conflicting-names.yaml +0 -21
- package/src/__tests__/fixtures/refs/openapi-with-external-refs.yaml +0 -33
- package/src/__tests__/fixtures/refs/openapi-with-url-refs.yaml +0 -18
- package/src/__tests__/fixtures/refs/param-b.yaml +0 -1
- package/src/__tests__/fixtures/refs/param-c.yaml +0 -1
- package/src/__tests__/fixtures/refs/rename.yaml +0 -1
- package/src/__tests__/fixtures/refs/requestBody.yaml +0 -9
- package/src/__tests__/fixtures/refs/schema-a.yaml +0 -1
- package/src/__tests__/fixtures/refs/simple.yaml +0 -1
- package/src/__tests__/fixtures/refs/vendor.schema.yaml +0 -20
- package/src/__tests__/fixtures/resolve/External.yaml +0 -10
- package/src/__tests__/fixtures/resolve/External2.yaml +0 -4
- package/src/__tests__/fixtures/resolve/description.md +0 -3
- package/src/__tests__/fixtures/resolve/externalInfo.yaml +0 -4
- package/src/__tests__/fixtures/resolve/externalLicense.yaml +0 -1
- package/src/__tests__/fixtures/resolve/openapi-with-back.yaml +0 -13
- package/src/__tests__/fixtures/resolve/openapi-with-md-description.yaml +0 -5
- package/src/__tests__/fixtures/resolve/openapi.yaml +0 -28
- package/src/__tests__/fixtures/resolve/schemas/type-a.yaml +0 -10
- package/src/__tests__/fixtures/resolve/schemas/type-b.yaml +0 -6
- package/src/__tests__/fixtures/resolve/transitive/a.yaml +0 -1
- package/src/__tests__/fixtures/resolve/transitive/components.yaml +0 -5
- package/src/__tests__/fixtures/resolve/transitive/schemas.yaml +0 -3
- package/src/__tests__/format.test.ts +0 -76
- package/src/__tests__/js-yaml.test.ts +0 -73
- package/src/__tests__/lint.test.ts +0 -388
- package/src/__tests__/logger-browser.test.ts +0 -53
- package/src/__tests__/logger.test.ts +0 -47
- package/src/__tests__/login.test.ts +0 -17
- package/src/__tests__/normalizeVisitors.test.ts +0 -151
- package/src/__tests__/output-browser.test.ts +0 -18
- package/src/__tests__/output.test.ts +0 -15
- package/src/__tests__/ref-utils.test.ts +0 -120
- package/src/__tests__/resolve-http.test.ts +0 -77
- package/src/__tests__/resolve.test.ts +0 -430
- package/src/__tests__/utils-browser.test.ts +0 -11
- package/src/__tests__/utils.test.ts +0 -144
- package/src/__tests__/walk.test.ts +0 -1545
- package/src/benchmark/benches/lint-with-many-rules.bench.ts +0 -35
- package/src/benchmark/benches/lint-with-nested-rule.bench.ts +0 -39
- package/src/benchmark/benches/lint-with-no-rules.bench.ts +0 -20
- package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -35
- package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +0 -32
- package/src/benchmark/benches/rebilly.yaml +0 -32275
- package/src/benchmark/benches/recommended-oas3.bench.ts +0 -22
- package/src/benchmark/benches/resolve-with-no-external.bench.ts +0 -23
- package/src/benchmark/benchmark.js +0 -311
- package/src/benchmark/colors.js +0 -29
- package/src/benchmark/fork.js +0 -83
- package/src/benchmark/utils.ts +0 -36
- package/src/bundle.ts +0 -399
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +0 -161
- package/src/config/__tests__/__snapshots__/config.test.ts.snap +0 -144
- package/src/config/__tests__/config-resolvers.test.ts +0 -491
- package/src/config/__tests__/config.test.ts +0 -307
- package/src/config/__tests__/fixtures/ingore-file.ts +0 -8
- package/src/config/__tests__/fixtures/load-redocly.yaml +0 -2
- package/src/config/__tests__/fixtures/plugin-config.yaml +0 -2
- package/src/config/__tests__/fixtures/plugin.js +0 -56
- package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +0 -11
- package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +0 -69
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +0 -7
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +0 -17
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +0 -18
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +0 -15
- package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +0 -9
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +0 -80
- package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +0 -3
- package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +0 -4
- package/src/config/__tests__/load.test.ts +0 -167
- package/src/config/__tests__/resolve-plugins.test.ts +0 -27
- package/src/config/__tests__/utils.test.ts +0 -204
- package/src/config/all.ts +0 -73
- package/src/config/builtIn.ts +0 -37
- package/src/config/config-resolvers.ts +0 -465
- package/src/config/config.ts +0 -330
- package/src/config/index.ts +0 -7
- package/src/config/load.ts +0 -144
- package/src/config/minimal.ts +0 -60
- package/src/config/recommended.ts +0 -60
- package/src/config/rules.ts +0 -54
- package/src/config/types.ts +0 -216
- package/src/config/utils.ts +0 -333
- package/src/decorators/__tests__/filter-in.test.ts +0 -310
- package/src/decorators/__tests__/filter-out.test.ts +0 -335
- package/src/decorators/__tests__/media-type-examples-override.test.ts +0 -665
- package/src/decorators/__tests__/remove-x-internal.test.ts +0 -316
- package/src/decorators/__tests__/resources/request.yaml +0 -3
- package/src/decorators/__tests__/resources/response.yaml +0 -3
- package/src/decorators/common/filters/filter-helper.ts +0 -72
- package/src/decorators/common/filters/filter-in.ts +0 -18
- package/src/decorators/common/filters/filter-out.ts +0 -18
- package/src/decorators/common/info-description-override.ts +0 -24
- package/src/decorators/common/info-override.ts +0 -15
- package/src/decorators/common/media-type-examples-override.ts +0 -79
- package/src/decorators/common/operation-description-override.ts +0 -30
- package/src/decorators/common/registry-dependencies.ts +0 -25
- package/src/decorators/common/remove-x-internal.ts +0 -59
- package/src/decorators/common/tag-description-override.ts +0 -25
- package/src/decorators/oas2/index.ts +0 -20
- package/src/decorators/oas3/index.ts +0 -22
- package/src/env.ts +0 -5
- package/src/format/codeframes.ts +0 -216
- package/src/format/format.ts +0 -375
- package/src/index.ts +0 -71
- package/src/js-yaml/index.ts +0 -14
- package/src/lint.ts +0 -130
- package/src/logger.ts +0 -34
- package/src/oas-types.ts +0 -57
- package/src/output.ts +0 -7
- package/src/redocly/__tests__/redocly-client.test.ts +0 -146
- package/src/redocly/index.ts +0 -187
- package/src/redocly/redocly-client-types.ts +0 -10
- package/src/redocly/registry-api-types.ts +0 -32
- package/src/redocly/registry-api.ts +0 -149
- package/src/ref-utils.ts +0 -85
- package/src/resolve.ts +0 -417
- package/src/rules/__tests__/fixtures/code-sample.php +0 -9
- package/src/rules/__tests__/fixtures/invalid-yaml.yaml +0 -1
- package/src/rules/__tests__/fixtures/ref.yaml +0 -1
- package/src/rules/__tests__/no-unresolved-refs.test.ts +0 -257
- package/src/rules/__tests__/utils.test.ts +0 -160
- package/src/rules/ajv.ts +0 -102
- package/src/rules/common/__tests__/info-license.test.ts +0 -62
- package/src/rules/common/__tests__/license-url.test.ts +0 -63
- package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +0 -96
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +0 -210
- package/src/rules/common/__tests__/no-identical-paths.test.ts +0 -58
- package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +0 -85
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +0 -192
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +0 -231
- package/src/rules/common/__tests__/operation-operationId-unique.test.ts +0 -76
- package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +0 -45
- package/src/rules/common/__tests__/operation-parameters-unique.test.ts +0 -167
- package/src/rules/common/__tests__/operation-singular-tag.test.ts +0 -72
- package/src/rules/common/__tests__/path-http-verbs-order.test.ts +0 -95
- package/src/rules/common/__tests__/path-not-include-query.test.ts +0 -64
- package/src/rules/common/__tests__/path-params-defined.test.ts +0 -202
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +0 -108
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +0 -264
- package/src/rules/common/__tests__/security-defined.test.ts +0 -175
- package/src/rules/common/__tests__/spec.test.ts +0 -555
- package/src/rules/common/__tests__/tag-description.test.ts +0 -65
- package/src/rules/common/__tests__/tags-alphabetical.test.ts +0 -64
- package/src/rules/common/assertions/__tests__/asserts.test.ts +0 -869
- package/src/rules/common/assertions/__tests__/index.test.ts +0 -100
- package/src/rules/common/assertions/__tests__/utils.test.ts +0 -236
- package/src/rules/common/assertions/asserts.ts +0 -357
- package/src/rules/common/assertions/index.ts +0 -56
- package/src/rules/common/assertions/utils.ts +0 -331
- package/src/rules/common/info-contact.ts +0 -15
- package/src/rules/common/info-license-url.ts +0 -10
- package/src/rules/common/info-license.ts +0 -15
- package/src/rules/common/no-ambiguous-paths.ts +0 -50
- package/src/rules/common/no-enum-type-mismatch.ts +0 -52
- package/src/rules/common/no-http-verbs-in-paths.ts +0 -36
- package/src/rules/common/no-identical-paths.ts +0 -24
- package/src/rules/common/no-invalid-parameter-examples.ts +0 -36
- package/src/rules/common/no-invalid-schema-examples.ts +0 -27
- package/src/rules/common/no-path-trailing-slash.ts +0 -15
- package/src/rules/common/operation-2xx-response.ts +0 -24
- package/src/rules/common/operation-4xx-response.ts +0 -24
- package/src/rules/common/operation-description.ts +0 -13
- package/src/rules/common/operation-operationId-unique.ts +0 -21
- package/src/rules/common/operation-operationId-url-safe.ts +0 -19
- package/src/rules/common/operation-operationId.ts +0 -17
- package/src/rules/common/operation-parameters-unique.ts +0 -48
- package/src/rules/common/operation-singular-tag.ts +0 -17
- package/src/rules/common/operation-summary.ts +0 -13
- package/src/rules/common/operation-tag-defined.ts +0 -26
- package/src/rules/common/parameter-description.ts +0 -22
- package/src/rules/common/path-declaration-must-exist.ts +0 -15
- package/src/rules/common/path-excludes-patterns.ts +0 -23
- package/src/rules/common/path-http-verbs-order.ts +0 -30
- package/src/rules/common/path-not-include-query.ts +0 -17
- package/src/rules/common/path-params-defined.ts +0 -65
- package/src/rules/common/path-segment-plural.ts +0 -31
- package/src/rules/common/paths-kebab-case.ts +0 -19
- package/src/rules/common/required-string-property-missing-min-length.ts +0 -44
- package/src/rules/common/response-contains-header.ts +0 -35
- package/src/rules/common/scalar-property-missing-example.ts +0 -58
- package/src/rules/common/security-defined.ts +0 -65
- package/src/rules/common/spec.ts +0 -174
- package/src/rules/common/tag-description.ts +0 -10
- package/src/rules/common/tags-alphabetical.ts +0 -20
- package/src/rules/no-unresolved-refs.ts +0 -51
- package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +0 -110
- package/src/rules/oas2/__tests__/response-contains-header.test.ts +0 -174
- package/src/rules/oas2/__tests__/response-contains-property.test.ts +0 -155
- package/src/rules/oas2/__tests__/spec/fixtures/description.md +0 -1
- package/src/rules/oas2/__tests__/spec/info.test.ts +0 -355
- package/src/rules/oas2/__tests__/spec/operation.test.ts +0 -123
- package/src/rules/oas2/__tests__/spec/paths.test.ts +0 -245
- package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +0 -35
- package/src/rules/oas2/__tests__/spec/utils.ts +0 -32
- package/src/rules/oas2/boolean-parameter-prefixes.ts +0 -26
- package/src/rules/oas2/index.ts +0 -89
- package/src/rules/oas2/remove-unused-components.ts +0 -81
- package/src/rules/oas2/request-mime-type.ts +0 -17
- package/src/rules/oas2/response-contains-property.ts +0 -36
- package/src/rules/oas2/response-mime-type.ts +0 -17
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +0 -111
- package/src/rules/oas3/__tests__/fixtures/common.yaml +0 -11
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +0 -205
- package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +0 -65
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +0 -473
- package/src/rules/oas3/__tests__/no-server-example.com.test.ts +0 -60
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +0 -79
- package/src/rules/oas3/__tests__/no-unused-components.test.ts +0 -131
- package/src/rules/oas3/__tests__/operation-4xx-problem-details-rfc7807.test.ts +0 -145
- package/src/rules/oas3/__tests__/response-contains-header.test.ts +0 -389
- package/src/rules/oas3/__tests__/response-contains-property.test.ts +0 -403
- package/src/rules/oas3/__tests__/spec/callbacks.test.ts +0 -41
- package/src/rules/oas3/__tests__/spec/fixtures/description.md +0 -1
- package/src/rules/oas3/__tests__/spec/info.test.ts +0 -391
- package/src/rules/oas3/__tests__/spec/operation.test.ts +0 -253
- package/src/rules/oas3/__tests__/spec/paths.test.ts +0 -284
- package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +0 -77
- package/src/rules/oas3/__tests__/spec/servers.test.ts +0 -505
- package/src/rules/oas3/__tests__/spec/spec.test.ts +0 -298
- package/src/rules/oas3/__tests__/spec/utils.ts +0 -32
- package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +0 -305
- package/src/rules/oas3/boolean-parameter-prefixes.ts +0 -28
- package/src/rules/oas3/index.ts +0 -109
- package/src/rules/oas3/no-empty-servers.ts +0 -22
- package/src/rules/oas3/no-example-value-and-externalValue.ts +0 -14
- package/src/rules/oas3/no-invalid-media-type-examples.ts +0 -49
- package/src/rules/oas3/no-server-example.com.ts +0 -14
- package/src/rules/oas3/no-server-trailing-slash.ts +0 -15
- package/src/rules/oas3/no-server-variables-empty-enum.ts +0 -66
- package/src/rules/oas3/no-undefined-server-variable.ts +0 -30
- package/src/rules/oas3/no-unused-components.ts +0 -75
- package/src/rules/oas3/operation-4xx-problem-details-rfc7807.ts +0 -36
- package/src/rules/oas3/remove-unused-components.ts +0 -95
- package/src/rules/oas3/request-mime-type.ts +0 -31
- package/src/rules/oas3/response-contains-property.ts +0 -38
- package/src/rules/oas3/response-mime-type.ts +0 -31
- package/src/rules/oas3/spec-components-invalid-map-name.ts +0 -74
- package/src/rules/other/stats.ts +0 -73
- package/src/rules/utils.ts +0 -191
- package/src/types/index.ts +0 -149
- package/src/types/oas2.ts +0 -478
- package/src/types/oas3.ts +0 -597
- package/src/types/oas3_1.ts +0 -258
- package/src/types/redocly-yaml.ts +0 -1010
- package/src/typings/common.ts +0 -17
- package/src/typings/openapi.ts +0 -298
- package/src/typings/swagger.ts +0 -236
- package/src/utils.ts +0 -276
- package/src/visitors.ts +0 -491
- package/src/walk.ts +0 -453
- package/tsconfig.json +0 -8
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule } from '../../visitors';
|
|
2
|
-
import { Problem, UserContext } from '../../walk';
|
|
3
|
-
import { Location } from '../../ref-utils';
|
|
4
|
-
|
|
5
|
-
export const SpecComponentsInvalidMapName: Oas3Rule = () => {
|
|
6
|
-
const KEYS_REGEX = '^[a-zA-Z0-9\\.\\-_]+$';
|
|
7
|
-
|
|
8
|
-
function validateKey(
|
|
9
|
-
key: string | number,
|
|
10
|
-
report: (problem: Problem) => void,
|
|
11
|
-
location: Location,
|
|
12
|
-
component: string
|
|
13
|
-
) {
|
|
14
|
-
if (!new RegExp(KEYS_REGEX).test(key as string)) {
|
|
15
|
-
report({
|
|
16
|
-
message: `The map key in ${component} "${key}" does not match the regular expression "${KEYS_REGEX}"`,
|
|
17
|
-
location: location.key(),
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
NamedSchemas: {
|
|
24
|
-
Schema(_node, { key, report, location }: UserContext) {
|
|
25
|
-
validateKey(key, report, location, 'schemas');
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
NamedParameters: {
|
|
29
|
-
Parameter(_node, { key, report, location }: UserContext) {
|
|
30
|
-
validateKey(key, report, location, 'parameters');
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
NamedResponses: {
|
|
34
|
-
Response(_node, { key, report, location }: UserContext) {
|
|
35
|
-
validateKey(key, report, location, 'responses');
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
NamedExamples: {
|
|
39
|
-
Example(_node, { key, report, location }: UserContext) {
|
|
40
|
-
validateKey(key, report, location, 'examples');
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
NamedRequestBodies: {
|
|
44
|
-
RequestBody(_node, { key, report, location }: UserContext) {
|
|
45
|
-
validateKey(key, report, location, 'requestBodies');
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
NamedHeaders: {
|
|
49
|
-
Header(_node, { key, report, location }: UserContext) {
|
|
50
|
-
validateKey(key, report, location, 'headers');
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
NamedSecuritySchemes: {
|
|
54
|
-
SecurityScheme(_node, { key, report, location }: UserContext) {
|
|
55
|
-
validateKey(key, report, location, 'securitySchemes');
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
NamedLinks: {
|
|
59
|
-
Link(_node, { key, report, location }: UserContext) {
|
|
60
|
-
validateKey(key, report, location, 'links');
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
NamedCallbacks: {
|
|
64
|
-
Callback(_node, { key, report, location }: UserContext) {
|
|
65
|
-
validateKey(key, report, location, 'callbacks');
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
ExampleMap: {
|
|
69
|
-
Example(_node, { key, report, location }: UserContext) {
|
|
70
|
-
validateKey(key, report, location, 'examples');
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
};
|
package/src/rules/other/stats.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Oas3Parameter, OasRef, Oas3Tag } from '../../typings/openapi';
|
|
2
|
-
import { Oas2Parameter } from '../../typings/swagger';
|
|
3
|
-
import { StatsAccumulator } from '../../typings/common';
|
|
4
|
-
|
|
5
|
-
export const Stats = (statsAccumulator: StatsAccumulator) => {
|
|
6
|
-
return {
|
|
7
|
-
ExternalDocs: {
|
|
8
|
-
leave() {
|
|
9
|
-
statsAccumulator.externalDocs.total++;
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
ref: {
|
|
13
|
-
enter(ref: OasRef) {
|
|
14
|
-
statsAccumulator.refs.items!.add(ref['$ref']);
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
Tag: {
|
|
18
|
-
leave(tag: Oas3Tag) {
|
|
19
|
-
statsAccumulator.tags.items!.add(tag.name);
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
Link: {
|
|
23
|
-
leave(link: any) {
|
|
24
|
-
statsAccumulator.links.items!.add(link.operationId);
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
Root: {
|
|
28
|
-
leave() {
|
|
29
|
-
statsAccumulator.parameters.total = statsAccumulator.parameters.items!.size;
|
|
30
|
-
statsAccumulator.refs.total = statsAccumulator.refs.items!.size;
|
|
31
|
-
statsAccumulator.links.total = statsAccumulator.links.items!.size;
|
|
32
|
-
statsAccumulator.tags.total = statsAccumulator.tags.items!.size;
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
WebhooksMap: {
|
|
36
|
-
Operation: {
|
|
37
|
-
leave(operation: any) {
|
|
38
|
-
operation.tags.forEach((tag: string) => {
|
|
39
|
-
statsAccumulator.tags.items!.add(tag);
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
Paths: {
|
|
45
|
-
PathItem: {
|
|
46
|
-
leave() {
|
|
47
|
-
statsAccumulator.pathItems.total++;
|
|
48
|
-
},
|
|
49
|
-
Operation: {
|
|
50
|
-
leave(operation: any) {
|
|
51
|
-
statsAccumulator.operations.total++;
|
|
52
|
-
operation.tags &&
|
|
53
|
-
operation.tags.forEach((tag: string) => {
|
|
54
|
-
statsAccumulator.tags.items!.add(tag);
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
Parameter: {
|
|
59
|
-
leave(parameter: Oas2Parameter | Oas3Parameter) {
|
|
60
|
-
statsAccumulator.parameters.items!.add(parameter.name);
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
NamedSchemas: {
|
|
66
|
-
Schema: {
|
|
67
|
-
leave() {
|
|
68
|
-
statsAccumulator.schemas.total++;
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
};
|
package/src/rules/utils.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import levenshtein = require('js-levenshtein');
|
|
2
|
-
import { UserContext } from '../walk';
|
|
3
|
-
import { Location } from '../ref-utils';
|
|
4
|
-
import { validateJsonSchema } from './ajv';
|
|
5
|
-
import { Oas3Schema, Referenced } from '../typings/openapi';
|
|
6
|
-
import { showErrorForDeprecatedField, showWarningForDeprecatedField } from '../utils';
|
|
7
|
-
|
|
8
|
-
export function oasTypeOf(value: unknown) {
|
|
9
|
-
if (Array.isArray(value)) {
|
|
10
|
-
return 'array';
|
|
11
|
-
} else if (value === null) {
|
|
12
|
-
return 'null';
|
|
13
|
-
} else if (Number.isInteger(value)) {
|
|
14
|
-
return 'integer';
|
|
15
|
-
} else {
|
|
16
|
-
return typeof value;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Checks if value matches specified JSON schema type
|
|
22
|
-
*
|
|
23
|
-
* @param {*} value - value to check
|
|
24
|
-
* @param {JSONSchemaType} type - JSON Schema type
|
|
25
|
-
* @returns boolean
|
|
26
|
-
*/
|
|
27
|
-
export function matchesJsonSchemaType(value: unknown, type: string, nullable: boolean): boolean {
|
|
28
|
-
if (nullable && value === null) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
switch (type) {
|
|
33
|
-
case 'array':
|
|
34
|
-
return Array.isArray(value);
|
|
35
|
-
case 'object':
|
|
36
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
37
|
-
case 'null':
|
|
38
|
-
return value === null;
|
|
39
|
-
case 'integer':
|
|
40
|
-
return Number.isInteger(value);
|
|
41
|
-
default:
|
|
42
|
-
return typeof value === type;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function missingRequiredField(type: string, field: string): string {
|
|
47
|
-
return `${type} object should contain \`${field}\` field.`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function fieldNonEmpty(type: string, field: string): string {
|
|
51
|
-
return `${type} object \`${field}\` must be non-empty string.`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function validateDefinedAndNonEmpty(fieldName: string, value: any, ctx: UserContext) {
|
|
55
|
-
if (typeof value !== 'object') {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (value[fieldName] === undefined) {
|
|
60
|
-
ctx.report({
|
|
61
|
-
message: missingRequiredField(ctx.type.name, fieldName),
|
|
62
|
-
location: ctx.location.child([fieldName]).key(),
|
|
63
|
-
});
|
|
64
|
-
} else if (!value[fieldName]) {
|
|
65
|
-
ctx.report({
|
|
66
|
-
message: fieldNonEmpty(ctx.type.name, fieldName),
|
|
67
|
-
location: ctx.location.child([fieldName]).key(),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function getSuggest(given: string, variants: string[]): string[] {
|
|
73
|
-
if (typeof given !== 'string' || !variants.length) return [];
|
|
74
|
-
|
|
75
|
-
const distances: Array<{ variant: string; distance: number }> = [];
|
|
76
|
-
|
|
77
|
-
for (let i = 0; i < variants.length; i++) {
|
|
78
|
-
const distance = levenshtein(given, variants[i]);
|
|
79
|
-
if (distance < 4) {
|
|
80
|
-
distances.push({ distance, variant: variants[i] });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
distances.sort((a, b) => a.distance - b.distance);
|
|
85
|
-
|
|
86
|
-
// if (bestMatch.distance <= 4) return bestMatch.string;
|
|
87
|
-
return distances.map((d) => d.variant);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function validateExample(
|
|
91
|
-
example: any,
|
|
92
|
-
schema: Referenced<Oas3Schema>,
|
|
93
|
-
dataLoc: Location,
|
|
94
|
-
{ resolve, location, report }: UserContext,
|
|
95
|
-
allowAdditionalProperties: boolean
|
|
96
|
-
) {
|
|
97
|
-
try {
|
|
98
|
-
const { valid, errors } = validateJsonSchema(
|
|
99
|
-
example,
|
|
100
|
-
schema,
|
|
101
|
-
location.child('schema'),
|
|
102
|
-
dataLoc.pointer,
|
|
103
|
-
resolve,
|
|
104
|
-
allowAdditionalProperties
|
|
105
|
-
);
|
|
106
|
-
if (!valid) {
|
|
107
|
-
for (const error of errors) {
|
|
108
|
-
report({
|
|
109
|
-
message: `Example value must conform to the schema: ${error.message}.`,
|
|
110
|
-
location: {
|
|
111
|
-
...new Location(dataLoc.source, error.instancePath),
|
|
112
|
-
reportOnKey:
|
|
113
|
-
error.keyword === 'unevaluatedProperties' || error.keyword === 'additionalProperties',
|
|
114
|
-
},
|
|
115
|
-
from: location,
|
|
116
|
-
suggest: error.suggest,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} catch (e) {
|
|
121
|
-
if (e.message === 'discriminator: requires oneOf or anyOf composite keyword') {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
report({
|
|
126
|
-
message: `Example validation errored: ${e.message}.`,
|
|
127
|
-
location: location.child('schema'),
|
|
128
|
-
from: location,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function getAdditionalPropertiesOption(opts: Record<string, any>): boolean {
|
|
134
|
-
if (opts.disallowAdditionalProperties === undefined) {
|
|
135
|
-
return opts.allowAdditionalProperties;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (opts.allowAdditionalProperties !== undefined) {
|
|
139
|
-
showErrorForDeprecatedField(
|
|
140
|
-
'disallowAdditionalProperties',
|
|
141
|
-
'allowAdditionalProperties',
|
|
142
|
-
undefined
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
showWarningForDeprecatedField('disallowAdditionalProperties', 'allowAdditionalProperties');
|
|
147
|
-
return !opts.disallowAdditionalProperties;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export function validateSchemaEnumType(
|
|
151
|
-
schemaEnum: string[],
|
|
152
|
-
propertyValue: string,
|
|
153
|
-
propName: string,
|
|
154
|
-
refLocation: Location | undefined,
|
|
155
|
-
{ report, location }: UserContext
|
|
156
|
-
) {
|
|
157
|
-
if (!schemaEnum) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if (!schemaEnum.includes(propertyValue === null ? 'null' : propertyValue)) {
|
|
161
|
-
report({
|
|
162
|
-
location,
|
|
163
|
-
message: `\`${propName}\` can be one of the following only: ${schemaEnum
|
|
164
|
-
.map((type) => `"${type}"`)
|
|
165
|
-
.join(', ')}.`,
|
|
166
|
-
from: refLocation,
|
|
167
|
-
suggest: getSuggest(propertyValue, schemaEnum),
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function validateResponseCodes(
|
|
173
|
-
responseCodes: string[],
|
|
174
|
-
codeRange: string,
|
|
175
|
-
{ report }: UserContext
|
|
176
|
-
) {
|
|
177
|
-
const responseCodeRegexp = new RegExp(`^${codeRange[0]}[0-9Xx]{2}$`);
|
|
178
|
-
|
|
179
|
-
const containsNeededCode = responseCodes.some(
|
|
180
|
-
(code) =>
|
|
181
|
-
(codeRange === '2XX' && code === 'default') || // It's OK to replace 2xx codes with the default
|
|
182
|
-
responseCodeRegexp.test(code)
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
if (!containsNeededCode) {
|
|
186
|
-
report({
|
|
187
|
-
message: `Operation must have at least one \`${codeRange}\` response.`,
|
|
188
|
-
location: { reportOnKey: true },
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
export type ScalarSchema = {
|
|
2
|
-
name?: never;
|
|
3
|
-
type?: 'string' | 'boolean' | 'number' | 'integer' | 'object' | 'array';
|
|
4
|
-
items?: ScalarSchema;
|
|
5
|
-
enum?: string[];
|
|
6
|
-
isExample?: boolean;
|
|
7
|
-
directResolveAs?: string;
|
|
8
|
-
minimum?: number;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type NormalizedScalarSchema = {
|
|
12
|
-
name?: never;
|
|
13
|
-
type?: 'string' | 'boolean' | 'number' | 'integer' | 'object' | 'array';
|
|
14
|
-
items?: ScalarSchema;
|
|
15
|
-
enum?: string[];
|
|
16
|
-
directResolveAs?: NormalizedNodeType;
|
|
17
|
-
resolvable: boolean;
|
|
18
|
-
minimum?: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type NodeType = {
|
|
22
|
-
properties: Record<string, PropType | ResolveTypeFn>;
|
|
23
|
-
additionalProperties?: PropType | ResolveTypeFn;
|
|
24
|
-
items?: string;
|
|
25
|
-
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
26
|
-
requiredOneOf?: string[];
|
|
27
|
-
allowed?: (value: any) => string[] | undefined;
|
|
28
|
-
extensionsPrefix?: string;
|
|
29
|
-
};
|
|
30
|
-
type PropType = string | NodeType | ScalarSchema | undefined | null;
|
|
31
|
-
type ResolveTypeFn = (value: any, key: string) => string | PropType;
|
|
32
|
-
|
|
33
|
-
export type NormalizedNodeType = {
|
|
34
|
-
name: string;
|
|
35
|
-
properties: Record<string, NormalizedPropType | NormalizedResolveTypeFn>;
|
|
36
|
-
additionalProperties?: NormalizedPropType | NormalizedResolveTypeFn;
|
|
37
|
-
items?: NormalizedNodeType;
|
|
38
|
-
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
39
|
-
requiredOneOf?: string[];
|
|
40
|
-
allowed?: (value: any) => string[] | undefined;
|
|
41
|
-
extensionsPrefix?: string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | undefined | null;
|
|
45
|
-
type NormalizedResolveTypeFn = (
|
|
46
|
-
value: any,
|
|
47
|
-
key: string
|
|
48
|
-
) => NormalizedNodeType | NormalizedScalarSchema | undefined | null;
|
|
49
|
-
|
|
50
|
-
export function listOf(typeName: string) {
|
|
51
|
-
return {
|
|
52
|
-
name: `${typeName}List`,
|
|
53
|
-
properties: {},
|
|
54
|
-
items: typeName,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function mapOf(typeName: string) {
|
|
59
|
-
return {
|
|
60
|
-
name: `${typeName}Map`,
|
|
61
|
-
properties: {},
|
|
62
|
-
additionalProperties: () => typeName,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const SpecExtension: NormalizedNodeType = {
|
|
67
|
-
name: 'SpecExtension',
|
|
68
|
-
properties: {},
|
|
69
|
-
// skip validation of additional properties for unknown extensions
|
|
70
|
-
additionalProperties: { resolvable: true },
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export function normalizeTypes(
|
|
74
|
-
types: Record<string, NodeType>,
|
|
75
|
-
options: { doNotResolveExamples?: boolean } = {}
|
|
76
|
-
): Record<string, NormalizedNodeType> {
|
|
77
|
-
const normalizedTypes: Record<string, NormalizedNodeType> = {};
|
|
78
|
-
|
|
79
|
-
for (const typeName of Object.keys(types)) {
|
|
80
|
-
normalizedTypes[typeName] = {
|
|
81
|
-
...types[typeName],
|
|
82
|
-
name: typeName,
|
|
83
|
-
} as NormalizedNodeType;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
for (const type of Object.values(normalizedTypes)) {
|
|
87
|
-
normalizeType(type);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// all type trees have a SpecExtension type by default
|
|
91
|
-
normalizedTypes['SpecExtension'] = SpecExtension;
|
|
92
|
-
|
|
93
|
-
return normalizedTypes;
|
|
94
|
-
|
|
95
|
-
function normalizeType(type: NormalizedNodeType) {
|
|
96
|
-
if (type.additionalProperties) {
|
|
97
|
-
type.additionalProperties = resolveType(type.additionalProperties);
|
|
98
|
-
}
|
|
99
|
-
if (type.items) {
|
|
100
|
-
type.items = resolveType(type.items);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (type.properties) {
|
|
104
|
-
const mappedProps: Record<string, any> = {};
|
|
105
|
-
for (const [propName, prop] of Object.entries(type.properties)) {
|
|
106
|
-
mappedProps[propName] = resolveType(prop);
|
|
107
|
-
|
|
108
|
-
if (options.doNotResolveExamples && prop && (prop as ScalarSchema).isExample) {
|
|
109
|
-
mappedProps[propName] = {
|
|
110
|
-
...(prop as object),
|
|
111
|
-
resolvable: false,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
type.properties = mappedProps;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// typings are painful here...
|
|
120
|
-
function resolveType(type?: any): any {
|
|
121
|
-
if (typeof type === 'string') {
|
|
122
|
-
if (!normalizedTypes[type]) {
|
|
123
|
-
throw new Error(`Unknown type name found: ${type}`);
|
|
124
|
-
}
|
|
125
|
-
return normalizedTypes[type];
|
|
126
|
-
} else if (typeof type === 'function') {
|
|
127
|
-
return (value: any, key: string) => {
|
|
128
|
-
return resolveType(type(value, key));
|
|
129
|
-
};
|
|
130
|
-
} else if (type && type.name) {
|
|
131
|
-
type = { ...type };
|
|
132
|
-
normalizeType(type);
|
|
133
|
-
return type;
|
|
134
|
-
} else if (type && type.directResolveAs) {
|
|
135
|
-
return {
|
|
136
|
-
...type,
|
|
137
|
-
directResolveAs: resolveType(type.directResolveAs),
|
|
138
|
-
};
|
|
139
|
-
} else {
|
|
140
|
-
return type;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function isNamedType(
|
|
146
|
-
t: NormalizedNodeType | NormalizedScalarSchema | null | undefined
|
|
147
|
-
): t is NormalizedNodeType {
|
|
148
|
-
return typeof t?.name === 'string';
|
|
149
|
-
}
|