@redocly/openapi-core 1.0.0-beta.99 → 1.0.0-rc.1
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 +6 -6
- 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/benches/resolve-with-no-external.bench.js +1 -1
- package/lib/benchmark/utils.d.ts +2 -2
- package/lib/benchmark/utils.js +2 -2
- package/lib/bundle.d.ts +10 -15
- package/lib/bundle.js +32 -12
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +16 -6
- 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 +121 -66
- package/lib/config/config.d.ts +12 -18
- package/lib/config/config.js +42 -26
- package/lib/config/load.d.ts +16 -3
- package/lib/config/load.js +36 -14
- package/lib/config/minimal.d.ts +2 -2
- package/lib/config/minimal.js +10 -6
- package/lib/config/recommended.d.ts +2 -2
- package/lib/config/recommended.js +10 -6
- package/lib/config/rules.d.ts +7 -4
- package/lib/config/rules.js +5 -4
- package/lib/config/types.d.ts +72 -23
- package/lib/config/types.js +13 -0
- package/lib/config/utils.d.ts +6 -5
- package/lib/config/utils.js +110 -32
- package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
- package/lib/decorators/common/filters/filter-helper.js +67 -0
- package/lib/decorators/common/filters/filter-in.d.ts +2 -0
- package/lib/decorators/common/filters/filter-in.js +17 -0
- package/lib/decorators/common/filters/filter-out.d.ts +2 -0
- package/lib/decorators/common/filters/filter-out.js +17 -0
- package/lib/decorators/common/info-override.d.ts +2 -0
- package/lib/decorators/common/info-override.js +28 -0
- package/lib/decorators/common/media-type-examples-override.d.ts +2 -0
- package/lib/decorators/common/media-type-examples-override.js +53 -0
- package/lib/decorators/common/registry-dependencies.js +2 -2
- package/lib/decorators/common/remove-x-internal.js +2 -2
- package/lib/decorators/oas2/index.d.ts +3 -0
- package/lib/decorators/oas2/index.js +7 -1
- package/lib/decorators/oas3/index.d.ts +4 -0
- package/lib/decorators/oas3/index.js +9 -1
- package/lib/env.d.ts +3 -0
- package/lib/env.js +8 -0
- package/lib/format/codeframes.js +16 -10
- package/lib/format/format.d.ts +1 -1
- package/lib/format/format.js +64 -32
- package/lib/index.d.ts +6 -6
- package/lib/index.js +7 -2
- package/lib/js-yaml/index.js +2 -6
- package/lib/lint.d.ts +4 -2
- package/lib/lint.js +36 -11
- 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 -28
- package/lib/redocly/registry-api.d.ts +3 -3
- package/lib/redocly/registry-api.js +10 -2
- package/lib/ref-utils.d.ts +1 -0
- package/lib/ref-utils.js +7 -2
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +33 -3
- package/lib/rules/ajv.d.ts +2 -2
- package/lib/rules/ajv.js +12 -12
- package/lib/rules/common/assertions/asserts.d.ts +29 -4
- package/lib/rules/common/assertions/asserts.js +227 -97
- package/lib/rules/common/assertions/index.d.ts +27 -2
- package/lib/rules/common/assertions/index.js +9 -37
- package/lib/rules/common/assertions/utils.d.ts +16 -8
- package/lib/rules/common/assertions/utils.js +160 -76
- 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-ambiguous-paths.js +1 -1
- package/lib/rules/common/no-enum-type-mismatch.js +1 -3
- package/lib/rules/common/no-identical-paths.js +4 -4
- 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-2xx-response.js +15 -9
- package/lib/rules/common/operation-4xx-response.js +15 -9
- package/lib/rules/common/operation-operationId.js +2 -2
- package/lib/rules/common/operation-tag-defined.js +1 -1
- package/lib/rules/common/path-not-include-query.js +2 -2
- package/lib/rules/common/path-params-defined.js +7 -2
- package/lib/rules/common/paths-kebab-case.js +4 -1
- package/lib/rules/common/required-string-property-missing-min-length.d.ts +2 -0
- package/lib/rules/common/required-string-property-missing-min-length.js +37 -0
- package/lib/rules/common/response-contains-header.js +2 -2
- package/lib/rules/common/scalar-property-missing-example.js +2 -1
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/{operation-security-defined.js → security-defined.js} +25 -6
- package/lib/rules/common/spec-strict-refs.d.ts +2 -0
- package/lib/rules/common/spec-strict-refs.js +30 -0
- package/lib/rules/common/spec.js +41 -18
- package/lib/rules/common/tags-alphabetical.js +1 -1
- package/lib/rules/oas2/index.d.ts +3 -2
- package/lib/rules/oas2/index.js +10 -8
- package/lib/rules/oas2/remove-unused-components.js +6 -6
- package/lib/rules/oas2/request-mime-type.d.ts +1 -1
- package/lib/rules/oas2/request-mime-type.js +1 -1
- package/lib/rules/oas2/response-mime-type.d.ts +1 -1
- package/lib/rules/oas2/response-mime-type.js +1 -1
- package/lib/rules/oas3/component-name-unique.d.ts +2 -0
- package/lib/rules/oas3/component-name-unique.js +124 -0
- package/lib/rules/oas3/index.js +18 -10
- package/lib/rules/oas3/no-empty-servers.js +2 -2
- 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} +5 -5
- package/lib/rules/oas3/no-unused-components.js +2 -2
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.d.ts +5 -0
- package/lib/rules/oas3/operation-4xx-problem-details-rfc7807.js +36 -0
- package/lib/rules/oas3/remove-unused-components.js +6 -6
- package/lib/rules/oas3/request-mime-type.d.ts +1 -1
- package/lib/rules/oas3/request-mime-type.js +1 -1
- package/lib/rules/oas3/response-mime-type.d.ts +1 -1
- package/lib/rules/oas3/response-mime-type.js +1 -1
- package/lib/rules/oas3/spec-components-invalid-map-name.d.ts +2 -0
- package/lib/rules/oas3/spec-components-invalid-map-name.js +62 -0
- package/lib/rules/other/stats.d.ts +2 -2
- package/lib/rules/other/stats.js +45 -16
- package/lib/rules/utils.d.ts +5 -2
- package/lib/rules/utils.js +54 -6
- package/lib/types/config-external-schemas.d.ts +2193 -0
- package/lib/types/config-external-schemas.js +805 -0
- package/lib/types/index.d.ts +3 -2
- package/lib/types/index.js +9 -1
- package/lib/types/oas2.js +91 -15
- package/lib/types/oas3.js +125 -46
- package/lib/types/oas3_1.js +23 -19
- package/lib/types/redocly-yaml.js +406 -60
- package/lib/utils.d.ts +15 -4
- package/lib/utils.js +72 -8
- package/lib/visitors.d.ts +20 -16
- package/lib/visitors.js +28 -3
- package/lib/walk.d.ts +11 -19
- package/lib/walk.js +74 -53
- package/package.json +5 -6
- package/__tests__/utils.ts +0 -86
- package/lib/rules/common/info-description.d.ts +0 -2
- package/lib/rules/common/info-description.js +0 -12
- package/lib/rules/common/license-url.d.ts +0 -2
- package/lib/rules/common/license-url.js +0 -12
- package/lib/rules/common/operation-security-defined.d.ts +0 -2
- package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +0 -255
- package/src/__tests__/bundle.test.ts +0 -156
- package/src/__tests__/codeframes.test.ts +0 -531
- 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__/js-yaml.test.ts +0 -71
- package/src/__tests__/lint.test.ts +0 -195
- package/src/__tests__/login.test.ts +0 -17
- package/src/__tests__/normalizeVisitors.test.ts +0 -151
- 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 -405
- package/src/__tests__/utils.test.ts +0 -85
- package/src/__tests__/walk.test.ts +0 -1485
- 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 -36
- package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +0 -32
- package/src/benchmark/benches/rebilly.yaml +0 -32267
- 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 -307
- 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 -386
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +0 -157
- package/src/config/__tests__/config-resolvers.test.ts +0 -429
- package/src/config/__tests__/config.test.ts +0 -244
- package/src/config/__tests__/fixtures/plugin-config.yaml +0 -3
- package/src/config/__tests__/fixtures/plugin.js +0 -56
- package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +0 -12
- package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +0 -67
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +0 -8
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +0 -19
- package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +0 -10
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +0 -66
- package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +0 -4
- package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +0 -5
- package/src/config/__tests__/load.test.ts +0 -83
- package/src/config/__tests__/resolve-plugins.test.ts +0 -27
- package/src/config/all.ts +0 -66
- package/src/config/builtIn.ts +0 -37
- package/src/config/config-resolvers.ts +0 -359
- package/src/config/config.ts +0 -312
- package/src/config/index.ts +0 -7
- package/src/config/load.ts +0 -84
- package/src/config/minimal.ts +0 -58
- package/src/config/recommended.ts +0 -58
- package/src/config/rules.ts +0 -46
- package/src/config/types.ts +0 -168
- package/src/config/utils.ts +0 -208
- package/src/decorators/__tests__/remove-x-internal.test.ts +0 -316
- package/src/decorators/common/info-description-override.ts +0 -24
- 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 -14
- package/src/decorators/oas3/index.ts +0 -14
- package/src/format/codeframes.ts +0 -210
- package/src/format/format.ts +0 -339
- package/src/index.ts +0 -68
- package/src/js-yaml/index.ts +0 -18
- package/src/lint.ts +0 -125
- package/src/oas-types.ts +0 -62
- package/src/redocly/__tests__/redocly-client.test.ts +0 -140
- package/src/redocly/index.ts +0 -182
- 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 -134
- package/src/ref-utils.ts +0 -80
- package/src/resolve.ts +0 -378
- 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 -168
- package/src/rules/ajv.ts +0 -103
- package/src/rules/common/__tests__/info-description.test.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 -209
- 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 -91
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +0 -107
- 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-security-defined.test.ts +0 -69
- 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 -133
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +0 -108
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +0 -207
- package/src/rules/common/__tests__/spec.test.ts +0 -62
- 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 -231
- package/src/rules/common/assertions/__tests__/index.test.ts +0 -65
- package/src/rules/common/assertions/__tests__/utils.test.ts +0 -89
- package/src/rules/common/assertions/asserts.ts +0 -137
- package/src/rules/common/assertions/index.ts +0 -75
- package/src/rules/common/assertions/utils.ts +0 -167
- package/src/rules/common/info-contact.ts +0 -15
- package/src/rules/common/info-description.ts +0 -10
- package/src/rules/common/info-license-url.ts +0 -15
- package/src/rules/common/license-url.ts +0 -10
- package/src/rules/common/no-ambiguous-paths.ts +0 -50
- package/src/rules/common/no-enum-type-mismatch.ts +0 -49
- 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 -16
- package/src/rules/common/operation-4xx-response.ts +0 -17
- 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-security-defined.ts +0 -45
- 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 -58
- package/src/rules/common/path-segment-plural.ts +0 -31
- package/src/rules/common/paths-kebab-case.ts +0 -16
- package/src/rules/common/response-contains-header.ts +0 -30
- package/src/rules/common/scalar-property-missing-example.ts +0 -55
- package/src/rules/common/spec.ts +0 -143
- 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 -31
- 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 -76
- 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 -392
- 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__/response-contains-header.test.ts +0 -273
- 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 -499
- package/src/rules/oas3/__tests__/spec/spec.test.ts +0 -288
- package/src/rules/oas3/__tests__/spec/utils.ts +0 -32
- package/src/rules/oas3/boolean-parameter-prefixes.ts +0 -28
- package/src/rules/oas3/index.ts +0 -105
- 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 -41
- 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-servers-empty-enum.ts +0 -67
- 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/remove-unused-components.ts +0 -84
- 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/other/stats.ts +0 -44
- package/src/rules/utils.ts +0 -123
- package/src/types/index.ts +0 -138
- package/src/types/oas2.ts +0 -397
- package/src/types/oas3.ts +0 -515
- package/src/types/oas3_1.ts +0 -253
- package/src/types/redocly-yaml.ts +0 -647
- package/src/typings/common.ts +0 -9
- package/src/typings/openapi.ts +0 -298
- package/src/typings/swagger.ts +0 -236
- package/src/utils.ts +0 -193
- package/src/visitors.ts +0 -448
- package/src/walk.ts +0 -416
- package/tsconfig.json +0 -8
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { OrderOptions, OrderDirection, isOrdered, getIntersectionLength } from './utils';
|
|
2
|
-
|
|
3
|
-
type Asserts = Record<string, (value: any, condition: any) => boolean>;
|
|
4
|
-
|
|
5
|
-
export const runOnKeysSet = new Set([
|
|
6
|
-
'mutuallyExclusive',
|
|
7
|
-
'mutuallyRequired',
|
|
8
|
-
'enum',
|
|
9
|
-
'pattern',
|
|
10
|
-
'minLength',
|
|
11
|
-
'maxLength',
|
|
12
|
-
'casing',
|
|
13
|
-
'sortOrder',
|
|
14
|
-
'disallowed',
|
|
15
|
-
'required',
|
|
16
|
-
]);
|
|
17
|
-
export const runOnValuesSet = new Set([
|
|
18
|
-
'pattern',
|
|
19
|
-
'enum',
|
|
20
|
-
'defined',
|
|
21
|
-
'undefined',
|
|
22
|
-
'nonEmpty',
|
|
23
|
-
'minLength',
|
|
24
|
-
'maxLength',
|
|
25
|
-
'casing',
|
|
26
|
-
'sortOrder',
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
export const asserts: Asserts = {
|
|
30
|
-
pattern: (value: string | string[], condition: string): boolean => {
|
|
31
|
-
if (typeof value === 'undefined') return true; // property doesn't exist, no need to lint it with this assert
|
|
32
|
-
const values = typeof value === 'string' ? [value] : value;
|
|
33
|
-
const regexOptions = condition.match(/(\b\/\b)(.+)/g) || ['/'];
|
|
34
|
-
condition = condition.slice(1).replace(regexOptions[0], '');
|
|
35
|
-
const regx = new RegExp(condition, regexOptions[0].slice(1));
|
|
36
|
-
for (let _val of values) {
|
|
37
|
-
if (!_val.match(regx)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
},
|
|
43
|
-
enum: (value: string | string[], condition: string[]): boolean => {
|
|
44
|
-
if (typeof value === 'undefined') return true; // property doesn't exist, no need to lint it with this assert
|
|
45
|
-
const values = typeof value === 'string' ? [value] : value;
|
|
46
|
-
for (let _val of values) {
|
|
47
|
-
if (!condition.includes(_val)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
52
|
-
},
|
|
53
|
-
defined: (value: string | undefined, condition: boolean = true): boolean => {
|
|
54
|
-
const isDefined = typeof value !== 'undefined';
|
|
55
|
-
return condition ? isDefined : !isDefined;
|
|
56
|
-
},
|
|
57
|
-
required: (value: string[], keys: string[]): boolean => {
|
|
58
|
-
for (const requiredKey of keys) {
|
|
59
|
-
if (!value.includes(requiredKey)) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
},
|
|
65
|
-
disallowed: (value: string | string[], condition: string[]): boolean => {
|
|
66
|
-
if (typeof value === 'undefined') return true; // property doesn't exist, no need to lint it with this assert
|
|
67
|
-
const values = typeof value === 'string' ? [value] : value;
|
|
68
|
-
for (let _val of values) {
|
|
69
|
-
if (condition.includes(_val)) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
},
|
|
75
|
-
undefined: (value: any, condition: boolean = true): boolean => {
|
|
76
|
-
const isUndefined = typeof value === 'undefined';
|
|
77
|
-
return condition ? isUndefined : !isUndefined;
|
|
78
|
-
},
|
|
79
|
-
nonEmpty: (value: string | undefined | null, condition: boolean = true): boolean => {
|
|
80
|
-
const isEmpty = typeof value === 'undefined' || value === null || value === '';
|
|
81
|
-
return condition ? !isEmpty : isEmpty;
|
|
82
|
-
},
|
|
83
|
-
minLength: (value: string | any[], condition: number): boolean => {
|
|
84
|
-
if (typeof value === 'undefined') return true; // property doesn't exist, no need to lint it with this assert
|
|
85
|
-
return value.length >= condition;
|
|
86
|
-
},
|
|
87
|
-
maxLength: (value: string | any[], condition: number): boolean => {
|
|
88
|
-
if (typeof value === 'undefined') return true; // property doesn't exist, no need to lint it with this assert
|
|
89
|
-
return value.length <= condition;
|
|
90
|
-
},
|
|
91
|
-
casing: (value: string | string[], condition: string): boolean => {
|
|
92
|
-
if (typeof value === 'undefined') return true; // property doesn't exist, no need to lint it with this assert
|
|
93
|
-
const values = typeof value === 'string' ? [value] : value;
|
|
94
|
-
for (let _val of values) {
|
|
95
|
-
let matchCase = false;
|
|
96
|
-
switch (condition) {
|
|
97
|
-
case 'camelCase':
|
|
98
|
-
matchCase = !!_val.match(/^[a-z][a-zA-Z0-9]+$/g);
|
|
99
|
-
break;
|
|
100
|
-
case 'kebab-case':
|
|
101
|
-
matchCase = !!_val.match(/^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/g);
|
|
102
|
-
break;
|
|
103
|
-
case 'snake_case':
|
|
104
|
-
matchCase = !!_val.match(/^([a-z][a-z0-9]*)(_[a-z0-9]+)*$/g);
|
|
105
|
-
break;
|
|
106
|
-
case 'PascalCase':
|
|
107
|
-
matchCase = !!_val.match(/^[A-Z][a-zA-Z0-9]+$/g);
|
|
108
|
-
break;
|
|
109
|
-
case 'MACRO_CASE':
|
|
110
|
-
matchCase = !!_val.match(/^([A-Z][A-Z0-9]*)(_[A-Z0-9]+)*$/g);
|
|
111
|
-
break;
|
|
112
|
-
case 'COBOL-CASE':
|
|
113
|
-
matchCase = !!_val.match(/^([A-Z][A-Z0-9]*)(-[A-Z0-9]+)*$/g);
|
|
114
|
-
break;
|
|
115
|
-
case 'flatcase':
|
|
116
|
-
matchCase = !!_val.match(/^[a-z][a-z0-9]+$/g);
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
if (!matchCase) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
},
|
|
125
|
-
sortOrder: (value: any[], condition: OrderOptions | OrderDirection): boolean => {
|
|
126
|
-
if (typeof value === 'undefined') return true;
|
|
127
|
-
return isOrdered(value, condition);
|
|
128
|
-
},
|
|
129
|
-
mutuallyExclusive: (value: string[], condition: string[]): boolean => {
|
|
130
|
-
return getIntersectionLength(value, condition) < 2;
|
|
131
|
-
},
|
|
132
|
-
mutuallyRequired: (value: string[], condition: string[]): boolean => {
|
|
133
|
-
return getIntersectionLength(value, condition) > 0
|
|
134
|
-
? getIntersectionLength(value, condition) === condition.length
|
|
135
|
-
: true;
|
|
136
|
-
},
|
|
137
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { asserts, runOnKeysSet, runOnValuesSet } from './asserts';
|
|
2
|
-
import { AssertToApply, buildSubjectVisitor, buildVisitorObject } from './utils';
|
|
3
|
-
import { Oas2Rule, Oas3Rule } from '../../../visitors';
|
|
4
|
-
|
|
5
|
-
export const Assertions: Oas3Rule | Oas2Rule = (opts: object) => {
|
|
6
|
-
let visitors: any[] = [];
|
|
7
|
-
|
|
8
|
-
// As 'Assertions' has an array of asserts,
|
|
9
|
-
// that array spreads into an 'opts' object on init rules phase here
|
|
10
|
-
// https://github.com/Redocly/redocly-cli/blob/master/packages/core/src/config/config.ts#L311
|
|
11
|
-
// that is why we need to iterate through 'opts' values;
|
|
12
|
-
// before - filter only object 'opts' values
|
|
13
|
-
const assertions: any[] = Object.values(opts).filter(
|
|
14
|
-
(opt: unknown) => typeof opt === 'object' && opt !== null,
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
for (const [index, assertion] of assertions.entries()) {
|
|
18
|
-
const assertId =
|
|
19
|
-
(assertion.assertionId && `${assertion.assertionId} assertion`) || `assertion #${index + 1}`;
|
|
20
|
-
|
|
21
|
-
if (!assertion.subject) {
|
|
22
|
-
throw new Error(`${assertId}: 'subject' is required`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const subjects: string[] = Array.isArray(assertion.subject)
|
|
26
|
-
? assertion.subject
|
|
27
|
-
: [assertion.subject];
|
|
28
|
-
|
|
29
|
-
const assertsToApply: AssertToApply[] = Object.keys(asserts)
|
|
30
|
-
.filter((assertName: string) => assertion[assertName] !== undefined)
|
|
31
|
-
.map((assertName: string) => {
|
|
32
|
-
return {
|
|
33
|
-
assertId,
|
|
34
|
-
name: assertName,
|
|
35
|
-
conditions: assertion[assertName],
|
|
36
|
-
message: assertion.message,
|
|
37
|
-
severity: assertion.severity || 'error',
|
|
38
|
-
suggest: assertion.suggest || [],
|
|
39
|
-
runsOnKeys: runOnKeysSet.has(assertName),
|
|
40
|
-
runsOnValues: runOnValuesSet.has(assertName),
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const shouldRunOnKeys: AssertToApply | undefined = assertsToApply.find(
|
|
45
|
-
(assert: AssertToApply) => assert.runsOnKeys && !assert.runsOnValues,
|
|
46
|
-
);
|
|
47
|
-
const shouldRunOnValues: AssertToApply | undefined = assertsToApply.find(
|
|
48
|
-
(assert: AssertToApply) => assert.runsOnValues && !assert.runsOnKeys,
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
if (shouldRunOnValues && !assertion.property) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`${shouldRunOnValues.name} can't be used on all keys. Please provide a single property.`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (shouldRunOnKeys && assertion.property) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`${shouldRunOnKeys.name} can't be used on a single property. Please use 'property'.`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
for (const subject of subjects) {
|
|
64
|
-
const subjectVisitor = buildSubjectVisitor(
|
|
65
|
-
assertion.property,
|
|
66
|
-
assertsToApply,
|
|
67
|
-
assertion.context,
|
|
68
|
-
);
|
|
69
|
-
const visitorObject = buildVisitorObject(subject, assertion.context, subjectVisitor);
|
|
70
|
-
visitors.push(visitorObject);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return visitors;
|
|
75
|
-
};
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { isRef } from '../../../ref-utils';
|
|
2
|
-
import { Problem, ProblemSeverity, UserContext } from '../../../walk';
|
|
3
|
-
import { asserts } from './asserts';
|
|
4
|
-
|
|
5
|
-
export type OrderDirection = 'asc' | 'desc';
|
|
6
|
-
|
|
7
|
-
export type OrderOptions = {
|
|
8
|
-
direction: OrderDirection;
|
|
9
|
-
property: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type AssertToApply = {
|
|
13
|
-
name: string;
|
|
14
|
-
assertId?: string;
|
|
15
|
-
conditions: any;
|
|
16
|
-
message?: string;
|
|
17
|
-
severity?: ProblemSeverity;
|
|
18
|
-
suggest?: string[];
|
|
19
|
-
runsOnKeys: boolean;
|
|
20
|
-
runsOnValues: boolean;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export function buildVisitorObject(
|
|
24
|
-
subject: string,
|
|
25
|
-
context: Record<string, any>[],
|
|
26
|
-
subjectVisitor: any,
|
|
27
|
-
) {
|
|
28
|
-
if (!context) {
|
|
29
|
-
return { [subject]: subjectVisitor };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let currentVisitorLevel: Record<string, any> = {};
|
|
33
|
-
const visitor: Record<string, any> = currentVisitorLevel;
|
|
34
|
-
|
|
35
|
-
for (let index = 0; index < context.length; index++) {
|
|
36
|
-
const node = context[index];
|
|
37
|
-
if (context.length === index + 1 && node.type === subject) {
|
|
38
|
-
// Visitors don't work properly for the same type nested nodes, so
|
|
39
|
-
// as a workaround for that we don't create separate visitor for the last element
|
|
40
|
-
// which is the same as subject;
|
|
41
|
-
// we will check includes/excludes it in the last visitor.
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const matchParentKeys = node.matchParentKeys;
|
|
45
|
-
const excludeParentKeys = node.excludeParentKeys;
|
|
46
|
-
|
|
47
|
-
if (matchParentKeys && excludeParentKeys) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
`Both 'matchParentKeys' and 'excludeParentKeys' can't be under one context item`,
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (matchParentKeys || excludeParentKeys) {
|
|
54
|
-
currentVisitorLevel[node.type] = {
|
|
55
|
-
skip: (_value: any, key: string) => {
|
|
56
|
-
if (matchParentKeys) {
|
|
57
|
-
return !matchParentKeys.includes(key);
|
|
58
|
-
}
|
|
59
|
-
if (excludeParentKeys) {
|
|
60
|
-
return excludeParentKeys.includes(key);
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
} else {
|
|
65
|
-
currentVisitorLevel[node.type] = {};
|
|
66
|
-
}
|
|
67
|
-
currentVisitorLevel = currentVisitorLevel[node.type];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
currentVisitorLevel[subject] = subjectVisitor;
|
|
71
|
-
|
|
72
|
-
return visitor;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function buildSubjectVisitor(
|
|
76
|
-
properties: string | string[],
|
|
77
|
-
asserts: AssertToApply[],
|
|
78
|
-
context?: Record<string, any>[],
|
|
79
|
-
) {
|
|
80
|
-
return function (node: any, { report, location, key, type, resolve }: UserContext) {
|
|
81
|
-
// We need to check context's last node if it has the same type as subject node;
|
|
82
|
-
// if yes - that means we didn't create context's last node visitor,
|
|
83
|
-
// so we need to handle 'matchParentKeys' and 'excludeParentKeys' conditions here;
|
|
84
|
-
if (context) {
|
|
85
|
-
const lastContextNode = context[context.length - 1];
|
|
86
|
-
if (lastContextNode.type === type.name) {
|
|
87
|
-
const matchParentKeys = lastContextNode.matchParentKeys;
|
|
88
|
-
const excludeParentKeys = lastContextNode.excludeParentKeys;
|
|
89
|
-
|
|
90
|
-
if (matchParentKeys && !matchParentKeys.includes(key)) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (excludeParentKeys && excludeParentKeys.includes(key)) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (properties) {
|
|
100
|
-
properties = Array.isArray(properties) ? properties : [properties];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
for (const assert of asserts) {
|
|
104
|
-
if (properties) {
|
|
105
|
-
for (const property of properties) {
|
|
106
|
-
// we can have resolvable scalar so need to resolve value here.
|
|
107
|
-
const value = isRef(node[property]) ? resolve(node[property])?.node : node[property];
|
|
108
|
-
runAssertion(value, assert, location.child(property), report);
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
runAssertion(Object.keys(node), assert, location.key(), report);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function getIntersectionLength(keys: string[], properties: string[]): number {
|
|
118
|
-
const props = new Set(properties);
|
|
119
|
-
let count = 0;
|
|
120
|
-
for (const key of keys) {
|
|
121
|
-
if (props.has(key)) {
|
|
122
|
-
count++;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return count;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function isOrdered(value: any[], options: OrderOptions | OrderDirection): boolean {
|
|
129
|
-
const direction = (options as OrderOptions).direction || (options as OrderDirection);
|
|
130
|
-
const property = (options as OrderOptions).property;
|
|
131
|
-
for (let i = 1; i < value.length; i++) {
|
|
132
|
-
let currValue = value[i];
|
|
133
|
-
let prevVal = value[i - 1];
|
|
134
|
-
|
|
135
|
-
if (property) {
|
|
136
|
-
if (!value[i][property] || !value[i - 1][property]) {
|
|
137
|
-
return false; // property doesn't exist, so collection is not ordered
|
|
138
|
-
}
|
|
139
|
-
currValue = value[i][property];
|
|
140
|
-
prevVal = value[i - 1][property];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const result = direction === 'asc' ? currValue >= prevVal : currValue <= prevVal;
|
|
144
|
-
if (!result) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function runAssertion(
|
|
152
|
-
values: string | string[],
|
|
153
|
-
assert: AssertToApply,
|
|
154
|
-
location: any,
|
|
155
|
-
report: (problem: Problem) => void,
|
|
156
|
-
) {
|
|
157
|
-
const lintResult = asserts[assert.name](values, assert.conditions);
|
|
158
|
-
if (!lintResult) {
|
|
159
|
-
report({
|
|
160
|
-
message: assert.message || `The ${assert.assertId} doesn't meet required conditions`,
|
|
161
|
-
location,
|
|
162
|
-
forceSeverity: assert.severity,
|
|
163
|
-
suggest: assert.suggest,
|
|
164
|
-
ruleId: assert.assertId,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { missingRequiredField } from '../utils';
|
|
3
|
-
|
|
4
|
-
export const InfoContact: Oas3Rule | Oas2Rule = () => {
|
|
5
|
-
return {
|
|
6
|
-
Info(info, { report, location }) {
|
|
7
|
-
if (!info.contact) {
|
|
8
|
-
report({
|
|
9
|
-
message: missingRequiredField('Info', 'contact'),
|
|
10
|
-
location: location.child('contact').key(),
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { validateDefinedAndNonEmpty } from '../utils';
|
|
3
|
-
|
|
4
|
-
export const InfoDescription: Oas3Rule | Oas2Rule = () => {
|
|
5
|
-
return {
|
|
6
|
-
Info(info, ctx) {
|
|
7
|
-
validateDefinedAndNonEmpty('description', info, ctx);
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { missingRequiredField } from '../utils';
|
|
3
|
-
|
|
4
|
-
export const InfoLicense: Oas3Rule | Oas2Rule = () => {
|
|
5
|
-
return {
|
|
6
|
-
Info(info, { report }) {
|
|
7
|
-
if (!info.license) {
|
|
8
|
-
report({
|
|
9
|
-
message: missingRequiredField('Info', 'license'),
|
|
10
|
-
location: { reportOnKey: true }
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { validateDefinedAndNonEmpty } from '../utils';
|
|
3
|
-
|
|
4
|
-
export const InfoLicenseUrl: Oas3Rule | Oas2Rule = () => {
|
|
5
|
-
return {
|
|
6
|
-
License(license, ctx) {
|
|
7
|
-
validateDefinedAndNonEmpty('url', license, ctx);
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { UserContext } from '../../walk';
|
|
3
|
-
import { Oas3Paths } from '../../typings/openapi';
|
|
4
|
-
import { Oas2Paths } from '../../typings/swagger';
|
|
5
|
-
|
|
6
|
-
export const NoAmbiguousPaths: Oas3Rule | Oas2Rule = () => {
|
|
7
|
-
return {
|
|
8
|
-
PathMap(pathMap: Oas3Paths | Oas2Paths, { report, location }: UserContext) {
|
|
9
|
-
const seenPaths: string[] = [];
|
|
10
|
-
|
|
11
|
-
for (const currentPath of Object.keys(pathMap)) {
|
|
12
|
-
const ambiguousPath = seenPaths.find((seenPath) =>
|
|
13
|
-
arePathsAmbiguous(seenPath, currentPath),
|
|
14
|
-
);
|
|
15
|
-
if (ambiguousPath) {
|
|
16
|
-
report({
|
|
17
|
-
message: `Paths should resolve unambiguously. Found two ambiguous paths: \`${ambiguousPath}\` and \`${currentPath}\`.`,
|
|
18
|
-
location: location.child([currentPath]).key(),
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
seenPaths.push(currentPath);
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
function arePathsAmbiguous(a: string, b: string) {
|
|
28
|
-
const partsA = a.split('/');
|
|
29
|
-
const partsB = b.split('/');
|
|
30
|
-
|
|
31
|
-
if (partsA.length !== partsB.length) return false;
|
|
32
|
-
|
|
33
|
-
let aVars = 0;
|
|
34
|
-
let bVars = 0;
|
|
35
|
-
let ambiguous = true;
|
|
36
|
-
for (let i = 0; i < partsA.length; i++) {
|
|
37
|
-
const aIsVar = partsA[i].match(/^{.+?}$/);
|
|
38
|
-
const bIsVar = partsB[i].match(/^{.+?}$/);
|
|
39
|
-
|
|
40
|
-
if (aIsVar || bIsVar) {
|
|
41
|
-
if (aIsVar) aVars++;
|
|
42
|
-
if (bIsVar) bVars++;
|
|
43
|
-
continue;
|
|
44
|
-
} else if (partsA[i] !== partsB[i]) {
|
|
45
|
-
ambiguous = false;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return ambiguous && aVars === bVars;
|
|
50
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { matchesJsonSchemaType, oasTypeOf } from '../utils';
|
|
3
|
-
import { Oas2Schema } from '../../typings/swagger';
|
|
4
|
-
import { Oas3Schema } from '../../typings/openapi';
|
|
5
|
-
import { UserContext } from '../../walk';
|
|
6
|
-
|
|
7
|
-
export const NoEnumTypeMismatch: Oas3Rule | Oas2Rule = () => {
|
|
8
|
-
return {
|
|
9
|
-
Schema(schema: Oas2Schema | Oas3Schema, { report, location }: UserContext) {
|
|
10
|
-
if (schema.enum && !Array.isArray(schema.enum)) return;
|
|
11
|
-
if (schema.enum && schema.type && !Array.isArray(schema.type)) {
|
|
12
|
-
const typeMismatchedValues = schema.enum.filter(
|
|
13
|
-
(item) => !matchesJsonSchemaType(item, schema.type as string, schema.nullable as boolean),
|
|
14
|
-
);
|
|
15
|
-
for (const mismatchedValue of typeMismatchedValues) {
|
|
16
|
-
report({
|
|
17
|
-
message: `All values of \`enum\` field must be of the same type as the \`type\` field: expected "${
|
|
18
|
-
schema.type
|
|
19
|
-
}" but received "${oasTypeOf(mismatchedValue)}".`,
|
|
20
|
-
location: location.child(['enum', schema.enum.indexOf(mismatchedValue)]),
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (schema.enum && schema.type && Array.isArray(schema.type)) {
|
|
26
|
-
const mismatchedResults: { [key: string]: string[]; } = {};
|
|
27
|
-
for (const enumValue of schema.enum) {
|
|
28
|
-
mismatchedResults[enumValue] = [];
|
|
29
|
-
|
|
30
|
-
for (const type of schema.type) {
|
|
31
|
-
const valid = matchesJsonSchemaType(enumValue, type as string, schema.nullable as boolean);
|
|
32
|
-
if (!valid)
|
|
33
|
-
mismatchedResults[enumValue].push(type);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if(mismatchedResults[enumValue].length !== schema.type.length)
|
|
37
|
-
delete mismatchedResults[enumValue];
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
for (const mismatchedKey of Object.keys(mismatchedResults)) {
|
|
41
|
-
report({
|
|
42
|
-
message: `Enum value \`${mismatchedKey}\` must be of one type. Allowed types: \`${schema.type}\`.`,
|
|
43
|
-
location: location.child(['enum', schema.enum.indexOf(mismatchedKey)]),
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { Oas2PathItem } from '../../typings/swagger';
|
|
3
|
-
import { Oas3PathItem } from '../../typings/openapi';
|
|
4
|
-
import { UserContext } from '../../walk';
|
|
5
|
-
import { isPathParameter, splitCamelCaseIntoWords } from '../../utils';
|
|
6
|
-
|
|
7
|
-
const httpMethods = ['get', 'head', 'post', 'put', 'patch', 'delete', 'options', 'trace'];
|
|
8
|
-
|
|
9
|
-
export const NoHttpVerbsInPaths: Oas3Rule | Oas2Rule = ({ splitIntoWords }) => {
|
|
10
|
-
return {
|
|
11
|
-
PathItem(_path: Oas2PathItem | Oas3PathItem, { key, report, location }: UserContext) {
|
|
12
|
-
const pathKey = key.toString();
|
|
13
|
-
if (!pathKey.startsWith('/')) return;
|
|
14
|
-
const pathSegments = pathKey.split('/');
|
|
15
|
-
|
|
16
|
-
for (const pathSegment of pathSegments) {
|
|
17
|
-
if (!pathSegment || isPathParameter(pathSegment)) continue;
|
|
18
|
-
|
|
19
|
-
const isHttpMethodIncluded = (method: string) => {
|
|
20
|
-
return splitIntoWords
|
|
21
|
-
? splitCamelCaseIntoWords(pathSegment).has(method)
|
|
22
|
-
: pathSegment.toLocaleLowerCase().includes(method);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
for (const method of httpMethods) {
|
|
26
|
-
if (isHttpMethodIncluded(method)) {
|
|
27
|
-
report({
|
|
28
|
-
message: `path \`${pathKey}\` should not contain http verb ${method}`,
|
|
29
|
-
location: location.key(),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { UserContext } from '../../walk';
|
|
3
|
-
import { Oas3Paths } from '../../typings/openapi';
|
|
4
|
-
import { Oas2Paths } from '../../typings/swagger';
|
|
5
|
-
|
|
6
|
-
export const NoIdenticalPaths: Oas3Rule | Oas2Rule = () => {
|
|
7
|
-
return {
|
|
8
|
-
PathMap(pathMap: Oas3Paths | Oas2Paths, { report, location }: UserContext) {
|
|
9
|
-
const pathsMap = new Map<string, string>();
|
|
10
|
-
for (const pathName of Object.keys(pathMap)) {
|
|
11
|
-
const id = pathName.replace(/{.+?}/g, '{VARIABLE}');
|
|
12
|
-
const existingSamePath = pathsMap.get(id);
|
|
13
|
-
if (existingSamePath) {
|
|
14
|
-
report({
|
|
15
|
-
message: `The path already exists which differs only by path parameter name(s): \`${existingSamePath}\` and \`${pathName}\`.`,
|
|
16
|
-
location: location.child([pathName]).key(),
|
|
17
|
-
});
|
|
18
|
-
} else {
|
|
19
|
-
pathsMap.set(id, pathName);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { UserContext } from '../../walk';
|
|
2
|
-
import { Oas3Parameter } from '../../typings/openapi';
|
|
3
|
-
import { validateExample } from '../utils';
|
|
4
|
-
|
|
5
|
-
export const NoInvalidParameterExamples: any = (opts: any) => {
|
|
6
|
-
const disallowAdditionalProperties = opts.disallowAdditionalProperties ?? true;
|
|
7
|
-
return {
|
|
8
|
-
Parameter: {
|
|
9
|
-
leave(parameter: Oas3Parameter, ctx: UserContext) {
|
|
10
|
-
if (parameter.example) {
|
|
11
|
-
validateExample(
|
|
12
|
-
parameter.example,
|
|
13
|
-
parameter.schema!,
|
|
14
|
-
ctx.location.child('example'),
|
|
15
|
-
ctx,
|
|
16
|
-
disallowAdditionalProperties,
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (parameter.examples) {
|
|
21
|
-
for (const [key, example] of Object.entries(parameter.examples)) {
|
|
22
|
-
if ('value' in example) {
|
|
23
|
-
validateExample(
|
|
24
|
-
example.value,
|
|
25
|
-
parameter.schema!,
|
|
26
|
-
ctx.location.child(['examples', key]),
|
|
27
|
-
ctx,
|
|
28
|
-
false,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { UserContext } from '../../walk';
|
|
2
|
-
import { Oas3_1Schema } from '../../typings/openapi';
|
|
3
|
-
import { validateExample } from '../utils';
|
|
4
|
-
|
|
5
|
-
export const NoInvalidSchemaExamples: any = (opts: any) => {
|
|
6
|
-
const disallowAdditionalProperties = opts.disallowAdditionalProperties ?? true;
|
|
7
|
-
return {
|
|
8
|
-
Schema: {
|
|
9
|
-
leave(schema: Oas3_1Schema, ctx: UserContext) {
|
|
10
|
-
if (schema.examples) {
|
|
11
|
-
for (const example of schema.examples) {
|
|
12
|
-
validateExample(
|
|
13
|
-
example,
|
|
14
|
-
schema,
|
|
15
|
-
ctx.location.child(['examples', schema.examples.indexOf(example)]),
|
|
16
|
-
ctx,
|
|
17
|
-
disallowAdditionalProperties,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (schema.example) {
|
|
22
|
-
validateExample(schema.example, schema, ctx.location.child('example'), ctx, false);
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { UserContext } from '../../walk';
|
|
3
|
-
|
|
4
|
-
export const NoPathTrailingSlash: Oas3Rule | Oas2Rule = () => {
|
|
5
|
-
return {
|
|
6
|
-
PathItem(_path: any, { report, key, location }: UserContext) {
|
|
7
|
-
if ((key as string).endsWith('/') && key !== '/') {
|
|
8
|
-
report({
|
|
9
|
-
message: `\`${key}\` should not have a trailing slash.`,
|
|
10
|
-
location: location.key(),
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
};
|