@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/format/format.js
CHANGED
|
@@ -2,20 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatProblems = exports.getTotals = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const
|
|
5
|
+
const logger_1 = require("../logger");
|
|
6
|
+
const output_1 = require("../output");
|
|
6
7
|
const coreVersion = require('../../package.json').version;
|
|
7
8
|
const codeframes_1 = require("./codeframes");
|
|
8
|
-
const
|
|
9
|
+
const env_1 = require("../env");
|
|
10
|
+
const ref_utils_1 = require("../ref-utils");
|
|
9
11
|
const ERROR_MESSAGE = {
|
|
10
12
|
INVALID_SEVERITY_LEVEL: 'Invalid severity level; accepted values: error or warn',
|
|
11
13
|
};
|
|
12
14
|
const BG_COLORS = {
|
|
13
|
-
warn: (str) =>
|
|
14
|
-
error:
|
|
15
|
+
warn: (str) => logger_1.colorize.bgYellow(logger_1.colorize.black(str)),
|
|
16
|
+
error: logger_1.colorize.bgRed,
|
|
15
17
|
};
|
|
16
18
|
const COLORS = {
|
|
17
|
-
warn:
|
|
18
|
-
error:
|
|
19
|
+
warn: logger_1.colorize.yellow,
|
|
20
|
+
error: logger_1.colorize.red,
|
|
19
21
|
};
|
|
20
22
|
const SEVERITY_NAMES = {
|
|
21
23
|
warn: 'Warning',
|
|
@@ -51,8 +53,8 @@ function getTotals(problems) {
|
|
|
51
53
|
}
|
|
52
54
|
exports.getTotals = getTotals;
|
|
53
55
|
function formatProblems(problems, opts) {
|
|
54
|
-
const { maxProblems = 100, cwd = process.cwd(), format = 'codeframe', color =
|
|
55
|
-
|
|
56
|
+
const { maxProblems = 100, cwd = process.cwd(), format = 'codeframe', color = logger_1.colorOptions.enabled, totals = getTotals(problems), version = coreVersion, } = opts;
|
|
57
|
+
logger_1.colorOptions.enabled = color; // force colors if specified
|
|
56
58
|
const totalProblems = problems.length;
|
|
57
59
|
problems = problems.filter((m) => !m.ignored);
|
|
58
60
|
const ignoredProblems = totalProblems - problems.length;
|
|
@@ -68,39 +70,42 @@ function formatProblems(problems, opts) {
|
|
|
68
70
|
case 'codeframe':
|
|
69
71
|
for (let i = 0; i < problems.length; i++) {
|
|
70
72
|
const problem = problems[i];
|
|
71
|
-
|
|
73
|
+
logger_1.logger.info(`${formatCodeframe(problem, i)}\n`);
|
|
72
74
|
}
|
|
73
75
|
break;
|
|
74
76
|
case 'stylish': {
|
|
75
77
|
const groupedByFile = groupByFiles(problems);
|
|
76
78
|
for (const [file, { ruleIdPad, locationPad: positionPad, fileProblems }] of Object.entries(groupedByFile)) {
|
|
77
|
-
|
|
79
|
+
logger_1.logger.info(`${logger_1.colorize.blue(ref_utils_1.isAbsoluteUrl(file) ? file : path.relative(cwd, file))}:\n`);
|
|
78
80
|
for (let i = 0; i < fileProblems.length; i++) {
|
|
79
81
|
const problem = fileProblems[i];
|
|
80
|
-
|
|
82
|
+
logger_1.logger.info(`${formatStylish(problem, positionPad, ruleIdPad)}\n`);
|
|
81
83
|
}
|
|
82
|
-
|
|
84
|
+
logger_1.logger.info('\n');
|
|
83
85
|
}
|
|
84
86
|
break;
|
|
85
87
|
}
|
|
86
88
|
case 'checkstyle': {
|
|
87
89
|
const groupedByFile = groupByFiles(problems);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
output_1.output.write('<?xml version="1.0" encoding="UTF-8"?>\n');
|
|
91
|
+
output_1.output.write('<checkstyle version="4.3">\n');
|
|
90
92
|
for (const [file, { fileProblems }] of Object.entries(groupedByFile)) {
|
|
91
|
-
|
|
93
|
+
output_1.output.write(`<file name="${xmlEscape(ref_utils_1.isAbsoluteUrl(file) ? file : path.relative(cwd, file))}">\n`);
|
|
92
94
|
fileProblems.forEach(formatCheckstyle);
|
|
93
|
-
|
|
95
|
+
output_1.output.write(`</file>\n`);
|
|
94
96
|
}
|
|
95
|
-
|
|
97
|
+
output_1.output.write(`</checkstyle>\n`);
|
|
96
98
|
break;
|
|
97
99
|
}
|
|
98
100
|
case 'codeclimate':
|
|
99
101
|
outputForCodeClimate();
|
|
100
102
|
break;
|
|
103
|
+
case 'summary':
|
|
104
|
+
formatSummary(problems);
|
|
105
|
+
break;
|
|
101
106
|
}
|
|
102
107
|
if (totalProblems - ignoredProblems > maxProblems) {
|
|
103
|
-
|
|
108
|
+
logger_1.logger.info(`< ... ${totalProblems - maxProblems} more problems hidden > ${logger_1.colorize.gray('increase with `--max-problems N`')}\n`);
|
|
104
109
|
}
|
|
105
110
|
function outputForCodeClimate() {
|
|
106
111
|
const issues = problems.map((p) => {
|
|
@@ -109,7 +114,9 @@ function formatProblems(problems, opts) {
|
|
|
109
114
|
return {
|
|
110
115
|
description: p.message,
|
|
111
116
|
location: {
|
|
112
|
-
path:
|
|
117
|
+
path: ref_utils_1.isAbsoluteUrl(location.source.absoluteRef)
|
|
118
|
+
? location.source.absoluteRef
|
|
119
|
+
: path.relative(cwd, location.source.absoluteRef),
|
|
113
120
|
lines: {
|
|
114
121
|
begin: lineCol.start.line,
|
|
115
122
|
},
|
|
@@ -118,21 +125,25 @@ function formatProblems(problems, opts) {
|
|
|
118
125
|
fingerprint: `${p.ruleId}${p.location.length > 0 ? '-' + p.location[0].pointer : ''}`,
|
|
119
126
|
};
|
|
120
127
|
});
|
|
121
|
-
|
|
128
|
+
output_1.output.write(JSON.stringify(issues, null, 2));
|
|
122
129
|
}
|
|
123
130
|
function outputJSON() {
|
|
124
131
|
const resultObject = {
|
|
125
132
|
totals,
|
|
126
133
|
version,
|
|
127
134
|
problems: problems.map((p) => {
|
|
128
|
-
var _a;
|
|
129
|
-
|
|
130
|
-
ref:
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
const problem = Object.assign(Object.assign({}, p), { location: p.location.map((location) => (Object.assign(Object.assign({}, location), { source: {
|
|
137
|
+
ref: ref_utils_1.isAbsoluteUrl(location.source.absoluteRef)
|
|
138
|
+
? location.source.absoluteRef
|
|
139
|
+
: path.relative(cwd, location.source.absoluteRef),
|
|
131
140
|
} }))), from: p.from
|
|
132
141
|
? Object.assign(Object.assign({}, p.from), { source: {
|
|
133
|
-
ref:
|
|
142
|
+
ref: ref_utils_1.isAbsoluteUrl((_a = p.from) === null || _a === void 0 ? void 0 : _a.source.absoluteRef)
|
|
143
|
+
? (_b = p.from) === null || _b === void 0 ? void 0 : _b.source.absoluteRef
|
|
144
|
+
: path.relative(cwd, ((_c = p.from) === null || _c === void 0 ? void 0 : _c.source.absoluteRef) || cwd),
|
|
134
145
|
} }) : undefined });
|
|
135
|
-
if (
|
|
146
|
+
if (env_1.env.FORMAT_JSON_WITH_CODEFRAMES) {
|
|
136
147
|
const location = p.location[0]; // TODO: support multiple locations
|
|
137
148
|
const loc = codeframes_1.getLineColLocation(location);
|
|
138
149
|
problem.codeframe = codeframes_1.getCodeframe(loc, color);
|
|
@@ -140,7 +151,7 @@ function formatProblems(problems, opts) {
|
|
|
140
151
|
return problem;
|
|
141
152
|
}),
|
|
142
153
|
};
|
|
143
|
-
|
|
154
|
+
output_1.output.write(JSON.stringify(resultObject, null, 2));
|
|
144
155
|
}
|
|
145
156
|
function getBgColor(problem) {
|
|
146
157
|
const { severity } = problem;
|
|
@@ -152,9 +163,11 @@ function formatProblems(problems, opts) {
|
|
|
152
163
|
function formatCodeframe(problem, idx) {
|
|
153
164
|
const bgColor = getBgColor(problem);
|
|
154
165
|
const location = problem.location[0]; // TODO: support multiple locations
|
|
155
|
-
const relativePath =
|
|
166
|
+
const relativePath = ref_utils_1.isAbsoluteUrl(location.source.absoluteRef)
|
|
167
|
+
? location.source.absoluteRef
|
|
168
|
+
: path.relative(cwd, location.source.absoluteRef);
|
|
156
169
|
const loc = codeframes_1.getLineColLocation(location);
|
|
157
|
-
const atPointer = location.pointer ?
|
|
170
|
+
const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
|
|
158
171
|
const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
|
|
159
172
|
return (`[${idx + 1}] ${bgColor(fileWithLoc)} ${atPointer}\n\n` +
|
|
160
173
|
`${problem.message}\n\n` +
|
|
@@ -162,12 +175,12 @@ function formatProblems(problems, opts) {
|
|
|
162
175
|
codeframes_1.getCodeframe(loc, color) +
|
|
163
176
|
'\n\n' +
|
|
164
177
|
formatFrom(cwd, problem.from) +
|
|
165
|
-
`${SEVERITY_NAMES[problem.severity]} was generated by the ${
|
|
178
|
+
`${SEVERITY_NAMES[problem.severity]} was generated by the ${logger_1.colorize.blue(problem.ruleId)} rule.\n\n`);
|
|
166
179
|
}
|
|
167
180
|
function formatStylish(problem, locationPad, ruleIdPad) {
|
|
168
181
|
const color = COLORS[problem.severity];
|
|
169
182
|
if (!SEVERITY_NAMES[problem.severity]) {
|
|
170
|
-
return 'Error not found severity. Please check your config file. Allowed values:
|
|
183
|
+
return 'Error not found severity. Please check your config file. Allowed values: `warn,error,off`';
|
|
171
184
|
}
|
|
172
185
|
const severityName = color(SEVERITY_NAMES[problem.severity].toLowerCase().padEnd(7));
|
|
173
186
|
const { start } = problem.location[0];
|
|
@@ -178,17 +191,35 @@ function formatProblems(problems, opts) {
|
|
|
178
191
|
const severity = problem.severity == 'warn' ? 'warning' : 'error';
|
|
179
192
|
const message = xmlEscape(problem.message);
|
|
180
193
|
const source = xmlEscape(problem.ruleId);
|
|
181
|
-
|
|
194
|
+
output_1.output.write(`<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`);
|
|
182
195
|
}
|
|
183
196
|
}
|
|
184
197
|
exports.formatProblems = formatProblems;
|
|
198
|
+
function formatSummary(problems) {
|
|
199
|
+
const counts = {};
|
|
200
|
+
for (const problem of problems) {
|
|
201
|
+
counts[problem.ruleId] = counts[problem.ruleId] || { count: 0, severity: problem.severity };
|
|
202
|
+
counts[problem.ruleId].count++;
|
|
203
|
+
}
|
|
204
|
+
const sorted = Object.entries(counts).sort(([, a], [, b]) => {
|
|
205
|
+
const severityDiff = severityToNumber(a.severity) - severityToNumber(b.severity);
|
|
206
|
+
return severityDiff || b.count - a.count;
|
|
207
|
+
});
|
|
208
|
+
for (const [ruleId, info] of sorted) {
|
|
209
|
+
const color = COLORS[info.severity];
|
|
210
|
+
const severityName = color(SEVERITY_NAMES[info.severity].toLowerCase().padEnd(7));
|
|
211
|
+
logger_1.logger.info(`${severityName} ${ruleId}: ${info.count}\n`);
|
|
212
|
+
}
|
|
213
|
+
logger_1.logger.info('\n');
|
|
214
|
+
}
|
|
185
215
|
function formatFrom(cwd, location) {
|
|
186
216
|
if (!location)
|
|
187
217
|
return '';
|
|
188
218
|
const relativePath = path.relative(cwd, location.source.absoluteRef);
|
|
189
219
|
const loc = codeframes_1.getLineColLocation(location);
|
|
190
220
|
const fileWithLoc = `${relativePath}:${loc.start.line}:${loc.start.col}`;
|
|
191
|
-
|
|
221
|
+
const atPointer = location.pointer ? logger_1.colorize.gray(`at ${location.pointer}`) : '';
|
|
222
|
+
return `referenced from ${logger_1.colorize.blue(fileWithLoc)} ${atPointer} \n\n`;
|
|
192
223
|
}
|
|
193
224
|
function formatDidYouMean(problem) {
|
|
194
225
|
if (problem.suggest.length === 0)
|
|
@@ -217,6 +248,7 @@ const groupByFiles = (problems) => {
|
|
|
217
248
|
return fileGroups;
|
|
218
249
|
};
|
|
219
250
|
function xmlEscape(s) {
|
|
251
|
+
// eslint-disable-next-line no-control-regex
|
|
220
252
|
return s.replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, (char) => {
|
|
221
253
|
switch (char) {
|
|
222
254
|
case '<':
|
package/lib/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export { BundleOutputFormat, readFileFromUrl, slash } from './utils';
|
|
1
|
+
export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist, isTruthy } from './utils';
|
|
2
2
|
export { Oas3_1Types } from './types/oas3_1';
|
|
3
3
|
export { Oas3Types } from './types/oas3';
|
|
4
4
|
export { Oas2Types } from './types/oas2';
|
|
5
5
|
export { ConfigTypes } from './types/redocly-yaml';
|
|
6
|
-
export { Oas3Definition, Oas3_1Definition, Oas3Components, Oas3PathItem, Oas3Paths, Oas3ComponentName, Oas3Schema, Oas3_1Schema, Oas3Tag, Oas3_1Webhooks, Referenced, } from './typings/openapi';
|
|
7
|
-
export { Oas2Definition } from './typings/swagger';
|
|
8
|
-
export { StatsAccumulator, StatsName } from './typings/common';
|
|
6
|
+
export type { Oas3Definition, Oas3_1Definition, Oas3Components, Oas3PathItem, Oas3Paths, Oas3ComponentName, Oas3Schema, Oas3_1Schema, Oas3Tag, Oas3_1Webhooks, Referenced, OasRef, } from './typings/openapi';
|
|
7
|
+
export type { Oas2Definition } from './typings/swagger';
|
|
8
|
+
export type { StatsAccumulator, StatsName } from './typings/common';
|
|
9
9
|
export { normalizeTypes } from './types';
|
|
10
10
|
export { Stats } from './rules/other/stats';
|
|
11
|
-
export { Config,
|
|
11
|
+
export { Config, StyleguideConfig, RawConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity, createConfig, ResolvedApi, } from './config';
|
|
12
12
|
export { RedoclyClient, isRedoclyRegistryURL } from './redocly';
|
|
13
13
|
export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
|
|
14
14
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
15
|
-
export { unescapePointer, isRef } from './ref-utils';
|
|
15
|
+
export { unescapePointer, isRef, isAbsoluteUrl } from './ref-utils';
|
|
16
16
|
export { detectOpenAPI, OasMajorVersion, openAPIMajor, OasVersion } from './oas-types';
|
|
17
17
|
export { normalizeVisitors } from './visitors';
|
|
18
18
|
export { WalkContext, walkDocument, NormalizedProblem, ProblemSeverity, LineColLocationObject, LocationObject, Loc, } from './walk';
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.OasVersion = exports.openAPIMajor = exports.OasMajorVersion = exports.detectOpenAPI = exports.isAbsoluteUrl = exports.isRef = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.isRedoclyRegistryURL = exports.RedoclyClient = exports.createConfig = exports.CONFIG_FILE_NAMES = exports.findConfig = exports.getConfig = exports.loadConfig = exports.transformConfig = exports.getMergedConfig = exports.IGNORE_FILE = exports.StyleguideConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.isTruthy = exports.doesYamlFileExist = exports.slash = exports.readFileFromUrl = void 0;
|
|
4
|
+
exports.mapTypeToComponent = void 0;
|
|
4
5
|
var utils_1 = require("./utils");
|
|
5
6
|
Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
|
|
6
7
|
Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
|
|
8
|
+
Object.defineProperty(exports, "doesYamlFileExist", { enumerable: true, get: function () { return utils_1.doesYamlFileExist; } });
|
|
9
|
+
Object.defineProperty(exports, "isTruthy", { enumerable: true, get: function () { return utils_1.isTruthy; } });
|
|
7
10
|
var oas3_1_1 = require("./types/oas3_1");
|
|
8
11
|
Object.defineProperty(exports, "Oas3_1Types", { enumerable: true, get: function () { return oas3_1_1.Oas3_1Types; } });
|
|
9
12
|
var oas3_1 = require("./types/oas3");
|
|
@@ -18,7 +21,7 @@ var stats_1 = require("./rules/other/stats");
|
|
|
18
21
|
Object.defineProperty(exports, "Stats", { enumerable: true, get: function () { return stats_1.Stats; } });
|
|
19
22
|
var config_1 = require("./config");
|
|
20
23
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
21
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "StyleguideConfig", { enumerable: true, get: function () { return config_1.StyleguideConfig; } });
|
|
22
25
|
Object.defineProperty(exports, "IGNORE_FILE", { enumerable: true, get: function () { return config_1.IGNORE_FILE; } });
|
|
23
26
|
Object.defineProperty(exports, "getMergedConfig", { enumerable: true, get: function () { return config_1.getMergedConfig; } });
|
|
24
27
|
Object.defineProperty(exports, "transformConfig", { enumerable: true, get: function () { return config_1.transformConfig; } });
|
|
@@ -26,6 +29,7 @@ Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function (
|
|
|
26
29
|
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
|
|
27
30
|
Object.defineProperty(exports, "findConfig", { enumerable: true, get: function () { return config_1.findConfig; } });
|
|
28
31
|
Object.defineProperty(exports, "CONFIG_FILE_NAMES", { enumerable: true, get: function () { return config_1.CONFIG_FILE_NAMES; } });
|
|
32
|
+
Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_1.createConfig; } });
|
|
29
33
|
var redocly_1 = require("./redocly");
|
|
30
34
|
Object.defineProperty(exports, "RedoclyClient", { enumerable: true, get: function () { return redocly_1.RedoclyClient; } });
|
|
31
35
|
Object.defineProperty(exports, "isRedoclyRegistryURL", { enumerable: true, get: function () { return redocly_1.isRedoclyRegistryURL; } });
|
|
@@ -42,6 +46,7 @@ Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: functio
|
|
|
42
46
|
var ref_utils_1 = require("./ref-utils");
|
|
43
47
|
Object.defineProperty(exports, "unescapePointer", { enumerable: true, get: function () { return ref_utils_1.unescapePointer; } });
|
|
44
48
|
Object.defineProperty(exports, "isRef", { enumerable: true, get: function () { return ref_utils_1.isRef; } });
|
|
49
|
+
Object.defineProperty(exports, "isAbsoluteUrl", { enumerable: true, get: function () { return ref_utils_1.isAbsoluteUrl; } });
|
|
45
50
|
var oas_types_1 = require("./oas-types");
|
|
46
51
|
Object.defineProperty(exports, "detectOpenAPI", { enumerable: true, get: function () { return oas_types_1.detectOpenAPI; } });
|
|
47
52
|
Object.defineProperty(exports, "OasMajorVersion", { enumerable: true, get: function () { return oas_types_1.OasMajorVersion; } });
|
package/lib/js-yaml/index.js
CHANGED
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringifyYaml = exports.parseYaml = void 0;
|
|
4
4
|
// TODO: add a type for "types" https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/js-yaml/index.d.ts
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
6
|
// @ts-ignore
|
|
6
7
|
const js_yaml_1 = require("js-yaml");
|
|
7
8
|
const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = js_yaml_1.JSON_SCHEMA.extend({
|
|
8
9
|
implicit: [js_yaml_1.types.merge],
|
|
9
|
-
explicit: [
|
|
10
|
-
js_yaml_1.types.binary,
|
|
11
|
-
js_yaml_1.types.omap,
|
|
12
|
-
js_yaml_1.types.pairs,
|
|
13
|
-
js_yaml_1.types.set,
|
|
14
|
-
],
|
|
10
|
+
explicit: [js_yaml_1.types.binary, js_yaml_1.types.omap, js_yaml_1.types.pairs, js_yaml_1.types.set],
|
|
15
11
|
});
|
|
16
12
|
const parseYaml = (str, opts) => js_yaml_1.load(str, Object.assign({ schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP }, opts));
|
|
17
13
|
exports.parseYaml = parseYaml;
|
package/lib/lint.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseResolver, Document } from './resolve';
|
|
2
2
|
import { NodeType } from './types';
|
|
3
|
-
import {
|
|
3
|
+
import { ProblemSeverity } from './walk';
|
|
4
|
+
import { StyleguideConfig, Config } from './config';
|
|
4
5
|
export declare function lint(opts: {
|
|
5
6
|
ref: string;
|
|
6
7
|
config: Config;
|
|
@@ -14,10 +15,11 @@ export declare function lintFromString(opts: {
|
|
|
14
15
|
}): Promise<import("./walk").NormalizedProblem[]>;
|
|
15
16
|
export declare function lintDocument(opts: {
|
|
16
17
|
document: Document;
|
|
17
|
-
config:
|
|
18
|
+
config: StyleguideConfig;
|
|
18
19
|
customTypes?: Record<string, NodeType>;
|
|
19
20
|
externalRefResolver: BaseResolver;
|
|
20
21
|
}): Promise<import("./walk").NormalizedProblem[]>;
|
|
21
22
|
export declare function lintConfig(opts: {
|
|
22
23
|
document: Document;
|
|
24
|
+
severity?: ProblemSeverity;
|
|
23
25
|
}): Promise<import("./walk").NormalizedProblem[]>;
|
package/lib/lint.js
CHANGED
|
@@ -26,7 +26,7 @@ function lint(opts) {
|
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
const { ref, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
|
|
28
28
|
const document = (yield externalRefResolver.resolveDocument(null, ref, true));
|
|
29
|
-
return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.
|
|
29
|
+
return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
exports.lint = lint;
|
|
@@ -34,7 +34,7 @@ function lintFromString(opts) {
|
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
const { source, absoluteRef, externalRefResolver = new resolve_1.BaseResolver(opts.config.resolve) } = opts;
|
|
36
36
|
const document = resolve_1.makeDocumentFromString(source, absoluteRef || '/');
|
|
37
|
-
return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.
|
|
37
|
+
return lintDocument(Object.assign(Object.assign({ document }, opts), { externalRefResolver, config: opts.config.styleguide }));
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
exports.lintFromString = lintFromString;
|
|
@@ -45,7 +45,11 @@ function lintDocument(opts) {
|
|
|
45
45
|
const oasVersion = oas_types_1.detectOpenAPI(document.parsed);
|
|
46
46
|
const oasMajorVersion = oas_types_1.openAPIMajor(oasVersion);
|
|
47
47
|
const rules = config.getRulesForOasVersion(oasMajorVersion);
|
|
48
|
-
const types = types_1.normalizeTypes(config.extendTypes((customTypes !== null && customTypes !== void 0 ? customTypes : oasMajorVersion === oas_types_1.OasMajorVersion.Version3)
|
|
48
|
+
const types = types_1.normalizeTypes(config.extendTypes((customTypes !== null && customTypes !== void 0 ? customTypes : oasMajorVersion === oas_types_1.OasMajorVersion.Version3)
|
|
49
|
+
? oasVersion === oas_types_1.OasVersion.Version3_1
|
|
50
|
+
? oas3_1_1.Oas3_1Types
|
|
51
|
+
: oas3_1.Oas3Types
|
|
52
|
+
: oas2_1.Oas2Types, oasVersion), config);
|
|
49
53
|
const ctx = {
|
|
50
54
|
problems: [],
|
|
51
55
|
oasVersion: oasVersion,
|
|
@@ -53,15 +57,30 @@ function lintDocument(opts) {
|
|
|
53
57
|
};
|
|
54
58
|
const preprocessors = config_1.initRules(rules, config, 'preprocessors', oasVersion);
|
|
55
59
|
const regularRules = config_1.initRules(rules, config, 'rules', oasVersion);
|
|
56
|
-
|
|
57
|
-
const resolvedRefMap = yield resolve_1.resolveDocument({
|
|
60
|
+
let resolvedRefMap = yield resolve_1.resolveDocument({
|
|
58
61
|
rootDocument: document,
|
|
59
|
-
rootType: types.
|
|
60
|
-
externalRefResolver
|
|
62
|
+
rootType: types.Root,
|
|
63
|
+
externalRefResolver,
|
|
61
64
|
});
|
|
65
|
+
if (preprocessors.length > 0) {
|
|
66
|
+
// Make additional pass to resolve refs defined in preprocessors.
|
|
67
|
+
walk_1.walkDocument({
|
|
68
|
+
document,
|
|
69
|
+
rootType: types.Root,
|
|
70
|
+
normalizedVisitors: visitors_1.normalizeVisitors(preprocessors, types),
|
|
71
|
+
resolvedRefMap,
|
|
72
|
+
ctx,
|
|
73
|
+
});
|
|
74
|
+
resolvedRefMap = yield resolve_1.resolveDocument({
|
|
75
|
+
rootDocument: document,
|
|
76
|
+
rootType: types.Root,
|
|
77
|
+
externalRefResolver,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const normalizedVisitors = visitors_1.normalizeVisitors(regularRules, types);
|
|
62
81
|
walk_1.walkDocument({
|
|
63
82
|
document,
|
|
64
|
-
rootType: types.
|
|
83
|
+
rootType: types.Root,
|
|
65
84
|
normalizedVisitors,
|
|
66
85
|
resolvedRefMap,
|
|
67
86
|
ctx,
|
|
@@ -72,19 +91,25 @@ function lintDocument(opts) {
|
|
|
72
91
|
exports.lintDocument = lintDocument;
|
|
73
92
|
function lintConfig(opts) {
|
|
74
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
const { document } = opts;
|
|
94
|
+
const { document, severity } = opts;
|
|
76
95
|
const ctx = {
|
|
77
96
|
problems: [],
|
|
78
97
|
oasVersion: oas_types_1.OasVersion.Version3_0,
|
|
79
98
|
visitorsData: {},
|
|
80
99
|
};
|
|
81
100
|
const plugins = config_1.resolvePlugins([config_1.defaultPlugin]);
|
|
82
|
-
const config = new config_1.
|
|
101
|
+
const config = new config_1.StyleguideConfig({
|
|
83
102
|
plugins,
|
|
84
103
|
rules: { spec: 'error' },
|
|
85
104
|
});
|
|
86
105
|
const types = types_1.normalizeTypes(redocly_yaml_1.ConfigTypes, config);
|
|
87
|
-
const rules = [
|
|
106
|
+
const rules = [
|
|
107
|
+
{
|
|
108
|
+
severity: severity || 'error',
|
|
109
|
+
ruleId: 'configuration spec',
|
|
110
|
+
visitor: spec_1.OasSpec({ severity: 'error' }),
|
|
111
|
+
},
|
|
112
|
+
];
|
|
88
113
|
const normalizedVisitors = visitors_1.normalizeVisitors(rules, types);
|
|
89
114
|
walk_1.walkDocument({
|
|
90
115
|
document,
|
package/lib/logger.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as colorette from 'colorette';
|
|
2
|
+
export { options as colorOptions } from 'colorette';
|
|
3
|
+
export declare const colorize: typeof colorette;
|
|
4
|
+
declare class Logger {
|
|
5
|
+
protected stderr(str: string): boolean;
|
|
6
|
+
info(str: string): boolean | void;
|
|
7
|
+
warn(str: string): boolean | void;
|
|
8
|
+
error(str: string): boolean | void;
|
|
9
|
+
}
|
|
10
|
+
export declare const logger: Logger;
|
package/lib/logger.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = exports.colorize = exports.colorOptions = void 0;
|
|
4
|
+
const colorette = require("colorette");
|
|
5
|
+
var colorette_1 = require("colorette");
|
|
6
|
+
Object.defineProperty(exports, "colorOptions", { enumerable: true, get: function () { return colorette_1.options; } });
|
|
7
|
+
const env_1 = require("./env");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
exports.colorize = new Proxy(colorette, {
|
|
10
|
+
get(target, prop) {
|
|
11
|
+
if (env_1.isBrowser) {
|
|
12
|
+
return utils_1.identity;
|
|
13
|
+
}
|
|
14
|
+
return target[prop];
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
class Logger {
|
|
18
|
+
stderr(str) {
|
|
19
|
+
return process.stderr.write(str);
|
|
20
|
+
}
|
|
21
|
+
info(str) {
|
|
22
|
+
return env_1.isBrowser ? console.log(str) : this.stderr(str);
|
|
23
|
+
}
|
|
24
|
+
warn(str) {
|
|
25
|
+
return env_1.isBrowser ? console.warn(str) : this.stderr(exports.colorize.yellow(str));
|
|
26
|
+
}
|
|
27
|
+
error(str) {
|
|
28
|
+
return env_1.isBrowser ? console.error(str) : this.stderr(exports.colorize.red(str));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.logger = new Logger();
|
package/lib/output.d.ts
ADDED
package/lib/output.js
ADDED
package/lib/redocly/index.js
CHANGED
|
@@ -13,26 +13,27 @@ exports.isRedoclyRegistryURL = exports.RedoclyClient = void 0;
|
|
|
13
13
|
const fs_1 = require("fs");
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const os_1 = require("os");
|
|
16
|
-
const colorette_1 = require("colorette");
|
|
17
16
|
const registry_api_1 = require("./registry-api");
|
|
18
17
|
const config_1 = require("../config/config");
|
|
18
|
+
const env_1 = require("../env");
|
|
19
19
|
const utils_1 = require("../utils");
|
|
20
|
+
const logger_1 = require("../logger");
|
|
20
21
|
const TOKEN_FILENAME = '.redocly-config.json';
|
|
21
22
|
class RedoclyClient {
|
|
22
23
|
constructor(region) {
|
|
23
24
|
this.accessTokens = {};
|
|
24
25
|
this.region = this.loadRegion(region);
|
|
25
26
|
this.loadTokens();
|
|
26
|
-
this.domain = region ? config_1.DOMAINS[region] :
|
|
27
|
-
|
|
27
|
+
this.domain = region ? config_1.DOMAINS[region] : env_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
|
|
28
|
+
env_1.env.REDOCLY_DOMAIN = this.domain; // isRedoclyRegistryURL depends on the value to be set
|
|
28
29
|
this.registryApi = new registry_api_1.RegistryApi(this.accessTokens, this.region);
|
|
29
30
|
}
|
|
30
31
|
loadRegion(region) {
|
|
31
32
|
if (region && !config_1.DOMAINS[region]) {
|
|
32
|
-
throw new Error(`Invalid argument: region in config file.\nGiven: ${
|
|
33
|
+
throw new Error(`Invalid argument: region in config file.\nGiven: ${logger_1.colorize.green(region)}, choices: "us", "eu".`);
|
|
33
34
|
}
|
|
34
|
-
if (
|
|
35
|
-
return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[region] ===
|
|
35
|
+
if (env_1.env.REDOCLY_DOMAIN) {
|
|
36
|
+
return (config_1.AVAILABLE_REGIONS.find((region) => config_1.DOMAINS[region] === env_1.env.REDOCLY_DOMAIN) || config_1.DEFAULT_REGION);
|
|
36
37
|
}
|
|
37
38
|
return region || config_1.DEFAULT_REGION;
|
|
38
39
|
}
|
|
@@ -64,8 +65,8 @@ class RedoclyClient {
|
|
|
64
65
|
[this.region]: credentials.token,
|
|
65
66
|
})));
|
|
66
67
|
}
|
|
67
|
-
if (
|
|
68
|
-
this.setAccessTokens(Object.assign(Object.assign({}, this.accessTokens), { [this.region]:
|
|
68
|
+
if (env_1.env.REDOCLY_AUTHORIZATION) {
|
|
69
|
+
this.setAccessTokens(Object.assign(Object.assign({}, this.accessTokens), { [this.region]: env_1.env.REDOCLY_AUTHORIZATION }));
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
getAllTokens() {
|
|
@@ -142,7 +143,7 @@ class RedoclyClient {
|
|
|
142
143
|
}
|
|
143
144
|
exports.RedoclyClient = RedoclyClient;
|
|
144
145
|
function isRedoclyRegistryURL(link) {
|
|
145
|
-
const domain =
|
|
146
|
+
const domain = env_1.env.REDOCLY_DOMAIN || config_1.DOMAINS[config_1.DEFAULT_REGION];
|
|
146
147
|
const legacyDomain = domain === 'redocly.com' ? 'redoc.ly' : domain;
|
|
147
148
|
if (!link.startsWith(`https://api.${domain}/registry/`) &&
|
|
148
149
|
!link.startsWith(`https://api.${legacyDomain}/registry/`)) {
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
version: string;
|
|
6
|
-
}
|
|
7
|
-
export interface PrepareFileuploadParams extends VersionParams {
|
|
8
|
-
filesHash: string;
|
|
9
|
-
filename: string;
|
|
10
|
-
isUpsert?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export interface PushApiParams extends VersionParams {
|
|
13
|
-
rootFilePath: string;
|
|
14
|
-
filePaths: string[];
|
|
15
|
-
branch?: string;
|
|
16
|
-
isUpsert?: boolean;
|
|
17
|
-
isPublic?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export interface PrepareFileuploadOKResponse {
|
|
20
|
-
filePath: string;
|
|
21
|
-
signedUploadUrl: string;
|
|
22
|
-
}
|
|
23
|
-
export interface NotFoundProblemResponse {
|
|
24
|
-
status: 404;
|
|
25
|
-
title: 'Not Found';
|
|
26
|
-
code: 'ORGANIZATION_NOT_FOUND' | 'API_VERSION_NOT_FOUND';
|
|
27
|
-
}
|
|
28
|
-
export {};
|
|
1
|
+
interface VersionParams {
|
|
2
|
+
organizationId: string;
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
29
5
|
}
|
|
6
|
+
export interface PrepareFileuploadParams extends VersionParams {
|
|
7
|
+
filesHash: string;
|
|
8
|
+
filename: string;
|
|
9
|
+
isUpsert?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface PushApiParams extends VersionParams {
|
|
12
|
+
rootFilePath: string;
|
|
13
|
+
filePaths: string[];
|
|
14
|
+
branch?: string;
|
|
15
|
+
isUpsert?: boolean;
|
|
16
|
+
isPublic?: boolean;
|
|
17
|
+
batchId?: string;
|
|
18
|
+
batchSize?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface PrepareFileuploadOKResponse {
|
|
21
|
+
filePath: string;
|
|
22
|
+
signedUploadUrl: string;
|
|
23
|
+
}
|
|
24
|
+
export interface NotFoundProblemResponse {
|
|
25
|
+
status: 404;
|
|
26
|
+
title: 'Not Found';
|
|
27
|
+
code: 'ORGANIZATION_NOT_FOUND' | 'API_VERSION_NOT_FOUND';
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PrepareFileuploadOKResponse, PrepareFileuploadParams, PushApiParams } from './registry-api-types';
|
|
2
2
|
import type { AccessTokens, Region } from '../config/types';
|
|
3
3
|
export declare class RegistryApi {
|
|
4
4
|
private accessTokens;
|
|
@@ -12,6 +12,6 @@ export declare class RegistryApi {
|
|
|
12
12
|
viewerId: string;
|
|
13
13
|
organizations: string[];
|
|
14
14
|
}>;
|
|
15
|
-
prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }:
|
|
16
|
-
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, }:
|
|
15
|
+
prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: PrepareFileuploadParams): Promise<PrepareFileuploadOKResponse>;
|
|
16
|
+
pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize, }: PushApiParams): Promise<void>;
|
|
17
17
|
}
|