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