@redocly/openapi-core 1.0.0-beta.99 → 1.0.0-rc.2
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
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserContext } from './walk';
|
|
2
|
-
import
|
|
2
|
+
import { HttpResolveConfig } from './config';
|
|
3
3
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
4
4
|
export declare type StackFrame<T> = {
|
|
5
5
|
prev: StackFrame<T> | null;
|
|
@@ -13,8 +13,8 @@ export declare function pushStack<T, P extends Stack<T> = Stack<T>>(head: P, val
|
|
|
13
13
|
};
|
|
14
14
|
export declare function popStack<T, P extends Stack<T>>(head: P): StackFrame<T> | null;
|
|
15
15
|
export declare type BundleOutputFormat = 'json' | 'yml' | 'yaml';
|
|
16
|
-
export declare function loadYaml(filename: string): Promise<
|
|
17
|
-
export declare function
|
|
16
|
+
export declare function loadYaml<T>(filename: string): Promise<T>;
|
|
17
|
+
export declare function isDefined<T>(x: T | undefined): x is T;
|
|
18
18
|
export declare function isPlainObject(value: any): value is object;
|
|
19
19
|
export declare function isEmptyObject(value: any): value is object;
|
|
20
20
|
export declare function isEmptyArray(value: any): boolean;
|
|
@@ -29,6 +29,7 @@ export declare function validateMimeType({ type, value }: any, { report, locatio
|
|
|
29
29
|
export declare function validateMimeTypeOAS3({ type, value }: any, { report, location }: UserContext, allowedValues: string[]): void;
|
|
30
30
|
export declare function isSingular(path: string): boolean;
|
|
31
31
|
export declare function readFileAsStringSync(filePath: string): string;
|
|
32
|
+
export declare function yamlAndJsonSyncReader<T>(filePath: string): T;
|
|
32
33
|
export declare function isPathParameter(pathSegment: string): boolean;
|
|
33
34
|
/**
|
|
34
35
|
* Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
|
|
@@ -38,4 +39,14 @@ export declare function isNotEmptyObject(obj: any): boolean;
|
|
|
38
39
|
export declare function isString(value: unknown): value is string;
|
|
39
40
|
export declare function isNotString<T>(value: string | T): value is T;
|
|
40
41
|
export declare function assignExisting<T>(target: Record<string, T>, obj: Record<string, T>): void;
|
|
41
|
-
export declare
|
|
42
|
+
export declare function getMatchingStatusCodeRange(code: number | string): string;
|
|
43
|
+
export declare function isCustomRuleId(id: string): boolean;
|
|
44
|
+
export declare function doesYamlFileExist(filePath: string): boolean;
|
|
45
|
+
export declare function showWarningForDeprecatedField(deprecatedField: string, updatedField?: string, updatedObject?: string): void;
|
|
46
|
+
export declare function showErrorForDeprecatedField(deprecatedField: string, updatedField?: string, updatedObject?: string): void;
|
|
47
|
+
export declare type Falsy = undefined | null | false | '' | 0;
|
|
48
|
+
export declare function isTruthy<Truthy>(value: Truthy | Falsy): value is Truthy;
|
|
49
|
+
export declare function identity<T>(value: T): T;
|
|
50
|
+
export declare function keysOf<T>(obj: T): (keyof T)[];
|
|
51
|
+
export declare function pickDefined<T extends Record<string, unknown>>(obj?: T): Record<string, unknown> | undefined;
|
|
52
|
+
export declare function nextTick(): void;
|
package/lib/utils.js
CHANGED
|
@@ -9,13 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.
|
|
12
|
+
exports.nextTick = exports.pickDefined = exports.keysOf = exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.yamlAndJsonSyncReader = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
|
|
13
13
|
const fs = require("fs");
|
|
14
|
+
const path_1 = require("path");
|
|
14
15
|
const minimatch = require("minimatch");
|
|
15
16
|
const node_fetch_1 = require("node-fetch");
|
|
16
17
|
const pluralize = require("pluralize");
|
|
17
18
|
const js_yaml_1 = require("./js-yaml");
|
|
18
|
-
const
|
|
19
|
+
const env_1 = require("./env");
|
|
20
|
+
const logger_1 = require("./logger");
|
|
19
21
|
var js_yaml_2 = require("./js-yaml");
|
|
20
22
|
Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
|
|
21
23
|
Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
|
|
@@ -35,10 +37,10 @@ function loadYaml(filename) {
|
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
39
|
exports.loadYaml = loadYaml;
|
|
38
|
-
function
|
|
40
|
+
function isDefined(x) {
|
|
39
41
|
return x !== undefined;
|
|
40
42
|
}
|
|
41
|
-
exports.
|
|
43
|
+
exports.isDefined = isDefined;
|
|
42
44
|
function isPlainObject(value) {
|
|
43
45
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
44
46
|
}
|
|
@@ -57,7 +59,7 @@ function readFileFromUrl(url, config) {
|
|
|
57
59
|
for (const header of config.headers) {
|
|
58
60
|
if (match(url, header.matches)) {
|
|
59
61
|
headers[header.name] =
|
|
60
|
-
header.envVariable !== undefined ?
|
|
62
|
+
header.envVariable !== undefined ? env_1.env[header.envVariable] || '' : header.value;
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
const req = yield (config.customFetch || node_fetch_1.default)(url, {
|
|
@@ -88,7 +90,7 @@ exports.omitObjectProps = omitObjectProps;
|
|
|
88
90
|
function splitCamelCaseIntoWords(str) {
|
|
89
91
|
const camel = str
|
|
90
92
|
.split(/(?:[-._])|([A-Z][a-z]+)/)
|
|
91
|
-
.filter(
|
|
93
|
+
.filter(isTruthy)
|
|
92
94
|
.map((item) => item.toLocaleLowerCase());
|
|
93
95
|
const caps = str
|
|
94
96
|
.split(/([A-Z]{2,})/)
|
|
@@ -137,6 +139,11 @@ function readFileAsStringSync(filePath) {
|
|
|
137
139
|
return fs.readFileSync(filePath, 'utf-8');
|
|
138
140
|
}
|
|
139
141
|
exports.readFileAsStringSync = readFileAsStringSync;
|
|
142
|
+
function yamlAndJsonSyncReader(filePath) {
|
|
143
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
144
|
+
return js_yaml_1.parseYaml(content);
|
|
145
|
+
}
|
|
146
|
+
exports.yamlAndJsonSyncReader = yamlAndJsonSyncReader;
|
|
140
147
|
function isPathParameter(pathSegment) {
|
|
141
148
|
return pathSegment.startsWith('{') && pathSegment.endsWith('}');
|
|
142
149
|
}
|
|
@@ -166,12 +173,69 @@ function isNotString(value) {
|
|
|
166
173
|
}
|
|
167
174
|
exports.isNotString = isNotString;
|
|
168
175
|
function assignExisting(target, obj) {
|
|
169
|
-
for (
|
|
176
|
+
for (const k of Object.keys(obj)) {
|
|
170
177
|
if (target.hasOwnProperty(k)) {
|
|
171
178
|
target[k] = obj[k];
|
|
172
179
|
}
|
|
173
180
|
}
|
|
174
181
|
}
|
|
175
182
|
exports.assignExisting = assignExisting;
|
|
176
|
-
|
|
183
|
+
function getMatchingStatusCodeRange(code) {
|
|
184
|
+
return `${code}`.replace(/^(\d)\d\d$/, (_, firstDigit) => `${firstDigit}XX`);
|
|
185
|
+
}
|
|
177
186
|
exports.getMatchingStatusCodeRange = getMatchingStatusCodeRange;
|
|
187
|
+
function isCustomRuleId(id) {
|
|
188
|
+
return id.includes('/');
|
|
189
|
+
}
|
|
190
|
+
exports.isCustomRuleId = isCustomRuleId;
|
|
191
|
+
function doesYamlFileExist(filePath) {
|
|
192
|
+
return ((path_1.extname(filePath) === '.yaml' || path_1.extname(filePath) === '.yml') &&
|
|
193
|
+
fs.hasOwnProperty('existsSync') &&
|
|
194
|
+
fs.existsSync(filePath));
|
|
195
|
+
}
|
|
196
|
+
exports.doesYamlFileExist = doesYamlFileExist;
|
|
197
|
+
function showWarningForDeprecatedField(deprecatedField, updatedField, updatedObject) {
|
|
198
|
+
logger_1.logger.warn(`The '${logger_1.colorize.red(deprecatedField)}' field is deprecated. ${updatedField
|
|
199
|
+
? `Use ${logger_1.colorize.green(getUpdatedFieldName(updatedField, updatedObject))} instead. `
|
|
200
|
+
: ''}Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties\n`);
|
|
201
|
+
}
|
|
202
|
+
exports.showWarningForDeprecatedField = showWarningForDeprecatedField;
|
|
203
|
+
function showErrorForDeprecatedField(deprecatedField, updatedField, updatedObject) {
|
|
204
|
+
throw new Error(`Do not use '${deprecatedField}' field. ${updatedField ? `Use '${getUpdatedFieldName(updatedField, updatedObject)}' instead. ` : ''}\n`);
|
|
205
|
+
}
|
|
206
|
+
exports.showErrorForDeprecatedField = showErrorForDeprecatedField;
|
|
207
|
+
function isTruthy(value) {
|
|
208
|
+
return !!value;
|
|
209
|
+
}
|
|
210
|
+
exports.isTruthy = isTruthy;
|
|
211
|
+
function identity(value) {
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
exports.identity = identity;
|
|
215
|
+
function keysOf(obj) {
|
|
216
|
+
if (!obj)
|
|
217
|
+
return [];
|
|
218
|
+
return Object.keys(obj);
|
|
219
|
+
}
|
|
220
|
+
exports.keysOf = keysOf;
|
|
221
|
+
function pickDefined(obj) {
|
|
222
|
+
if (!obj)
|
|
223
|
+
return undefined;
|
|
224
|
+
const res = {};
|
|
225
|
+
for (const key in obj) {
|
|
226
|
+
if (obj[key] !== undefined) {
|
|
227
|
+
res[key] = obj[key];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return res;
|
|
231
|
+
}
|
|
232
|
+
exports.pickDefined = pickDefined;
|
|
233
|
+
function nextTick() {
|
|
234
|
+
new Promise((resolve) => {
|
|
235
|
+
setTimeout(resolve);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
exports.nextTick = nextTick;
|
|
239
|
+
function getUpdatedFieldName(updatedField, updatedObject) {
|
|
240
|
+
return `${typeof updatedObject !== 'undefined' ? `${updatedObject}.` : ''}${updatedField}`;
|
|
241
|
+
}
|
package/lib/visitors.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { Oas3Definition, Oas3ExternalDocs, Oas3Info, Oas3Contact, Oas3Components, Oas3License, Oas3Schema, Oas3Header, Oas3Parameter, Oas3Operation, Oas3PathItem, Oas3ServerVariable, Oas3Server, Oas3MediaType, Oas3Response, Oas3Example, Oas3RequestBody, Oas3Tag, OasRef, Oas3SecurityScheme, Oas3SecurityRequirement, Oas3Encoding, Oas3Link, Oas3Xml, Oas3Discriminator, Oas3Callback } from './typings/openapi';
|
|
2
|
-
import { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
|
|
2
|
+
import type { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
|
|
3
3
|
import { NormalizedNodeType } from './types';
|
|
4
|
-
import { Stack } from './utils';
|
|
5
|
-
import { UserContext, ResolveResult, ProblemSeverity } from './walk';
|
|
6
|
-
import { Location } from './ref-utils';
|
|
4
|
+
import type { Stack } from './utils';
|
|
5
|
+
import type { UserContext, ResolveResult, ProblemSeverity } from './walk';
|
|
6
|
+
import type { Location } from './ref-utils';
|
|
7
|
+
export declare type SkipFunctionContext = Pick<UserContext, 'location' | 'rawNode' | 'resolve' | 'rawLocation'>;
|
|
7
8
|
export declare type VisitFunction<T> = (node: T, ctx: UserContext & {
|
|
8
9
|
ignoreNextVisitorsOnNode: () => void;
|
|
9
10
|
}, parents?: any, context?: any) => void;
|
|
10
11
|
declare type VisitRefFunction = (node: OasRef, ctx: UserContext, resolved: ResolveResult<any>) => void;
|
|
11
|
-
declare type SkipFunction<T> = (node: T, key: string | number) => boolean;
|
|
12
|
+
declare type SkipFunction<T> = (node: T, key: string | number, ctx: SkipFunctionContext) => boolean;
|
|
12
13
|
declare type VisitObject<T> = {
|
|
13
14
|
enter?: VisitFunction<T>;
|
|
14
15
|
leave?: VisitFunction<T>;
|
|
@@ -16,7 +17,7 @@ declare type VisitObject<T> = {
|
|
|
16
17
|
};
|
|
17
18
|
declare type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
|
|
18
19
|
declare type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
|
|
19
|
-
declare type VisitorNode<T
|
|
20
|
+
declare type VisitorNode<T> = {
|
|
20
21
|
ruleId: string;
|
|
21
22
|
severity: ProblemSeverity;
|
|
22
23
|
context: VisitorLevelContext | VisitorSkippedLevelContext;
|
|
@@ -61,7 +62,7 @@ export declare type BaseVisitor = {
|
|
|
61
62
|
} | VisitRefFunction;
|
|
62
63
|
};
|
|
63
64
|
declare type Oas3FlatVisitor = {
|
|
64
|
-
|
|
65
|
+
Root?: VisitFunctionOrObject<Oas3Definition>;
|
|
65
66
|
Tag?: VisitFunctionOrObject<Oas3Tag>;
|
|
66
67
|
ExternalDocs?: VisitFunctionOrObject<Oas3ExternalDocs>;
|
|
67
68
|
Server?: VisitFunctionOrObject<Oas3Server>;
|
|
@@ -70,18 +71,19 @@ declare type Oas3FlatVisitor = {
|
|
|
70
71
|
Info?: VisitFunctionOrObject<Oas3Info>;
|
|
71
72
|
Contact?: VisitFunctionOrObject<Oas3Contact>;
|
|
72
73
|
License?: VisitFunctionOrObject<Oas3License>;
|
|
73
|
-
|
|
74
|
+
Paths?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
|
|
74
75
|
PathItem?: VisitFunctionOrObject<Oas3PathItem>;
|
|
75
|
-
Callback?: VisitFunctionOrObject<
|
|
76
|
+
Callback?: VisitFunctionOrObject<Oas3Callback>;
|
|
77
|
+
CallbacksMap?: VisitFunctionOrObject<Record<string, Oas3Callback>>;
|
|
76
78
|
Parameter?: VisitFunctionOrObject<Oas3Parameter>;
|
|
77
79
|
Operation?: VisitFunctionOrObject<Oas3Operation>;
|
|
78
80
|
RequestBody?: VisitFunctionOrObject<Oas3RequestBody>;
|
|
79
|
-
|
|
81
|
+
MediaTypesMap?: VisitFunctionOrObject<Record<string, Oas3MediaType>>;
|
|
80
82
|
MediaType?: VisitFunctionOrObject<Oas3MediaType>;
|
|
81
83
|
Example?: VisitFunctionOrObject<Oas3Example>;
|
|
82
84
|
Encoding?: VisitFunctionOrObject<Oas3Encoding>;
|
|
83
85
|
Header?: VisitFunctionOrObject<Oas3Header>;
|
|
84
|
-
|
|
86
|
+
Responses?: VisitFunctionOrObject<Record<string, Oas3Response>>;
|
|
85
87
|
Response?: VisitFunctionOrObject<Oas3Response>;
|
|
86
88
|
Link?: VisitFunctionOrObject<Oas3Link>;
|
|
87
89
|
Schema?: VisitFunctionOrObject<Oas3Schema>;
|
|
@@ -103,24 +105,25 @@ declare type Oas3FlatVisitor = {
|
|
|
103
105
|
PasswordFlow?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['password']>;
|
|
104
106
|
ClientCredentials?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['clientCredentials']>;
|
|
105
107
|
AuthorizationCode?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['authorizationCode']>;
|
|
106
|
-
|
|
108
|
+
OAuth2Flows?: VisitFunctionOrObject<Oas3SecurityScheme['flows']>;
|
|
107
109
|
SecurityScheme?: VisitFunctionOrObject<Oas3SecurityScheme>;
|
|
110
|
+
SpecExtension?: VisitFunctionOrObject<unknown>;
|
|
108
111
|
};
|
|
109
112
|
declare type Oas2FlatVisitor = {
|
|
110
|
-
|
|
113
|
+
Root?: VisitFunctionOrObject<Oas2Definition>;
|
|
111
114
|
Tag?: VisitFunctionOrObject<Oas2Tag>;
|
|
112
115
|
ExternalDocs?: VisitFunctionOrObject<Oas2ExternalDocs>;
|
|
113
116
|
SecurityRequirement?: VisitFunctionOrObject<Oas2SecurityRequirement>;
|
|
114
117
|
Info?: VisitFunctionOrObject<Oas2Info>;
|
|
115
118
|
Contact?: VisitFunctionOrObject<Oas2Contact>;
|
|
116
119
|
License?: VisitFunctionOrObject<Oas2License>;
|
|
117
|
-
|
|
120
|
+
Paths?: VisitFunctionOrObject<Record<string, Oas2PathItem>>;
|
|
118
121
|
PathItem?: VisitFunctionOrObject<Oas2PathItem>;
|
|
119
122
|
Parameter?: VisitFunctionOrObject<any>;
|
|
120
123
|
Operation?: VisitFunctionOrObject<Oas2Operation>;
|
|
121
124
|
Examples?: VisitFunctionOrObject<Record<string, any>>;
|
|
122
125
|
Header?: VisitFunctionOrObject<Oas2Header>;
|
|
123
|
-
|
|
126
|
+
Responses?: VisitFunctionOrObject<Record<string, Oas2Response>>;
|
|
124
127
|
Response?: VisitFunctionOrObject<Oas2Response>;
|
|
125
128
|
Schema?: VisitFunctionOrObject<Oas2Schema>;
|
|
126
129
|
Xml?: VisitFunctionOrObject<Oas2Xml>;
|
|
@@ -129,6 +132,7 @@ declare type Oas2FlatVisitor = {
|
|
|
129
132
|
NamedResponses?: VisitFunctionOrObject<Record<string, Oas2Response>>;
|
|
130
133
|
NamedParameters?: VisitFunctionOrObject<Record<string, Oas2Parameter>>;
|
|
131
134
|
SecurityScheme?: VisitFunctionOrObject<Oas2SecurityScheme>;
|
|
135
|
+
SpecExtension?: VisitFunctionOrObject<unknown>;
|
|
132
136
|
};
|
|
133
137
|
declare type Oas3NestedVisitor = {
|
|
134
138
|
[T in keyof Oas3FlatVisitor]: Oas3FlatVisitor[T] extends Function ? Oas3FlatVisitor[T] : Oas3FlatVisitor[T] & NestedVisitor<Oas3NestedVisitor>;
|
|
@@ -140,7 +144,7 @@ export declare type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<strin
|
|
|
140
144
|
export declare type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
|
|
141
145
|
export declare type Oas3TransformVisitor = BaseVisitor & Oas3FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
|
|
142
146
|
export declare type Oas2TransformVisitor = BaseVisitor & Oas2FlatVisitor & Record<string, VisitFunction<any> | VisitObject<any>>;
|
|
143
|
-
export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | '
|
|
147
|
+
export declare type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
|
|
144
148
|
export declare type NormalizedOasVisitors<T extends BaseVisitor> = {
|
|
145
149
|
[V in keyof T]-?: {
|
|
146
150
|
enter: Array<NormalizeVisitor<T[V]>>;
|
package/lib/visitors.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeVisitors = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const legacyTypesMap = {
|
|
6
|
+
Root: 'DefinitionRoot',
|
|
7
|
+
ServerVariablesMap: 'ServerVariableMap',
|
|
8
|
+
Paths: ['PathMap', 'PathsMap'],
|
|
9
|
+
CallbacksMap: 'CallbackMap',
|
|
10
|
+
MediaTypesMap: 'MediaTypeMap',
|
|
11
|
+
ExamplesMap: 'ExampleMap',
|
|
12
|
+
EncodingMap: 'EncodingsMap',
|
|
13
|
+
HeadersMap: 'HeaderMap',
|
|
14
|
+
LinksMap: 'LinkMap',
|
|
15
|
+
OAuth2Flows: 'SecuritySchemeFlows',
|
|
16
|
+
Responses: 'ResponsesMap',
|
|
17
|
+
};
|
|
4
18
|
function normalizeVisitors(visitorsConfig, types) {
|
|
5
19
|
const normalizedVisitors = {};
|
|
6
20
|
normalizedVisitors.any = {
|
|
@@ -30,7 +44,7 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
30
44
|
return;
|
|
31
45
|
stack = [...stack, from];
|
|
32
46
|
const possibleChildren = new Set();
|
|
33
|
-
for (
|
|
47
|
+
for (const type of Object.values(from.properties)) {
|
|
34
48
|
if (type === to) {
|
|
35
49
|
addWeakFromStack(ruleConf, stack);
|
|
36
50
|
continue;
|
|
@@ -55,7 +69,10 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
55
69
|
possibleChildren.add(from.items);
|
|
56
70
|
}
|
|
57
71
|
}
|
|
58
|
-
|
|
72
|
+
if (from.extensionsPrefix) {
|
|
73
|
+
possibleChildren.add(types_1.SpecExtension);
|
|
74
|
+
}
|
|
75
|
+
for (const fromType of Array.from(possibleChildren.values())) {
|
|
59
76
|
addWeakNodes(ruleConf, fromType, to, parentContext, stack);
|
|
60
77
|
}
|
|
61
78
|
function addWeakFromStack(ruleConf, stack) {
|
|
@@ -74,6 +91,13 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
74
91
|
}
|
|
75
92
|
}
|
|
76
93
|
}
|
|
94
|
+
function findLegacyVisitorNode(visitor, typeName) {
|
|
95
|
+
if (Array.isArray(typeName)) {
|
|
96
|
+
const name = typeName.find((name) => visitor[name]) || undefined;
|
|
97
|
+
return name && visitor[name];
|
|
98
|
+
}
|
|
99
|
+
return visitor[typeName];
|
|
100
|
+
}
|
|
77
101
|
function normalizeVisitorLevel(ruleConf, visitor, parentContext, depth = 0) {
|
|
78
102
|
const visitorKeys = Object.keys(types);
|
|
79
103
|
if (depth === 0) {
|
|
@@ -89,7 +113,8 @@ function normalizeVisitors(visitorsConfig, types) {
|
|
|
89
113
|
}
|
|
90
114
|
}
|
|
91
115
|
for (const typeName of visitorKeys) {
|
|
92
|
-
const typeVisitor = visitor[typeName]
|
|
116
|
+
const typeVisitor = (visitor[typeName] ||
|
|
117
|
+
findLegacyVisitorNode(visitor, legacyTypesMap[typeName]));
|
|
93
118
|
const normalizedTypeVisitor = normalizedVisitors[typeName];
|
|
94
119
|
if (!typeVisitor)
|
|
95
120
|
continue;
|
package/lib/walk.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Referenced } from './typings/openapi';
|
|
1
|
+
import type { Referenced } from './typings/openapi';
|
|
2
|
+
import type { NormalizedOasVisitors } from './visitors';
|
|
3
|
+
import type { ResolvedRefMap, Document } from './resolve';
|
|
4
|
+
import type { NormalizedNodeType } from './types';
|
|
5
|
+
import type { RuleSeverity } from './config';
|
|
2
6
|
import { Location } from './ref-utils';
|
|
3
|
-
import {
|
|
4
|
-
import { ResolvedRefMap, Document, ResolveError, YamlParseError, Source } from './resolve';
|
|
7
|
+
import { ResolveError, YamlParseError, Source } from './resolve';
|
|
5
8
|
import { OasVersion } from './oas-types';
|
|
6
|
-
import { NormalizedNodeType } from './types';
|
|
7
9
|
declare type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
|
|
8
10
|
export declare type ResolveResult<T extends NonUndefined> = {
|
|
9
11
|
node: T;
|
|
@@ -14,23 +16,13 @@ export declare type ResolveResult<T extends NonUndefined> = {
|
|
|
14
16
|
location: undefined;
|
|
15
17
|
error?: ResolveError | YamlParseError;
|
|
16
18
|
};
|
|
17
|
-
export declare type ResolveFn<T>
|
|
18
|
-
location: Location;
|
|
19
|
-
node: T;
|
|
20
|
-
} | {
|
|
21
|
-
location: undefined;
|
|
22
|
-
node: undefined;
|
|
23
|
-
};
|
|
19
|
+
export declare type ResolveFn = <T>(node: Referenced<T>, from?: string) => ResolveResult<T>;
|
|
24
20
|
export declare type UserContext = {
|
|
25
21
|
report(problem: Problem): void;
|
|
26
22
|
location: Location;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} | {
|
|
31
|
-
location: undefined;
|
|
32
|
-
node: undefined;
|
|
33
|
-
};
|
|
23
|
+
rawNode: any;
|
|
24
|
+
rawLocation: Location;
|
|
25
|
+
resolve: ResolveFn;
|
|
34
26
|
parentLocations: Record<string, Location>;
|
|
35
27
|
type: NormalizedNodeType;
|
|
36
28
|
key: string | number;
|
|
@@ -59,7 +51,7 @@ export declare type Problem = {
|
|
|
59
51
|
suggest?: string[];
|
|
60
52
|
location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
|
|
61
53
|
from?: LocationObject;
|
|
62
|
-
forceSeverity?:
|
|
54
|
+
forceSeverity?: RuleSeverity;
|
|
63
55
|
ruleId?: string;
|
|
64
56
|
};
|
|
65
57
|
export declare type NormalizedProblem = {
|
package/lib/walk.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.walkDocument = void 0;
|
|
4
4
|
const ref_utils_1 = require("./ref-utils");
|
|
5
|
-
const resolve_1 = require("./resolve");
|
|
6
5
|
const utils_1 = require("./utils");
|
|
6
|
+
const resolve_1 = require("./resolve");
|
|
7
7
|
const types_1 = require("./types");
|
|
8
8
|
function collectParents(ctx) {
|
|
9
9
|
var _a;
|
|
@@ -28,33 +28,53 @@ function collectParentsLocations(ctx) {
|
|
|
28
28
|
function walkDocument(opts) {
|
|
29
29
|
const { document, rootType, normalizedVisitors, resolvedRefMap, ctx } = opts;
|
|
30
30
|
const seenNodesPerType = {};
|
|
31
|
-
const
|
|
31
|
+
const ignoredNodes = new Set();
|
|
32
32
|
walkNode(document.parsed, rootType, new ref_utils_1.Location(document.source, '#/'), undefined, '');
|
|
33
33
|
function walkNode(node, type, location, parent, key) {
|
|
34
34
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
35
|
+
const resolve = (ref, from = currentLocation.source.absoluteRef) => {
|
|
36
|
+
if (!ref_utils_1.isRef(ref))
|
|
37
|
+
return { location, node: ref };
|
|
38
|
+
const refId = resolve_1.makeRefId(from, ref.$ref);
|
|
39
|
+
const resolvedRef = resolvedRefMap.get(refId);
|
|
40
|
+
if (!resolvedRef) {
|
|
41
|
+
return {
|
|
42
|
+
location: undefined,
|
|
43
|
+
node: undefined,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const { resolved, node, document, nodePointer, error } = resolvedRef;
|
|
47
|
+
const newLocation = resolved
|
|
48
|
+
? new ref_utils_1.Location(document.source, nodePointer)
|
|
49
|
+
: error instanceof resolve_1.YamlParseError
|
|
50
|
+
? new ref_utils_1.Location(error.source, '')
|
|
51
|
+
: undefined;
|
|
52
|
+
return { location: newLocation, node, error };
|
|
53
|
+
};
|
|
54
|
+
const rawLocation = location;
|
|
35
55
|
let currentLocation = location;
|
|
36
56
|
const { node: resolvedNode, location: resolvedLocation, error } = resolve(node);
|
|
37
57
|
const enteredContexts = new Set();
|
|
38
58
|
if (ref_utils_1.isRef(node)) {
|
|
39
59
|
const refEnterVisitors = normalizedVisitors.ref.enter;
|
|
40
60
|
for (const { visit: visitor, ruleId, severity, context } of refEnterVisitors) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
enteredContexts.add(context);
|
|
62
|
+
const report = reportFn.bind(undefined, ruleId, severity);
|
|
63
|
+
visitor(node, {
|
|
64
|
+
report,
|
|
65
|
+
resolve,
|
|
66
|
+
rawNode: node,
|
|
67
|
+
rawLocation,
|
|
68
|
+
location,
|
|
69
|
+
type,
|
|
70
|
+
parent,
|
|
71
|
+
key,
|
|
72
|
+
parentLocations: {},
|
|
73
|
+
oasVersion: ctx.oasVersion,
|
|
74
|
+
getVisitorData: getVisitorDataFn.bind(undefined, ruleId),
|
|
75
|
+
}, { node: resolvedNode, location: resolvedLocation, error });
|
|
76
|
+
if ((resolvedLocation === null || resolvedLocation === void 0 ? void 0 : resolvedLocation.source.absoluteRef) && ctx.refTypes) {
|
|
77
|
+
ctx.refTypes.set(resolvedLocation === null || resolvedLocation === void 0 ? void 0 : resolvedLocation.source.absoluteRef, type);
|
|
58
78
|
}
|
|
59
79
|
}
|
|
60
80
|
}
|
|
@@ -66,6 +86,8 @@ function walkDocument(opts) {
|
|
|
66
86
|
const currentEnterVisitors = anyEnterVisitors.concat(((_c = normalizedVisitors[type.name]) === null || _c === void 0 ? void 0 : _c.enter) || []);
|
|
67
87
|
const activatedContexts = [];
|
|
68
88
|
for (const { context, visit, skip, ruleId, severity } of currentEnterVisitors) {
|
|
89
|
+
if (ignoredNodes.has(currentLocation.pointer))
|
|
90
|
+
break;
|
|
69
91
|
if (context.isSkippedLevel) {
|
|
70
92
|
if (context.parent.activatedOn &&
|
|
71
93
|
!context.parent.activatedOn.value.nextLevelTypeActivated &&
|
|
@@ -90,7 +112,13 @@ function walkDocument(opts) {
|
|
|
90
112
|
location: resolvedLocation,
|
|
91
113
|
nextLevelTypeActivated: null,
|
|
92
114
|
withParentNode: (_g = (_f = context.parent) === null || _f === void 0 ? void 0 : _f.activatedOn) === null || _g === void 0 ? void 0 : _g.value.node,
|
|
93
|
-
skipped: (_k = (((_j = (_h = context.parent) === null || _h === void 0 ? void 0 : _h.activatedOn) === null || _j === void 0 ? void 0 : _j.value.skipped) ||
|
|
115
|
+
skipped: (_k = (((_j = (_h = context.parent) === null || _h === void 0 ? void 0 : _h.activatedOn) === null || _j === void 0 ? void 0 : _j.value.skipped) ||
|
|
116
|
+
(skip === null || skip === void 0 ? void 0 : skip(resolvedNode, key, {
|
|
117
|
+
location,
|
|
118
|
+
rawLocation,
|
|
119
|
+
resolve,
|
|
120
|
+
rawNode: node,
|
|
121
|
+
})))) !== null && _k !== void 0 ? _k : false,
|
|
94
122
|
};
|
|
95
123
|
context.activatedOn = utils_1.pushStack(context.activatedOn, activatedOn);
|
|
96
124
|
let ctx = context.parent;
|
|
@@ -101,9 +129,7 @@ function walkDocument(opts) {
|
|
|
101
129
|
if (!activatedOn.skipped) {
|
|
102
130
|
visitedBySome = true;
|
|
103
131
|
enteredContexts.add(context);
|
|
104
|
-
|
|
105
|
-
if (ignoreNextVisitorsOnNode)
|
|
106
|
-
break;
|
|
132
|
+
visitWithContext(visit, resolvedNode, node, context, ruleId, severity);
|
|
107
133
|
}
|
|
108
134
|
}
|
|
109
135
|
}
|
|
@@ -125,6 +151,9 @@ function walkDocument(opts) {
|
|
|
125
151
|
if (type.additionalProperties) {
|
|
126
152
|
props.push(...Object.keys(resolvedNode).filter((k) => !props.includes(k)));
|
|
127
153
|
}
|
|
154
|
+
else if (type.extensionsPrefix) {
|
|
155
|
+
props.push(...Object.keys(resolvedNode).filter((k) => k.startsWith(type.extensionsPrefix)));
|
|
156
|
+
}
|
|
128
157
|
if (ref_utils_1.isRef(node)) {
|
|
129
158
|
props.push(...Object.keys(node).filter((k) => k !== '$ref' && !props.includes(k))); // properties on the same level as $ref
|
|
130
159
|
}
|
|
@@ -140,6 +169,11 @@ function walkDocument(opts) {
|
|
|
140
169
|
propType = type.additionalProperties;
|
|
141
170
|
if (typeof propType === 'function')
|
|
142
171
|
propType = propType(value, propName);
|
|
172
|
+
if (propType === undefined &&
|
|
173
|
+
type.extensionsPrefix &&
|
|
174
|
+
propName.startsWith(type.extensionsPrefix)) {
|
|
175
|
+
propType = types_1.SpecExtension;
|
|
176
|
+
}
|
|
143
177
|
if (!types_1.isNamedType(propType) && (propType === null || propType === void 0 ? void 0 : propType.directResolveAs)) {
|
|
144
178
|
propType = propType.directResolveAs;
|
|
145
179
|
value = { $ref: value };
|
|
@@ -173,7 +207,7 @@ function walkDocument(opts) {
|
|
|
173
207
|
}
|
|
174
208
|
for (const { context, visit, ruleId, severity } of currentLeaveVisitors) {
|
|
175
209
|
if (!context.isSkippedLevel && enteredContexts.has(context)) {
|
|
176
|
-
visitWithContext(visit, resolvedNode, context, ruleId, severity);
|
|
210
|
+
visitWithContext(visit, resolvedNode, node, context, ruleId, severity);
|
|
177
211
|
}
|
|
178
212
|
}
|
|
179
213
|
}
|
|
@@ -186,63 +220,50 @@ function walkDocument(opts) {
|
|
|
186
220
|
visitor(node, {
|
|
187
221
|
report,
|
|
188
222
|
resolve,
|
|
223
|
+
rawNode: node,
|
|
224
|
+
rawLocation,
|
|
189
225
|
location,
|
|
190
226
|
type,
|
|
191
227
|
parent,
|
|
192
228
|
key,
|
|
193
229
|
parentLocations: {},
|
|
194
230
|
oasVersion: ctx.oasVersion,
|
|
195
|
-
getVisitorData: getVisitorDataFn.bind(undefined, ruleId)
|
|
231
|
+
getVisitorData: getVisitorDataFn.bind(undefined, ruleId),
|
|
196
232
|
}, { node: resolvedNode, location: resolvedLocation, error });
|
|
197
233
|
}
|
|
198
234
|
}
|
|
199
235
|
}
|
|
200
236
|
// returns true ignores all the next visitors on the specific node
|
|
201
|
-
function visitWithContext(visit, node, context, ruleId, severity) {
|
|
237
|
+
function visitWithContext(visit, resolvedNode, node, context, ruleId, severity) {
|
|
202
238
|
const report = reportFn.bind(undefined, ruleId, severity);
|
|
203
|
-
|
|
204
|
-
visit(node, {
|
|
239
|
+
visit(resolvedNode, {
|
|
205
240
|
report,
|
|
206
241
|
resolve,
|
|
242
|
+
rawNode: node,
|
|
207
243
|
location: currentLocation,
|
|
244
|
+
rawLocation,
|
|
208
245
|
type,
|
|
209
246
|
parent,
|
|
210
247
|
key,
|
|
211
248
|
parentLocations: collectParentsLocations(context),
|
|
212
249
|
oasVersion: ctx.oasVersion,
|
|
213
|
-
ignoreNextVisitorsOnNode: () => {
|
|
250
|
+
ignoreNextVisitorsOnNode: () => {
|
|
251
|
+
ignoredNodes.add(currentLocation.pointer);
|
|
252
|
+
},
|
|
214
253
|
getVisitorData: getVisitorDataFn.bind(undefined, ruleId),
|
|
215
254
|
}, collectParents(context), context);
|
|
216
|
-
return { ignoreNextVisitorsOnNode };
|
|
217
|
-
}
|
|
218
|
-
function resolve(ref, from = currentLocation.source.absoluteRef) {
|
|
219
|
-
if (!ref_utils_1.isRef(ref))
|
|
220
|
-
return { location, node: ref };
|
|
221
|
-
const refId = resolve_1.makeRefId(from, ref.$ref);
|
|
222
|
-
const resolvedRef = resolvedRefMap.get(refId);
|
|
223
|
-
if (!resolvedRef) {
|
|
224
|
-
return {
|
|
225
|
-
location: undefined,
|
|
226
|
-
node: undefined,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
const { resolved, node, document, nodePointer, error } = resolvedRef;
|
|
230
|
-
const newLocation = resolved
|
|
231
|
-
? new ref_utils_1.Location(document.source, nodePointer)
|
|
232
|
-
: error instanceof resolve_1.YamlParseError
|
|
233
|
-
? new ref_utils_1.Location(error.source, '')
|
|
234
|
-
: undefined;
|
|
235
|
-
return { location: newLocation, node, error };
|
|
236
255
|
}
|
|
237
256
|
function reportFn(ruleId, severity, opts) {
|
|
238
|
-
const
|
|
257
|
+
const normalizedLocation = opts.location
|
|
239
258
|
? Array.isArray(opts.location)
|
|
240
259
|
? opts.location
|
|
241
260
|
: [opts.location]
|
|
242
261
|
: [Object.assign(Object.assign({}, currentLocation), { reportOnKey: false })];
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
262
|
+
const location = normalizedLocation.map((l) => (Object.assign(Object.assign(Object.assign({}, currentLocation), { reportOnKey: false }), l)));
|
|
263
|
+
const ruleSeverity = opts.forceSeverity || severity;
|
|
264
|
+
if (ruleSeverity !== 'off') {
|
|
265
|
+
ctx.problems.push(Object.assign(Object.assign({ ruleId: opts.ruleId || ruleId, severity: ruleSeverity }, opts), { suggest: opts.suggest || [], location }));
|
|
266
|
+
}
|
|
246
267
|
}
|
|
247
268
|
function getVisitorDataFn(ruleId) {
|
|
248
269
|
ctx.visitorsData[ruleId] = ctx.visitorsData[ruleId] || {};
|