@redocly/openapi-core 1.0.0-beta.98 → 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 +12 -15
- package/lib/bundle.js +38 -15
- package/lib/config/all.d.ts +2 -2
- package/lib/config/all.js +17 -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 +8 -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.d.ts +2 -0
- package/lib/rules/common/response-contains-header.js +29 -0
- package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
- package/lib/rules/common/scalar-property-missing-example.js +42 -0
- 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 +6 -2
- package/lib/rules/oas2/index.js +16 -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-contains-property.d.ts +2 -0
- package/lib/rules/oas2/response-contains-property.js +38 -0
- 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 +24 -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-contains-property.d.ts +2 -0
- package/lib/rules/oas3/response-contains-property.js +40 -0
- 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 +139 -49
- package/lib/types/oas3_1.js +32 -26
- package/lib/types/redocly-yaml.js +414 -58
- package/lib/typings/openapi.d.ts +3 -2
- package/lib/utils.d.ts +15 -3
- package/lib/utils.js +73 -7
- 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__/__snapshots__/bundle.test.ts.snap +0 -229
- package/__tests__/bundle.test.ts +0 -132
- package/__tests__/codeframes.test.ts +0 -531
- package/__tests__/fixtures/extension.js +0 -24
- package/__tests__/fixtures/refs/definitions.yaml +0 -3
- package/__tests__/fixtures/refs/examples.yaml +0 -8
- package/__tests__/fixtures/refs/external-request-body.yaml +0 -13
- package/__tests__/fixtures/refs/externalref.yaml +0 -35
- package/__tests__/fixtures/refs/hosted.yaml +0 -35
- package/__tests__/fixtures/refs/openapi-with-external-refs-conflicting-names.yaml +0 -21
- package/__tests__/fixtures/refs/openapi-with-external-refs.yaml +0 -33
- package/__tests__/fixtures/refs/param-b.yaml +0 -1
- package/__tests__/fixtures/refs/param-c.yaml +0 -1
- package/__tests__/fixtures/refs/rename.yaml +0 -1
- package/__tests__/fixtures/refs/requestBody.yaml +0 -9
- package/__tests__/fixtures/refs/schema-a.yaml +0 -1
- package/__tests__/fixtures/refs/simple.yaml +0 -1
- package/__tests__/fixtures/refs/vendor.schema.yaml +0 -20
- package/__tests__/fixtures/resolve/External.yaml +0 -10
- package/__tests__/fixtures/resolve/External2.yaml +0 -4
- package/__tests__/fixtures/resolve/description.md +0 -3
- package/__tests__/fixtures/resolve/externalInfo.yaml +0 -4
- package/__tests__/fixtures/resolve/externalLicense.yaml +0 -1
- package/__tests__/fixtures/resolve/openapi-with-back.yaml +0 -13
- package/__tests__/fixtures/resolve/openapi-with-md-description.yaml +0 -5
- package/__tests__/fixtures/resolve/openapi.yaml +0 -28
- package/__tests__/fixtures/resolve/schemas/type-a.yaml +0 -10
- package/__tests__/fixtures/resolve/schemas/type-b.yaml +0 -6
- package/__tests__/fixtures/resolve/transitive/a.yaml +0 -1
- package/__tests__/fixtures/resolve/transitive/components.yaml +0 -5
- package/__tests__/fixtures/resolve/transitive/schemas.yaml +0 -3
- package/__tests__/lint.test.ts +0 -17
- package/__tests__/login.test.ts +0 -17
- package/__tests__/normalizeVisitors.test.ts +0 -151
- package/__tests__/ref-utils.test.ts +0 -120
- package/__tests__/resolve-http.test.ts +0 -77
- package/__tests__/resolve.test.ts +0 -405
- package/__tests__/utils.ts +0 -86
- package/__tests__/walk.test.ts +0 -1485
- 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__/js-yaml.test.ts +0 -71
- package/src/__tests__/lint.test.ts +0 -182
- package/src/__tests__/utils.test.ts +0 -74
- 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 -371
- 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 -65
- 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 -79
- 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__/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/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__/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 -83
- 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-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__/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 -99
- 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-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 -506
- package/src/types/oas3_1.ts +0 -251
- package/src/types/redocly-yaml.ts +0 -637
- package/src/typings/common.ts +0 -9
- package/src/typings/openapi.ts +0 -297
- package/src/typings/swagger.ts +0 -236
- package/src/utils.ts +0 -190
- package/src/visitors.ts +0 -448
- package/src/walk.ts +0 -416
- package/tsconfig.json +0 -8
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -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
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { UserContext } from '../../walk';
|
|
3
|
-
|
|
4
|
-
export const Operation2xxResponse: Oas3Rule | Oas2Rule = () => {
|
|
5
|
-
return {
|
|
6
|
-
ResponsesMap(responses: Record<string, object>, { report }: UserContext) {
|
|
7
|
-
const codes = Object.keys(responses);
|
|
8
|
-
if (!codes.some((code) => code === 'default' || /2[Xx0-9]{2}/.test(code))) {
|
|
9
|
-
report({
|
|
10
|
-
message: 'Operation must have at least one `2xx` response.',
|
|
11
|
-
location: { reportOnKey: true },
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { UserContext } from '../../walk';
|
|
3
|
-
|
|
4
|
-
export const Operation4xxResponse: Oas3Rule | Oas2Rule = () => {
|
|
5
|
-
return {
|
|
6
|
-
ResponsesMap(responses: Record<string, object>, { report }: UserContext) {
|
|
7
|
-
const codes = Object.keys(responses);
|
|
8
|
-
|
|
9
|
-
if (!codes.some((code) => /4[Xx0-9]{2}/.test(code))) {
|
|
10
|
-
report({
|
|
11
|
-
message: 'Operation must have at least one `4xx` response.',
|
|
12
|
-
location: { reportOnKey: true },
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { validateDefinedAndNonEmpty } from '../utils';
|
|
3
|
-
import { UserContext } from '../../walk';
|
|
4
|
-
import { Oas2Operation } from '../../typings/swagger';
|
|
5
|
-
import { Oas3Operation } from '../../typings/openapi';
|
|
6
|
-
|
|
7
|
-
export const OperationDescription: Oas3Rule | Oas2Rule = () => {
|
|
8
|
-
return {
|
|
9
|
-
Operation(operation: Oas2Operation | Oas3Operation, ctx: UserContext) {
|
|
10
|
-
validateDefinedAndNonEmpty('description', operation, ctx);
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { Oas2Operation } from '../../typings/swagger';
|
|
3
|
-
import { Oas3Operation } from '../../typings/openapi';
|
|
4
|
-
import { UserContext } from '../../walk';
|
|
5
|
-
|
|
6
|
-
export const OperationIdUnique: Oas3Rule | Oas2Rule = () => {
|
|
7
|
-
const seenOperations = new Set();
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
Operation(operation: Oas2Operation | Oas3Operation, { report, location }: UserContext) {
|
|
11
|
-
if (!operation.operationId) return;
|
|
12
|
-
if (seenOperations.has(operation.operationId)) {
|
|
13
|
-
report({
|
|
14
|
-
message: 'Every operation must have a unique `operationId`.',
|
|
15
|
-
location: location.child([operation.operationId]),
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
seenOperations.add(operation.operationId);
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { Oas2Operation } from '../../typings/swagger';
|
|
3
|
-
import { Oas3Operation } from '../../typings/openapi';
|
|
4
|
-
import { UserContext } from '../../walk';
|
|
5
|
-
|
|
6
|
-
const validUrlSymbols = /^[A-Za-z0-9-._~:/?#\[\]@!\$&'()*+,;=]*$/;
|
|
7
|
-
|
|
8
|
-
export const OperationIdUrlSafe: Oas3Rule | Oas2Rule = () => {
|
|
9
|
-
return {
|
|
10
|
-
Operation(operation: Oas2Operation | Oas3Operation, { report, location }: UserContext) {
|
|
11
|
-
if (operation.operationId && !validUrlSymbols.test(operation.operationId)) {
|
|
12
|
-
report({
|
|
13
|
-
message: 'Operation `operationId` should not have URL invalid characters.',
|
|
14
|
-
location: location.child(['operationId']),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { validateDefinedAndNonEmpty } from '../utils';
|
|
3
|
-
import { UserContext } from '../../walk';
|
|
4
|
-
import { Oas2Operation } from '../../typings/swagger';
|
|
5
|
-
import { Oas3Operation } from '../../typings/openapi';
|
|
6
|
-
|
|
7
|
-
export const OperationOperationId: Oas3Rule | Oas2Rule = () => {
|
|
8
|
-
return {
|
|
9
|
-
DefinitionRoot: {
|
|
10
|
-
PathItem: {
|
|
11
|
-
Operation(operation: Oas2Operation | Oas3Operation, ctx: UserContext) {
|
|
12
|
-
validateDefinedAndNonEmpty('operationId', operation, ctx);
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { Oas2Parameter } from '../../typings/swagger';
|
|
3
|
-
import { Oas3Parameter } from '../../typings/openapi';
|
|
4
|
-
import { UserContext } from '../../walk';
|
|
5
|
-
|
|
6
|
-
export const OperationParametersUnique: Oas3Rule | Oas2Rule = () => {
|
|
7
|
-
let seenPathParams: Set<string>;
|
|
8
|
-
let seenOperationParams: Set<string>;
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
PathItem: {
|
|
12
|
-
enter() {
|
|
13
|
-
seenPathParams = new Set();
|
|
14
|
-
},
|
|
15
|
-
Parameter(
|
|
16
|
-
parameter: Oas2Parameter | Oas3Parameter,
|
|
17
|
-
{ report, key, parentLocations }: UserContext,
|
|
18
|
-
) {
|
|
19
|
-
const paramId = `${parameter.in}___${parameter.name}`;
|
|
20
|
-
if (seenPathParams.has(paramId)) {
|
|
21
|
-
report({
|
|
22
|
-
message: `Paths must have unique \`name\` + \`in\` parameters.\nRepeats of \`in:${parameter.in}\` + \`name:${parameter.name}\`.`,
|
|
23
|
-
location: parentLocations.PathItem.child(['parameters', key]),
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
seenPathParams.add(`${parameter.in}___${parameter.name}`);
|
|
27
|
-
},
|
|
28
|
-
Operation: {
|
|
29
|
-
enter() {
|
|
30
|
-
seenOperationParams = new Set();
|
|
31
|
-
},
|
|
32
|
-
Parameter(
|
|
33
|
-
parameter: Oas2Parameter | Oas3Parameter,
|
|
34
|
-
{ report, key, parentLocations }: UserContext,
|
|
35
|
-
) {
|
|
36
|
-
const paramId = `${parameter.in}___${parameter.name}`;
|
|
37
|
-
if (seenOperationParams.has(paramId)) {
|
|
38
|
-
report({
|
|
39
|
-
message: `Operations must have unique \`name\` + \`in\` parameters. Repeats of \`in:${parameter.in}\` + \`name:${parameter.name}\`.`,
|
|
40
|
-
location: parentLocations.Operation.child(['parameters', key]),
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
seenOperationParams.add(paramId);
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Oas3Rule, Oas2Rule } from '../../visitors';
|
|
2
|
-
import { Location } from '../../ref-utils';
|
|
3
|
-
import { UserContext } from '../../walk';
|
|
4
|
-
import { Oas2SecurityScheme } from '../../typings/swagger';
|
|
5
|
-
import { Oas3SecurityScheme } from '../../typings/openapi';
|
|
6
|
-
|
|
7
|
-
export const OperationSecurityDefined: Oas3Rule | Oas2Rule = () => {
|
|
8
|
-
let referencedSchemes = new Map<
|
|
9
|
-
string,
|
|
10
|
-
{
|
|
11
|
-
defined?: boolean;
|
|
12
|
-
from: Location[];
|
|
13
|
-
}
|
|
14
|
-
>();
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
DefinitionRoot: {
|
|
18
|
-
leave(_: object, { report }: UserContext) {
|
|
19
|
-
for (const [name, scheme] of referencedSchemes.entries()) {
|
|
20
|
-
if (scheme.defined) continue;
|
|
21
|
-
for (const reportedFromLocation of scheme.from) {
|
|
22
|
-
report({
|
|
23
|
-
message: `There is no \`${name}\` security scheme defined.`,
|
|
24
|
-
location: reportedFromLocation.key(),
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
SecurityScheme(_securityScheme: Oas2SecurityScheme | Oas3SecurityScheme, { key }: UserContext) {
|
|
31
|
-
referencedSchemes.set(key.toString(), { defined: true, from: [] });
|
|
32
|
-
},
|
|
33
|
-
SecurityRequirement(requirements, { location }) {
|
|
34
|
-
for (const requirement of Object.keys(requirements)) {
|
|
35
|
-
const authScheme = referencedSchemes.get(requirement);
|
|
36
|
-
const requirementLocation = location.child([requirement]);
|
|
37
|
-
if (!authScheme) {
|
|
38
|
-
referencedSchemes.set(requirement, { from: [requirementLocation] });
|
|
39
|
-
} else {
|
|
40
|
-
authScheme.from.push(requirementLocation);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
};
|