@redocly/openapi-core 0.0.0-snapshot.1737554067
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 +268 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-many-rules.bench.js +38 -0
- package/lib/benchmark/benches/lint-with-nested-rule.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-nested-rule.bench.js +44 -0
- package/lib/benchmark/benches/lint-with-no-rules.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-no-rules.bench.js +25 -0
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +37 -0
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.d.ts +4 -0
- package/lib/benchmark/benches/lint-with-top-level-rule.bench.js +36 -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 +34 -0
- package/lib/bundle.d.ts +50 -0
- package/lib/bundle.js +385 -0
- package/lib/config/all.d.ts +3 -0
- package/lib/config/all.js +227 -0
- package/lib/config/builtIn.d.ts +3 -0
- package/lib/config/builtIn.js +53 -0
- package/lib/config/config-resolvers.d.ts +30 -0
- package/lib/config/config-resolvers.js +447 -0
- package/lib/config/config.d.ts +53 -0
- package/lib/config/config.js +320 -0
- package/lib/config/index.d.ts +7 -0
- package/lib/config/index.js +23 -0
- package/lib/config/load.d.ts +38 -0
- package/lib/config/load.js +140 -0
- package/lib/config/minimal.d.ts +3 -0
- package/lib/config/minimal.js +203 -0
- package/lib/config/recommended-strict.d.ts +3 -0
- package/lib/config/recommended-strict.js +203 -0
- package/lib/config/recommended.d.ts +3 -0
- package/lib/config/recommended.js +203 -0
- package/lib/config/rules.d.ts +10 -0
- package/lib/config/rules.js +37 -0
- package/lib/config/spec.d.ts +3 -0
- package/lib/config/spec.js +29 -0
- package/lib/config/types.d.ts +189 -0
- package/lib/config/types.js +2 -0
- package/lib/config/utils.d.ts +19 -0
- package/lib/config/utils.js +308 -0
- package/lib/decorators/arazzo/index.d.ts +1 -0
- package/lib/decorators/arazzo/index.js +4 -0
- package/lib/decorators/async2/index.d.ts +1 -0
- package/lib/decorators/async2/index.js +4 -0
- package/lib/decorators/async3/index.d.ts +1 -0
- package/lib/decorators/async3/index.js +4 -0
- package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
- package/lib/decorators/common/filters/filter-helper.js +66 -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-description-override.d.ts +2 -0
- package/lib/decorators/common/info-description-override.js +24 -0
- package/lib/decorators/common/info-override.d.ts +2 -0
- package/lib/decorators/common/info-override.js +17 -0
- package/lib/decorators/common/media-type-examples-override.d.ts +2 -0
- package/lib/decorators/common/media-type-examples-override.js +59 -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 +69 -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 +11 -0
- package/lib/decorators/oas2/index.js +21 -0
- package/lib/decorators/oas2/remove-unused-components.d.ts +2 -0
- package/lib/decorators/oas2/remove-unused-components.js +89 -0
- package/lib/decorators/oas3/index.d.ts +12 -0
- package/lib/decorators/oas3/index.js +23 -0
- package/lib/decorators/oas3/remove-unused-components.d.ts +2 -0
- package/lib/decorators/oas3/remove-unused-components.js +100 -0
- package/lib/env.d.ts +2 -0
- package/lib/env.js +7 -0
- package/lib/format/codeframes.d.ts +22 -0
- package/lib/format/codeframes.js +185 -0
- package/lib/format/format.d.ts +20 -0
- package/lib/format/format.js +365 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +98 -0
- package/lib/js-yaml/index.d.ts +3 -0
- package/lib/js-yaml/index.js +15 -0
- package/lib/lint.d.ts +32 -0
- package/lib/lint.js +118 -0
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +31 -0
- package/lib/oas-types.d.ts +36 -0
- package/lib/oas-types.js +92 -0
- package/lib/output.d.ts +3 -0
- package/lib/output.js +9 -0
- package/lib/redocly/domains.d.ts +14 -0
- package/lib/redocly/domains.js +41 -0
- package/lib/redocly/index.d.ts +30 -0
- package/lib/redocly/index.js +131 -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 +96 -0
- package/lib/ref-utils.d.ts +27 -0
- package/lib/ref-utils.js +85 -0
- package/lib/resolve.d.ts +66 -0
- package/lib/resolve.js +342 -0
- package/lib/rules/ajv.d.ts +10 -0
- package/lib/rules/ajv.js +82 -0
- package/lib/rules/arazzo/criteria-unique.d.ts +2 -0
- package/lib/rules/arazzo/criteria-unique.js +71 -0
- package/lib/rules/arazzo/index.d.ts +3 -0
- package/lib/rules/arazzo/index.js +36 -0
- package/lib/rules/arazzo/parameters-unique.d.ts +2 -0
- package/lib/rules/arazzo/parameters-unique.js +32 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.d.ts +2 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.js +28 -0
- package/lib/rules/arazzo/sourceDescription-type.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescription-type.js +22 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.js +24 -0
- package/lib/rules/arazzo/sourceDescriptions-not-empty.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescriptions-not-empty.js +18 -0
- package/lib/rules/arazzo/step-onFailure-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onFailure-unique.js +32 -0
- package/lib/rules/arazzo/step-onSuccess-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onSuccess-unique.js +32 -0
- package/lib/rules/arazzo/stepId-unique.d.ts +2 -0
- package/lib/rules/arazzo/stepId-unique.js +26 -0
- package/lib/rules/arazzo/workflow-dependsOn.d.ts +2 -0
- package/lib/rules/arazzo/workflow-dependsOn.js +56 -0
- package/lib/rules/arazzo/workflowId-unique.d.ts +2 -0
- package/lib/rules/arazzo/workflowId-unique.js +22 -0
- package/lib/rules/async2/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async2/channels-kebab-case.js +19 -0
- package/lib/rules/async2/index.d.ts +3 -0
- package/lib/rules/async2/index.js +27 -0
- package/lib/rules/async2/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async2/no-channel-trailing-slash.js +16 -0
- package/lib/rules/async3/channels-kebab-case.d.ts +2 -0
- package/lib/rules/async3/channels-kebab-case.js +19 -0
- package/lib/rules/async3/index.d.ts +3 -0
- package/lib/rules/async3/index.js +27 -0
- package/lib/rules/async3/no-channel-trailing-slash.d.ts +2 -0
- package/lib/rules/async3/no-channel-trailing-slash.js +16 -0
- package/lib/rules/common/assertions/asserts.d.ts +30 -0
- package/lib/rules/common/assertions/asserts.js +281 -0
- package/lib/rules/common/assertions/index.d.ts +27 -0
- package/lib/rules/common/assertions/index.js +24 -0
- package/lib/rules/common/assertions/utils.d.ts +28 -0
- package/lib/rules/common/assertions/utils.js +226 -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-license-strict.d.ts +2 -0
- package/lib/rules/common/info-license-strict.js +26 -0
- package/lib/rules/common/info-license-url.d.ts +2 -0
- package/lib/rules/common/info-license-url.js +12 -0
- 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.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 +41 -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 +24 -0
- package/lib/rules/common/no-invalid-schema-examples.d.ts +1 -0
- package/lib/rules/common/no-invalid-schema-examples.js +22 -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/no-required-schema-properties-undefined.d.ts +2 -0
- package/lib/rules/common/no-required-schema-properties-undefined.js +36 -0
- package/lib/rules/common/operation-2xx-response.d.ts +2 -0
- package/lib/rules/common/operation-2xx-response.js +23 -0
- package/lib/rules/common/operation-4xx-response.d.ts +2 -0
- package/lib/rules/common/operation-4xx-response.js +23 -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 +18 -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-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 +24 -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 +58 -0
- package/lib/rules/common/path-segment-plural.d.ts +2 -0
- package/lib/rules/common/path-segment-plural.js +33 -0
- package/lib/rules/common/paths-kebab-case.d.ts +2 -0
- package/lib/rules/common/paths-kebab-case.js +20 -0
- package/lib/rules/common/required-string-property-missing-min-length.d.ts +2 -0
- package/lib/rules/common/required-string-property-missing-min-length.js +37 -0
- package/lib/rules/common/response-contains-header.d.ts +2 -0
- package/lib/rules/common/response-contains-header.js +29 -0
- package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
- package/lib/rules/common/scalar-property-missing-example.js +42 -0
- package/lib/rules/common/security-defined.d.ts +2 -0
- package/lib/rules/common/security-defined.js +65 -0
- 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/struct.d.ts +2 -0
- package/lib/rules/common/struct.js +158 -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 +23 -0
- package/lib/rules/no-unresolved-refs.d.ts +5 -0
- package/lib/rules/no-unresolved-refs.js +46 -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 +3 -0
- package/lib/rules/oas2/index.js +98 -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 +37 -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/array-parameter-serialization.d.ts +5 -0
- package/lib/rules/oas3/array-parameter-serialization.js +29 -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/component-name-unique.d.ts +2 -0
- package/lib/rules/oas3/component-name-unique.js +133 -0
- package/lib/rules/oas3/index.d.ts +3 -0
- package/lib/rules/oas3/index.js +122 -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 +39 -0
- package/lib/rules/oas3/no-server-example.com.d.ts +2 -0
- package/lib/rules/oas3/no-server-example.com.js +18 -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-server-variables-empty-enum.d.ts +2 -0
- package/lib/rules/oas3/no-server-variables-empty-enum.js +66 -0
- package/lib/rules/oas3/no-undefined-server-variable.d.ts +2 -0
- package/lib/rules/oas3/no-undefined-server-variable.js +31 -0
- package/lib/rules/oas3/no-unused-components.d.ts +2 -0
- package/lib/rules/oas3/no-unused-components.js +73 -0
- 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/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 +39 -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/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 +41 -0
- package/lib/rules/other/stats.js +75 -0
- package/lib/rules/spot/no-criteria-xpath.d.ts +2 -0
- package/lib/rules/spot/no-criteria-xpath.js +21 -0
- package/lib/rules/spot/spot-supported-versions.d.ts +2 -0
- package/lib/rules/spot/spot-supported-versions.js +21 -0
- package/lib/rules/utils.d.ts +22 -0
- package/lib/rules/utils.js +183 -0
- package/lib/types/arazzo.d.ts +2 -0
- package/lib/types/arazzo.js +311 -0
- package/lib/types/asyncapi2.d.ts +17 -0
- package/lib/types/asyncapi2.js +1008 -0
- package/lib/types/asyncapi3.d.ts +2 -0
- package/lib/types/asyncapi3.js +347 -0
- package/lib/types/index.d.ts +57 -0
- package/lib/types/index.js +94 -0
- package/lib/types/json-schema-adapter.d.ts +3 -0
- package/lib/types/json-schema-adapter.js +159 -0
- package/lib/types/oas2.d.ts +3 -0
- package/lib/types/oas2.js +456 -0
- package/lib/types/oas3.d.ts +7 -0
- package/lib/types/oas3.js +554 -0
- package/lib/types/oas3_1.d.ts +6 -0
- package/lib/types/oas3_1.js +285 -0
- package/lib/types/redocly-yaml.d.ts +26 -0
- package/lib/types/redocly-yaml.js +1126 -0
- package/lib/typings/arazzo.d.ts +131 -0
- package/lib/typings/arazzo.js +5 -0
- package/lib/typings/asyncapi.d.ts +21 -0
- package/lib/typings/asyncapi.js +2 -0
- package/lib/typings/asyncapi3.d.ts +53 -0
- package/lib/typings/asyncapi3.js +2 -0
- package/lib/typings/common.d.ts +8 -0
- package/lib/typings/common.js +2 -0
- package/lib/typings/openapi.d.ts +355 -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 +70 -0
- package/lib/utils.js +301 -0
- package/lib/visitors.d.ts +229 -0
- package/lib/visitors.js +176 -0
- package/lib/walk.d.ts +78 -0
- package/lib/walk.js +290 -0
- package/package.json +59 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { NormalizedNodeType } from './types';
|
|
2
|
+
import type { Stack } from './utils';
|
|
3
|
+
import type { UserContext, ResolveResult, ProblemSeverity } from './walk';
|
|
4
|
+
import type { Location } from './ref-utils';
|
|
5
|
+
import type { Oas3Definition, Oas3_1Definition, Oas3ExternalDocs, Oas3Info, Oas3Contact, Oas3Components, Oas3_1Components, Oas3License, Oas3Schema, Oas3_1Schema, Oas3Header, Oas3Parameter, Oas3Operation, Oas3PathItem, Oas3ServerVariable, Oas3Server, Oas3MediaType, Oas3Response, Oas3Example, Oas3RequestBody, Oas3Tag, OasRef, Oas3SecurityScheme, Oas3SecurityRequirement, Oas3Encoding, Oas3Link, Oas3Xml, Oas3Discriminator, Oas3Callback } from './typings/openapi';
|
|
6
|
+
import type { Oas2Definition, Oas2Tag, Oas2ExternalDocs, Oas2SecurityRequirement, Oas2Info, Oas2Contact, Oas2License, Oas2PathItem, Oas2Operation, Oas2Header, Oas2Response, Oas2Schema, Oas2Xml, Oas2Parameter, Oas2SecurityScheme } from './typings/swagger';
|
|
7
|
+
import type { Async2Definition } from './typings/asyncapi';
|
|
8
|
+
import type { Async3Definition } from './typings/asyncapi3';
|
|
9
|
+
import type { ArazzoDefinition, ArazzoSourceDescription, CriteriaObject, ExtendedOperation, InfoObject, OnFailureObject, OnSuccessObject, OpenAPISourceDescription, Parameter, Replacement, RequestBody, SourceDescription, Step, Workflow } from './typings/arazzo';
|
|
10
|
+
export type SkipFunctionContext = Pick<UserContext, 'location' | 'rawNode' | 'resolve' | 'rawLocation'>;
|
|
11
|
+
export type VisitFunction<T> = (node: T, ctx: UserContext & {
|
|
12
|
+
ignoreNextVisitorsOnNode: () => void;
|
|
13
|
+
}, parents?: any, context?: any) => void;
|
|
14
|
+
type VisitRefFunction = (node: OasRef, ctx: UserContext, resolved: ResolveResult<any>) => void;
|
|
15
|
+
type SkipFunction<T> = (node: T, key: string | number, ctx: SkipFunctionContext) => boolean;
|
|
16
|
+
type VisitObject<T> = {
|
|
17
|
+
enter?: VisitFunction<T>;
|
|
18
|
+
leave?: VisitFunction<T>;
|
|
19
|
+
skip?: SkipFunction<T>;
|
|
20
|
+
};
|
|
21
|
+
export type NestedVisitObject<T, P> = VisitObject<T> & NestedVisitor<P>;
|
|
22
|
+
type VisitFunctionOrObject<T> = VisitFunction<T> | VisitObject<T>;
|
|
23
|
+
export type VisitorNode<T> = {
|
|
24
|
+
ruleId: string;
|
|
25
|
+
severity: ProblemSeverity;
|
|
26
|
+
message?: string;
|
|
27
|
+
context: VisitorLevelContext | VisitorSkippedLevelContext;
|
|
28
|
+
depth: number;
|
|
29
|
+
visit: VisitFunction<T>;
|
|
30
|
+
skip?: SkipFunction<T>;
|
|
31
|
+
};
|
|
32
|
+
type VisitorRefNode = {
|
|
33
|
+
ruleId: string;
|
|
34
|
+
severity: ProblemSeverity;
|
|
35
|
+
message?: string;
|
|
36
|
+
context: VisitorLevelContext;
|
|
37
|
+
depth: number;
|
|
38
|
+
visit: VisitRefFunction;
|
|
39
|
+
};
|
|
40
|
+
export type VisitorLevelContext = {
|
|
41
|
+
isSkippedLevel: false;
|
|
42
|
+
type: NormalizedNodeType;
|
|
43
|
+
parent: VisitorLevelContext | null;
|
|
44
|
+
activatedOn: Stack<{
|
|
45
|
+
node?: any;
|
|
46
|
+
withParentNode?: any;
|
|
47
|
+
skipped: boolean;
|
|
48
|
+
nextLevelTypeActivated: Stack<NormalizedNodeType>;
|
|
49
|
+
location?: Location;
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
export type VisitorSkippedLevelContext = {
|
|
53
|
+
isSkippedLevel: true;
|
|
54
|
+
parent: VisitorLevelContext;
|
|
55
|
+
seen: Set<any>;
|
|
56
|
+
};
|
|
57
|
+
export type NormalizeVisitor<Fn> = Fn extends VisitFunction<infer T> ? VisitorNode<T> : never;
|
|
58
|
+
export type BaseVisitor = {
|
|
59
|
+
any?: {
|
|
60
|
+
enter?: VisitFunction<any>;
|
|
61
|
+
leave?: VisitFunction<any>;
|
|
62
|
+
skip?: SkipFunction<any>;
|
|
63
|
+
} | VisitFunction<any>;
|
|
64
|
+
ref?: {
|
|
65
|
+
enter?: VisitRefFunction;
|
|
66
|
+
leave?: VisitRefFunction;
|
|
67
|
+
} | VisitRefFunction;
|
|
68
|
+
};
|
|
69
|
+
type Oas3FlatVisitor = {
|
|
70
|
+
Root?: VisitFunctionOrObject<Oas3Definition | Oas3_1Definition>;
|
|
71
|
+
Tag?: VisitFunctionOrObject<Oas3Tag>;
|
|
72
|
+
ExternalDocs?: VisitFunctionOrObject<Oas3ExternalDocs>;
|
|
73
|
+
Server?: VisitFunctionOrObject<Oas3Server>;
|
|
74
|
+
ServerVariable?: VisitFunctionOrObject<Oas3ServerVariable>;
|
|
75
|
+
SecurityRequirement?: VisitFunctionOrObject<Oas3SecurityRequirement>;
|
|
76
|
+
Info?: VisitFunctionOrObject<Oas3Info>;
|
|
77
|
+
Contact?: VisitFunctionOrObject<Oas3Contact>;
|
|
78
|
+
License?: VisitFunctionOrObject<Oas3License>;
|
|
79
|
+
Paths?: VisitFunctionOrObject<Record<string, Oas3PathItem<Oas3Schema | Oas3_1Schema>>>;
|
|
80
|
+
PathItem?: VisitFunctionOrObject<Oas3PathItem<Oas3Schema | Oas3_1Schema>>;
|
|
81
|
+
Callback?: VisitFunctionOrObject<Oas3Callback<Oas3Schema | Oas3_1Schema>>;
|
|
82
|
+
CallbacksMap?: VisitFunctionOrObject<Record<string, Oas3Callback<Oas3Schema | Oas3_1Schema>>>;
|
|
83
|
+
Parameter?: VisitFunctionOrObject<Oas3Parameter<Oas3Schema | Oas3_1Schema>>;
|
|
84
|
+
Operation?: VisitFunctionOrObject<Oas3Operation<Oas3Schema | Oas3_1Schema>>;
|
|
85
|
+
RequestBody?: VisitFunctionOrObject<Oas3RequestBody<Oas3Schema | Oas3_1Schema>>;
|
|
86
|
+
MediaTypesMap?: VisitFunctionOrObject<Record<string, Oas3MediaType<Oas3Schema | Oas3_1Schema>>>;
|
|
87
|
+
MediaType?: VisitFunctionOrObject<Oas3MediaType<Oas3Schema | Oas3_1Schema>>;
|
|
88
|
+
Example?: VisitFunctionOrObject<Oas3Example>;
|
|
89
|
+
Encoding?: VisitFunctionOrObject<Oas3Encoding<Oas3Schema | Oas3_1Schema>>;
|
|
90
|
+
Header?: VisitFunctionOrObject<Oas3Header<Oas3Schema | Oas3_1Schema>>;
|
|
91
|
+
Responses?: VisitFunctionOrObject<Record<string, Oas3Response<Oas3Schema | Oas3_1Schema>>>;
|
|
92
|
+
Response?: VisitFunctionOrObject<Oas3Response<Oas3Schema | Oas3_1Schema>>;
|
|
93
|
+
Link?: VisitFunctionOrObject<Oas3Link>;
|
|
94
|
+
Schema?: VisitFunctionOrObject<Oas3Schema | Oas3_1Schema>;
|
|
95
|
+
Xml?: VisitFunctionOrObject<Oas3Xml>;
|
|
96
|
+
SchemaProperties?: VisitFunctionOrObject<Record<string, Oas3Schema>>;
|
|
97
|
+
DiscriminatorMapping?: VisitFunctionOrObject<Record<string, string>>;
|
|
98
|
+
Discriminator?: VisitFunctionOrObject<Oas3Discriminator>;
|
|
99
|
+
Components?: VisitFunctionOrObject<Oas3Components | Oas3_1Components>;
|
|
100
|
+
NamedSchemas?: VisitFunctionOrObject<Record<string, Oas3Schema>>;
|
|
101
|
+
NamedResponses?: VisitFunctionOrObject<Record<string, Oas3Response<Oas3Schema | Oas3_1Schema>>>;
|
|
102
|
+
NamedParameters?: VisitFunctionOrObject<Record<string, Oas3Parameter<Oas3Schema | Oas3_1Schema>>>;
|
|
103
|
+
NamedExamples?: VisitFunctionOrObject<Record<string, Oas3Example>>;
|
|
104
|
+
NamedRequestBodies?: VisitFunctionOrObject<Record<string, Oas3RequestBody<Oas3Schema | Oas3_1Schema>>>;
|
|
105
|
+
NamedHeaders?: VisitFunctionOrObject<Record<string, Oas3Header<Oas3Schema | Oas3_1Schema>>>;
|
|
106
|
+
NamedSecuritySchemes?: VisitFunctionOrObject<Record<string, Oas3SecurityScheme>>;
|
|
107
|
+
NamedLinks?: VisitFunctionOrObject<Record<string, Oas3Link>>;
|
|
108
|
+
NamedCallbacks?: VisitFunctionOrObject<Record<string, Oas3Callback<Oas3Schema | Oas3_1Schema>>>;
|
|
109
|
+
ImplicitFlow?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['implicit']>;
|
|
110
|
+
PasswordFlow?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['password']>;
|
|
111
|
+
ClientCredentials?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['clientCredentials']>;
|
|
112
|
+
AuthorizationCode?: VisitFunctionOrObject<Oas3SecurityScheme['flows']['authorizationCode']>;
|
|
113
|
+
OAuth2Flows?: VisitFunctionOrObject<Oas3SecurityScheme['flows']>;
|
|
114
|
+
SecurityScheme?: VisitFunctionOrObject<Oas3SecurityScheme>;
|
|
115
|
+
SpecExtension?: VisitFunctionOrObject<unknown>;
|
|
116
|
+
};
|
|
117
|
+
type Oas2FlatVisitor = {
|
|
118
|
+
Root?: VisitFunctionOrObject<Oas2Definition>;
|
|
119
|
+
Tag?: VisitFunctionOrObject<Oas2Tag>;
|
|
120
|
+
ExternalDocs?: VisitFunctionOrObject<Oas2ExternalDocs>;
|
|
121
|
+
SecurityRequirement?: VisitFunctionOrObject<Oas2SecurityRequirement>;
|
|
122
|
+
Info?: VisitFunctionOrObject<Oas2Info>;
|
|
123
|
+
Contact?: VisitFunctionOrObject<Oas2Contact>;
|
|
124
|
+
License?: VisitFunctionOrObject<Oas2License>;
|
|
125
|
+
Paths?: VisitFunctionOrObject<Record<string, Oas2PathItem>>;
|
|
126
|
+
PathItem?: VisitFunctionOrObject<Oas2PathItem>;
|
|
127
|
+
Parameter?: VisitFunctionOrObject<any>;
|
|
128
|
+
Operation?: VisitFunctionOrObject<Oas2Operation>;
|
|
129
|
+
Examples?: VisitFunctionOrObject<Record<string, any>>;
|
|
130
|
+
Header?: VisitFunctionOrObject<Oas2Header>;
|
|
131
|
+
Responses?: VisitFunctionOrObject<Record<string, Oas2Response>>;
|
|
132
|
+
Response?: VisitFunctionOrObject<Oas2Response>;
|
|
133
|
+
Schema?: VisitFunctionOrObject<Oas2Schema>;
|
|
134
|
+
Xml?: VisitFunctionOrObject<Oas2Xml>;
|
|
135
|
+
SchemaProperties?: VisitFunctionOrObject<Record<string, Oas2Schema>>;
|
|
136
|
+
NamedSchemas?: VisitFunctionOrObject<Record<string, Oas2Schema>>;
|
|
137
|
+
NamedResponses?: VisitFunctionOrObject<Record<string, Oas2Response>>;
|
|
138
|
+
NamedParameters?: VisitFunctionOrObject<Record<string, Oas2Parameter>>;
|
|
139
|
+
SecurityScheme?: VisitFunctionOrObject<Oas2SecurityScheme>;
|
|
140
|
+
NamedSecuritySchemes?: VisitFunctionOrObject<Record<string, Oas2SecurityScheme>>;
|
|
141
|
+
SpecExtension?: VisitFunctionOrObject<unknown>;
|
|
142
|
+
};
|
|
143
|
+
type Async2FlatVisitor = {
|
|
144
|
+
Root?: VisitFunctionOrObject<Async2Definition>;
|
|
145
|
+
};
|
|
146
|
+
type Async3FlatVisitor = {
|
|
147
|
+
Root?: VisitFunctionOrObject<Async3Definition>;
|
|
148
|
+
};
|
|
149
|
+
type ArazzoFlatVisitor = {
|
|
150
|
+
Root?: VisitFunctionOrObject<ArazzoDefinition>;
|
|
151
|
+
ParameterObject?: VisitFunctionOrObject<Parameter>;
|
|
152
|
+
InfoObject?: VisitFunctionOrObject<InfoObject>;
|
|
153
|
+
OpenAPISourceDescription?: VisitFunctionOrObject<OpenAPISourceDescription>;
|
|
154
|
+
ArazzoSourceDescription?: VisitFunctionOrObject<ArazzoSourceDescription>;
|
|
155
|
+
SourceDescription?: VisitFunctionOrObject<SourceDescription>;
|
|
156
|
+
ExtendedOperation?: VisitFunctionOrObject<ExtendedOperation>;
|
|
157
|
+
Replacement?: VisitFunctionOrObject<Replacement>;
|
|
158
|
+
RequestBody?: VisitFunctionOrObject<RequestBody>;
|
|
159
|
+
CriteriaObject?: VisitFunctionOrObject<CriteriaObject>;
|
|
160
|
+
OnSuccessObject?: VisitFunctionOrObject<OnSuccessObject>;
|
|
161
|
+
OnFailureObject?: VisitFunctionOrObject<OnFailureObject>;
|
|
162
|
+
Step?: VisitFunctionOrObject<Step>;
|
|
163
|
+
Steps?: VisitFunctionOrObject<Step[]>;
|
|
164
|
+
Workflow?: VisitFunctionOrObject<Workflow>;
|
|
165
|
+
Workflows?: VisitFunctionOrObject<Workflow[]>;
|
|
166
|
+
};
|
|
167
|
+
type Oas3NestedVisitor = {
|
|
168
|
+
[T in keyof Oas3FlatVisitor]: Oas3FlatVisitor[T] extends Function ? Oas3FlatVisitor[T] : Oas3FlatVisitor[T] & NestedVisitor<Oas3NestedVisitor>;
|
|
169
|
+
};
|
|
170
|
+
type Oas2NestedVisitor = {
|
|
171
|
+
[T in keyof Oas2FlatVisitor]: Oas2FlatVisitor[T] extends Function ? Oas2FlatVisitor[T] : Oas2FlatVisitor[T] & NestedVisitor<Oas2NestedVisitor>;
|
|
172
|
+
};
|
|
173
|
+
type Async2NestedVisitor = {
|
|
174
|
+
[T in keyof Async2FlatVisitor]: Async2FlatVisitor[T] extends Function ? Async2FlatVisitor[T] : Async2FlatVisitor[T] & NestedVisitor<Async2NestedVisitor>;
|
|
175
|
+
};
|
|
176
|
+
type Async3NestedVisitor = {
|
|
177
|
+
[T in keyof Async3FlatVisitor]: Async3FlatVisitor[T] extends Function ? Async3FlatVisitor[T] : Async3FlatVisitor[T] & NestedVisitor<Async3NestedVisitor>;
|
|
178
|
+
};
|
|
179
|
+
type ArazzoNestedVisitor = {
|
|
180
|
+
[T in keyof ArazzoFlatVisitor]: ArazzoFlatVisitor[T] extends Function ? ArazzoFlatVisitor[T] : ArazzoFlatVisitor[T] & NestedVisitor<ArazzoNestedVisitor>;
|
|
181
|
+
};
|
|
182
|
+
export type Oas3Visitor = BaseVisitor & Oas3NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas3NestedVisitor>>;
|
|
183
|
+
export type Oas2Visitor = BaseVisitor & Oas2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Oas2NestedVisitor>>;
|
|
184
|
+
export type Async2Visitor = BaseVisitor & Async2NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Async2NestedVisitor>>;
|
|
185
|
+
export type Async3Visitor = BaseVisitor & Async3NestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, Async3NestedVisitor>>;
|
|
186
|
+
export type Arazzo1Visitor = BaseVisitor & ArazzoNestedVisitor & Record<string, VisitFunction<any> | NestedVisitObject<any, ArazzoNestedVisitor>>;
|
|
187
|
+
export type NestedVisitor<T> = Exclude<T, 'any' | 'ref' | 'Root'>;
|
|
188
|
+
export type NormalizedOasVisitors<T extends BaseVisitor> = {
|
|
189
|
+
[V in keyof T]-?: {
|
|
190
|
+
enter: Array<NormalizeVisitor<T[V]>>;
|
|
191
|
+
leave: Array<NormalizeVisitor<T[V]>>;
|
|
192
|
+
};
|
|
193
|
+
} & {
|
|
194
|
+
ref: {
|
|
195
|
+
enter: Array<VisitorRefNode>;
|
|
196
|
+
leave: Array<VisitorRefNode>;
|
|
197
|
+
};
|
|
198
|
+
[k: string]: {
|
|
199
|
+
enter: Array<VisitorNode<any>>;
|
|
200
|
+
leave: Array<VisitorNode<any>>;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
export type Oas3Rule = (options: Record<string, any>) => Oas3Visitor | Oas3Visitor[];
|
|
204
|
+
export type Oas2Rule = (options: Record<string, any>) => Oas2Visitor | Oas2Visitor[];
|
|
205
|
+
export type Async2Rule = (options: Record<string, any>) => Async2Visitor | Async2Visitor[];
|
|
206
|
+
export type Async3Rule = (options: Record<string, any>) => Async3Visitor | Async3Visitor[];
|
|
207
|
+
export type Arazzo1Rule = (options: Record<string, any>) => Arazzo1Visitor | Arazzo1Visitor[];
|
|
208
|
+
export type Oas3Preprocessor = (options: Record<string, any>) => Oas3Visitor;
|
|
209
|
+
export type Oas2Preprocessor = (options: Record<string, any>) => Oas2Visitor;
|
|
210
|
+
export type Async2Preprocessor = (options: Record<string, any>) => Async2Visitor;
|
|
211
|
+
export type Async3Preprocessor = (options: Record<string, any>) => Async3Visitor;
|
|
212
|
+
export type Arazzo1Preprocessor = (options: Record<string, any>) => Arazzo1Visitor;
|
|
213
|
+
export type Oas3Decorator = (options: Record<string, any>) => Oas3Visitor;
|
|
214
|
+
export type Oas2Decorator = (options: Record<string, any>) => Oas2Visitor;
|
|
215
|
+
export type Async2Decorator = (options: Record<string, any>) => Async2Visitor;
|
|
216
|
+
export type Async3Decorator = (options: Record<string, any>) => Async3Visitor;
|
|
217
|
+
export type Arazzo1Decorator = (options: Record<string, any>) => Arazzo1Visitor;
|
|
218
|
+
export type OasRule = Oas3Rule;
|
|
219
|
+
export type OasPreprocessor = Oas3Preprocessor;
|
|
220
|
+
export type OasDecorator = Oas3Decorator;
|
|
221
|
+
export type RuleInstanceConfig = {
|
|
222
|
+
ruleId: string;
|
|
223
|
+
severity: ProblemSeverity;
|
|
224
|
+
message?: string;
|
|
225
|
+
};
|
|
226
|
+
export declare function normalizeVisitors<T extends BaseVisitor>(visitorsConfig: (RuleInstanceConfig & {
|
|
227
|
+
visitor: NestedVisitObject<unknown, T>;
|
|
228
|
+
})[], types: Record<keyof T, NormalizedNodeType>): NormalizedOasVisitors<T>;
|
|
229
|
+
export {};
|
package/lib/visitors.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeVisitors = normalizeVisitors;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const legacyTypesMap = {
|
|
6
|
+
Root: 'DefinitionRoot',
|
|
7
|
+
ServerVariablesMap: 'ServerVariableMap',
|
|
8
|
+
Paths: ['PathMap', 'PathsMap'],
|
|
9
|
+
CallbacksMap: 'CallbackMap',
|
|
10
|
+
MediaTypesMap: 'MediaTypeMap',
|
|
11
|
+
ExamplesMap: 'ExampleMap',
|
|
12
|
+
EncodingMap: 'EncodingsMap',
|
|
13
|
+
HeadersMap: 'HeaderMap',
|
|
14
|
+
LinksMap: 'LinkMap',
|
|
15
|
+
OAuth2Flows: 'SecuritySchemeFlows',
|
|
16
|
+
Responses: 'ResponsesMap',
|
|
17
|
+
};
|
|
18
|
+
function normalizeVisitors(visitorsConfig, types) {
|
|
19
|
+
const normalizedVisitors = {};
|
|
20
|
+
normalizedVisitors.any = {
|
|
21
|
+
enter: [],
|
|
22
|
+
leave: [],
|
|
23
|
+
};
|
|
24
|
+
for (const typeName of Object.keys(types)) {
|
|
25
|
+
normalizedVisitors[typeName] = {
|
|
26
|
+
enter: [],
|
|
27
|
+
leave: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
normalizedVisitors.ref = {
|
|
31
|
+
enter: [],
|
|
32
|
+
leave: [],
|
|
33
|
+
};
|
|
34
|
+
for (const { ruleId, severity, message, visitor } of visitorsConfig) {
|
|
35
|
+
normalizeVisitorLevel({ ruleId, severity, message }, visitor, null);
|
|
36
|
+
}
|
|
37
|
+
for (const v of Object.keys(normalizedVisitors)) {
|
|
38
|
+
normalizedVisitors[v].enter.sort((a, b) => b.depth - a.depth);
|
|
39
|
+
normalizedVisitors[v].leave.sort((a, b) => a.depth - b.depth);
|
|
40
|
+
}
|
|
41
|
+
return normalizedVisitors;
|
|
42
|
+
function addWeakNodes(ruleConf, from, to, parentContext, stack = []) {
|
|
43
|
+
if (stack.includes(from))
|
|
44
|
+
return;
|
|
45
|
+
stack = [...stack, from];
|
|
46
|
+
const possibleChildren = new Set();
|
|
47
|
+
for (const type of Object.values(from.properties)) {
|
|
48
|
+
if (type === to) {
|
|
49
|
+
addWeakFromStack(ruleConf, stack);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (typeof type === 'object' && type !== null && type.name) {
|
|
53
|
+
possibleChildren.add(type);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (from.additionalProperties && typeof from.additionalProperties !== 'function') {
|
|
57
|
+
if (from.additionalProperties === to) {
|
|
58
|
+
addWeakFromStack(ruleConf, stack);
|
|
59
|
+
}
|
|
60
|
+
else if (from.additionalProperties.name !== undefined) {
|
|
61
|
+
possibleChildren.add(from.additionalProperties);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (from.items && typeof from.items !== 'function') {
|
|
65
|
+
if (from.items === to) {
|
|
66
|
+
addWeakFromStack(ruleConf, stack);
|
|
67
|
+
}
|
|
68
|
+
else if (from.items.name !== undefined) {
|
|
69
|
+
possibleChildren.add(from.items);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (from.extensionsPrefix) {
|
|
73
|
+
possibleChildren.add(types_1.SpecExtension);
|
|
74
|
+
}
|
|
75
|
+
for (const fromType of Array.from(possibleChildren.values())) {
|
|
76
|
+
addWeakNodes(ruleConf, fromType, to, parentContext, stack);
|
|
77
|
+
}
|
|
78
|
+
function addWeakFromStack(ruleConf, stack) {
|
|
79
|
+
for (const interType of stack.slice(1)) {
|
|
80
|
+
normalizedVisitors[interType.name] = normalizedVisitors[interType.name] || {
|
|
81
|
+
enter: [],
|
|
82
|
+
leave: [],
|
|
83
|
+
};
|
|
84
|
+
normalizedVisitors[interType.name].enter.push({
|
|
85
|
+
...ruleConf,
|
|
86
|
+
visit: () => undefined,
|
|
87
|
+
depth: 0,
|
|
88
|
+
context: {
|
|
89
|
+
isSkippedLevel: true,
|
|
90
|
+
seen: new Set(),
|
|
91
|
+
parent: parentContext,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function findLegacyVisitorNode(visitor, typeName) {
|
|
98
|
+
if (Array.isArray(typeName)) {
|
|
99
|
+
const name = typeName.find((name) => visitor[name]) || undefined;
|
|
100
|
+
return name && visitor[name];
|
|
101
|
+
}
|
|
102
|
+
return visitor[typeName];
|
|
103
|
+
}
|
|
104
|
+
function normalizeVisitorLevel(ruleConf, visitor, parentContext, depth = 0) {
|
|
105
|
+
const visitorKeys = Object.keys(types);
|
|
106
|
+
if (depth === 0) {
|
|
107
|
+
visitorKeys.push('any');
|
|
108
|
+
visitorKeys.push('ref');
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
if (visitor.any) {
|
|
112
|
+
throw new Error('any() is allowed only on top level');
|
|
113
|
+
}
|
|
114
|
+
if (visitor.ref) {
|
|
115
|
+
throw new Error('ref() is allowed only on top level');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
for (const typeName of visitorKeys) {
|
|
119
|
+
const typeVisitor = (visitor[typeName] ||
|
|
120
|
+
findLegacyVisitorNode(visitor, legacyTypesMap[typeName]));
|
|
121
|
+
const normalizedTypeVisitor = normalizedVisitors[typeName];
|
|
122
|
+
if (!typeVisitor)
|
|
123
|
+
continue;
|
|
124
|
+
let visitorEnter;
|
|
125
|
+
let visitorLeave;
|
|
126
|
+
let visitorSkip;
|
|
127
|
+
const isObjectVisitor = typeof typeVisitor === 'object';
|
|
128
|
+
if (typeName === 'ref' && isObjectVisitor && typeVisitor.skip) {
|
|
129
|
+
throw new Error('ref() visitor does not support skip');
|
|
130
|
+
}
|
|
131
|
+
if (typeof typeVisitor === 'function') {
|
|
132
|
+
visitorEnter = typeVisitor;
|
|
133
|
+
}
|
|
134
|
+
else if (isObjectVisitor) {
|
|
135
|
+
visitorEnter = typeVisitor.enter;
|
|
136
|
+
visitorLeave = typeVisitor.leave;
|
|
137
|
+
visitorSkip = typeVisitor.skip;
|
|
138
|
+
}
|
|
139
|
+
const context = {
|
|
140
|
+
activatedOn: null,
|
|
141
|
+
type: types[typeName],
|
|
142
|
+
parent: parentContext,
|
|
143
|
+
isSkippedLevel: false,
|
|
144
|
+
};
|
|
145
|
+
if (typeof typeVisitor === 'object') {
|
|
146
|
+
normalizeVisitorLevel(ruleConf, typeVisitor, context, depth + 1);
|
|
147
|
+
}
|
|
148
|
+
if (parentContext) {
|
|
149
|
+
addWeakNodes(ruleConf, parentContext.type, types[typeName], parentContext);
|
|
150
|
+
}
|
|
151
|
+
if (visitorEnter || isObjectVisitor) {
|
|
152
|
+
if (visitorEnter && typeof visitorEnter !== 'function') {
|
|
153
|
+
throw new Error('DEV: should be function');
|
|
154
|
+
}
|
|
155
|
+
normalizedTypeVisitor.enter.push({
|
|
156
|
+
...ruleConf,
|
|
157
|
+
visit: visitorEnter || (() => undefined),
|
|
158
|
+
skip: visitorSkip,
|
|
159
|
+
depth,
|
|
160
|
+
context,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (visitorLeave) {
|
|
164
|
+
if (typeof visitorLeave !== 'function') {
|
|
165
|
+
throw new Error('DEV: should be function');
|
|
166
|
+
}
|
|
167
|
+
normalizedTypeVisitor.leave.push({
|
|
168
|
+
...ruleConf,
|
|
169
|
+
visit: visitorLeave,
|
|
170
|
+
depth,
|
|
171
|
+
context,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
package/lib/walk.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Location } from './ref-utils';
|
|
2
|
+
import { YamlParseError } from './resolve';
|
|
3
|
+
import type { SpecVersion } from './oas-types';
|
|
4
|
+
import type { ResolveError, Source, ResolvedRefMap, Document } from './resolve';
|
|
5
|
+
import type { Referenced } from './typings/openapi';
|
|
6
|
+
import type { NormalizedOasVisitors, BaseVisitor } from './visitors';
|
|
7
|
+
import type { NormalizedNodeType } from './types';
|
|
8
|
+
import type { RuleSeverity } from './config';
|
|
9
|
+
export type NonUndefined = string | number | boolean | symbol | bigint | object | Record<string, any>;
|
|
10
|
+
export type ResolveResult<T extends NonUndefined> = {
|
|
11
|
+
node: T;
|
|
12
|
+
location: Location;
|
|
13
|
+
error?: ResolveError | YamlParseError;
|
|
14
|
+
} | {
|
|
15
|
+
node: undefined;
|
|
16
|
+
location: undefined;
|
|
17
|
+
error?: ResolveError | YamlParseError;
|
|
18
|
+
};
|
|
19
|
+
export type ResolveFn = <T extends NonUndefined>(node: Referenced<T>, from?: string) => ResolveResult<T>;
|
|
20
|
+
export type UserContext = {
|
|
21
|
+
report(problem: Problem): void;
|
|
22
|
+
location: Location;
|
|
23
|
+
rawNode: any;
|
|
24
|
+
rawLocation: Location;
|
|
25
|
+
resolve: ResolveFn;
|
|
26
|
+
parentLocations: Record<string, Location>;
|
|
27
|
+
type: NormalizedNodeType;
|
|
28
|
+
key: string | number;
|
|
29
|
+
parent: any;
|
|
30
|
+
oasVersion: SpecVersion;
|
|
31
|
+
getVisitorData: () => Record<string, unknown>;
|
|
32
|
+
};
|
|
33
|
+
export type Loc = {
|
|
34
|
+
line: number;
|
|
35
|
+
col: number;
|
|
36
|
+
};
|
|
37
|
+
export type PointerLocationObject = {
|
|
38
|
+
source: Source;
|
|
39
|
+
reportOnKey?: boolean;
|
|
40
|
+
pointer: string;
|
|
41
|
+
};
|
|
42
|
+
export type LineColLocationObject = Omit<PointerLocationObject, 'pointer'> & {
|
|
43
|
+
pointer: undefined;
|
|
44
|
+
start: Loc;
|
|
45
|
+
end?: Loc;
|
|
46
|
+
};
|
|
47
|
+
export type LocationObject = LineColLocationObject | PointerLocationObject;
|
|
48
|
+
export type ProblemSeverity = 'error' | 'warn';
|
|
49
|
+
export type Problem = {
|
|
50
|
+
message: string;
|
|
51
|
+
suggest?: string[];
|
|
52
|
+
location?: Partial<LocationObject> | Array<Partial<LocationObject>>;
|
|
53
|
+
from?: LocationObject;
|
|
54
|
+
forceSeverity?: RuleSeverity;
|
|
55
|
+
ruleId?: string;
|
|
56
|
+
};
|
|
57
|
+
export type NormalizedProblem = {
|
|
58
|
+
message: string;
|
|
59
|
+
ruleId: string;
|
|
60
|
+
severity: ProblemSeverity;
|
|
61
|
+
location: LocationObject[];
|
|
62
|
+
from?: LocationObject;
|
|
63
|
+
suggest: string[];
|
|
64
|
+
ignored?: boolean;
|
|
65
|
+
};
|
|
66
|
+
export type WalkContext = {
|
|
67
|
+
problems: NormalizedProblem[];
|
|
68
|
+
oasVersion: SpecVersion;
|
|
69
|
+
visitorsData: Record<string, Record<string, unknown>>;
|
|
70
|
+
refTypes?: Map<string, NormalizedNodeType>;
|
|
71
|
+
};
|
|
72
|
+
export declare function walkDocument<T extends BaseVisitor>(opts: {
|
|
73
|
+
document: Document;
|
|
74
|
+
rootType: NormalizedNodeType;
|
|
75
|
+
normalizedVisitors: NormalizedOasVisitors<T>;
|
|
76
|
+
resolvedRefMap: ResolvedRefMap;
|
|
77
|
+
ctx: WalkContext;
|
|
78
|
+
}): void;
|