@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,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncApi3Types = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const asyncapi2_1 = require("./asyncapi2");
|
|
6
|
+
const Root = {
|
|
7
|
+
properties: {
|
|
8
|
+
asyncapi: { type: 'string', enum: ['3.0.0'] },
|
|
9
|
+
info: 'Info',
|
|
10
|
+
id: { type: 'string' },
|
|
11
|
+
servers: 'ServerMap',
|
|
12
|
+
channels: 'NamedChannels',
|
|
13
|
+
components: 'Components',
|
|
14
|
+
operations: 'NamedOperations',
|
|
15
|
+
defaultContentType: { type: 'string' },
|
|
16
|
+
},
|
|
17
|
+
required: ['asyncapi', 'info'],
|
|
18
|
+
};
|
|
19
|
+
const Channel = {
|
|
20
|
+
properties: {
|
|
21
|
+
address: { type: 'string' },
|
|
22
|
+
messages: 'NamedMessages',
|
|
23
|
+
title: { type: 'string' },
|
|
24
|
+
summary: { type: 'string' },
|
|
25
|
+
description: { type: 'string' },
|
|
26
|
+
servers: 'ServerList',
|
|
27
|
+
parameters: 'ParametersMap',
|
|
28
|
+
bindings: 'ChannelBindings',
|
|
29
|
+
tags: 'TagList',
|
|
30
|
+
externalDocs: 'ExternalDocs',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const Server = {
|
|
34
|
+
properties: {
|
|
35
|
+
host: { type: 'string' },
|
|
36
|
+
pathname: { type: 'string' },
|
|
37
|
+
protocol: { type: 'string' },
|
|
38
|
+
protocolVersion: { type: 'string' },
|
|
39
|
+
description: { type: 'string' },
|
|
40
|
+
variables: 'ServerVariablesMap',
|
|
41
|
+
security: 'SecuritySchemeList',
|
|
42
|
+
bindings: 'ServerBindings',
|
|
43
|
+
externalDocs: 'ExternalDocs',
|
|
44
|
+
tags: 'TagList',
|
|
45
|
+
},
|
|
46
|
+
required: ['host', 'protocol'],
|
|
47
|
+
};
|
|
48
|
+
const Info = {
|
|
49
|
+
properties: {
|
|
50
|
+
title: { type: 'string' },
|
|
51
|
+
version: { type: 'string' },
|
|
52
|
+
description: { type: 'string' },
|
|
53
|
+
termsOfService: { type: 'string' },
|
|
54
|
+
contact: 'Contact',
|
|
55
|
+
license: 'License',
|
|
56
|
+
tags: 'TagList',
|
|
57
|
+
externalDocs: 'ExternalDocs',
|
|
58
|
+
},
|
|
59
|
+
required: ['title', 'version'],
|
|
60
|
+
};
|
|
61
|
+
const Parameter = {
|
|
62
|
+
properties: {
|
|
63
|
+
description: { type: 'string' },
|
|
64
|
+
enum: { type: 'array', items: { type: 'string' } },
|
|
65
|
+
default: { type: 'string' },
|
|
66
|
+
examples: { type: 'array', items: { type: 'string' } },
|
|
67
|
+
location: { type: 'string' },
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const Message = {
|
|
71
|
+
properties: {
|
|
72
|
+
headers: 'Schema',
|
|
73
|
+
payload: (value) => {
|
|
74
|
+
if (!!value && value?.['schemaFormat']) {
|
|
75
|
+
return {
|
|
76
|
+
properties: {
|
|
77
|
+
schema: 'Schema',
|
|
78
|
+
schemaFormat: { type: 'string' },
|
|
79
|
+
},
|
|
80
|
+
required: ['schema', 'schemaFormat'],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return 'Schema';
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
correlationId: 'CorrelationId',
|
|
88
|
+
contentType: { type: 'string' },
|
|
89
|
+
name: { type: 'string' },
|
|
90
|
+
title: { type: 'string' },
|
|
91
|
+
summary: { type: 'string' },
|
|
92
|
+
description: { type: 'string' },
|
|
93
|
+
tags: 'TagList',
|
|
94
|
+
externalDocs: 'ExternalDocs',
|
|
95
|
+
bindings: 'MessageBindings',
|
|
96
|
+
examples: 'MessageExampleList',
|
|
97
|
+
traits: 'MessageTraitList',
|
|
98
|
+
},
|
|
99
|
+
additionalProperties: {},
|
|
100
|
+
};
|
|
101
|
+
const OperationTrait = {
|
|
102
|
+
properties: {
|
|
103
|
+
tags: 'TagList',
|
|
104
|
+
title: { type: 'string' },
|
|
105
|
+
summary: { type: 'string' },
|
|
106
|
+
description: { type: 'string' },
|
|
107
|
+
externalDocs: 'ExternalDocs',
|
|
108
|
+
security: 'SecuritySchemeList',
|
|
109
|
+
bindings: 'OperationBindings',
|
|
110
|
+
},
|
|
111
|
+
required: [],
|
|
112
|
+
};
|
|
113
|
+
const MessageTrait = {
|
|
114
|
+
properties: {
|
|
115
|
+
headers: (value) => {
|
|
116
|
+
if (typeof value === 'function' || (typeof value === 'object' && !!value)) {
|
|
117
|
+
return {
|
|
118
|
+
properties: {
|
|
119
|
+
schema: 'Schema',
|
|
120
|
+
schemaFormat: { type: 'string' },
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return 'Schema';
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
correlationId: 'CorrelationId',
|
|
129
|
+
contentType: { type: 'string' },
|
|
130
|
+
name: { type: 'string' },
|
|
131
|
+
title: { type: 'string' },
|
|
132
|
+
summary: { type: 'string' },
|
|
133
|
+
description: { type: 'string' },
|
|
134
|
+
tags: 'TagList',
|
|
135
|
+
externalDocs: 'ExternalDocs',
|
|
136
|
+
bindings: 'MessageBindings',
|
|
137
|
+
examples: 'MessageExampleList',
|
|
138
|
+
},
|
|
139
|
+
additionalProperties: {},
|
|
140
|
+
};
|
|
141
|
+
const Operation = {
|
|
142
|
+
properties: {
|
|
143
|
+
action: { type: 'string', enum: ['send', 'receive'] },
|
|
144
|
+
channel: 'Channel',
|
|
145
|
+
title: { type: 'string' },
|
|
146
|
+
tags: 'TagList',
|
|
147
|
+
summary: { type: 'string' },
|
|
148
|
+
description: { type: 'string' },
|
|
149
|
+
externalDocs: 'ExternalDocs',
|
|
150
|
+
operationId: { type: 'string' },
|
|
151
|
+
security: 'SecuritySchemeList',
|
|
152
|
+
bindings: 'OperationBindings',
|
|
153
|
+
traits: 'OperationTraitList',
|
|
154
|
+
messages: 'MessageList',
|
|
155
|
+
reply: 'OperationReply',
|
|
156
|
+
},
|
|
157
|
+
required: ['action', 'channel'],
|
|
158
|
+
};
|
|
159
|
+
const OperationReply = {
|
|
160
|
+
properties: {
|
|
161
|
+
channel: 'Channel',
|
|
162
|
+
messages: 'MessageList',
|
|
163
|
+
address: 'OperationReplyAddress',
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
const OperationReplyAddress = {
|
|
167
|
+
properties: {
|
|
168
|
+
location: { type: 'string' },
|
|
169
|
+
description: { type: 'string' },
|
|
170
|
+
},
|
|
171
|
+
required: ['location'],
|
|
172
|
+
};
|
|
173
|
+
const Components = {
|
|
174
|
+
properties: {
|
|
175
|
+
messages: 'NamedMessages',
|
|
176
|
+
parameters: 'NamedParameters',
|
|
177
|
+
schemas: 'NamedSchemas',
|
|
178
|
+
replies: 'NamedOperationReplies',
|
|
179
|
+
replyAddresses: 'NamedOperationRelyAddresses',
|
|
180
|
+
correlationIds: 'NamedCorrelationIds',
|
|
181
|
+
messageTraits: 'NamedMessageTraits',
|
|
182
|
+
operationTraits: 'NamedOperationTraits',
|
|
183
|
+
tags: 'NamedTags',
|
|
184
|
+
externalDocs: 'NamedExternalDocs',
|
|
185
|
+
securitySchemes: 'NamedSecuritySchemes',
|
|
186
|
+
servers: 'ServerMap',
|
|
187
|
+
serverVariables: 'ServerVariablesMap',
|
|
188
|
+
channels: 'NamedChannels',
|
|
189
|
+
operations: 'NamedOperations',
|
|
190
|
+
serverBindings: 'ServerBindings',
|
|
191
|
+
channelBindings: 'ChannelBindings',
|
|
192
|
+
operationBindings: 'OperationBindings',
|
|
193
|
+
messageBindings: 'MessageBindings',
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
const ImplicitFlow = {
|
|
197
|
+
properties: {
|
|
198
|
+
refreshUrl: { type: 'string' },
|
|
199
|
+
availableScopes: { type: 'object', additionalProperties: { type: 'string' } },
|
|
200
|
+
authorizationUrl: { type: 'string' },
|
|
201
|
+
},
|
|
202
|
+
required: ['authorizationUrl', 'availableScopes'],
|
|
203
|
+
};
|
|
204
|
+
const PasswordFlow = {
|
|
205
|
+
properties: {
|
|
206
|
+
refreshUrl: { type: 'string' },
|
|
207
|
+
availableScopes: { type: 'object', additionalProperties: { type: 'string' } },
|
|
208
|
+
tokenUrl: { type: 'string' },
|
|
209
|
+
},
|
|
210
|
+
required: ['tokenUrl', 'availableScopes'],
|
|
211
|
+
};
|
|
212
|
+
const ClientCredentials = {
|
|
213
|
+
properties: {
|
|
214
|
+
refreshUrl: { type: 'string' },
|
|
215
|
+
availableScopes: { type: 'object', additionalProperties: { type: 'string' } },
|
|
216
|
+
tokenUrl: { type: 'string' },
|
|
217
|
+
},
|
|
218
|
+
required: ['tokenUrl', 'availableScopes'],
|
|
219
|
+
};
|
|
220
|
+
const AuthorizationCode = {
|
|
221
|
+
properties: {
|
|
222
|
+
refreshUrl: { type: 'string' },
|
|
223
|
+
authorizationUrl: { type: 'string' },
|
|
224
|
+
availableScopes: { type: 'object', additionalProperties: { type: 'string' } },
|
|
225
|
+
tokenUrl: { type: 'string' },
|
|
226
|
+
},
|
|
227
|
+
required: ['authorizationUrl', 'tokenUrl', 'availableScopes'],
|
|
228
|
+
};
|
|
229
|
+
const SecurityScheme = {
|
|
230
|
+
properties: {
|
|
231
|
+
type: {
|
|
232
|
+
enum: [
|
|
233
|
+
'userPassword',
|
|
234
|
+
'apiKey',
|
|
235
|
+
'X509',
|
|
236
|
+
'symmetricEncryption',
|
|
237
|
+
'asymmetricEncryption',
|
|
238
|
+
'httpApiKey',
|
|
239
|
+
'http',
|
|
240
|
+
'oauth2',
|
|
241
|
+
'openIdConnect',
|
|
242
|
+
'plain',
|
|
243
|
+
'scramSha256',
|
|
244
|
+
'scramSha512',
|
|
245
|
+
'gssapi',
|
|
246
|
+
],
|
|
247
|
+
},
|
|
248
|
+
description: { type: 'string' },
|
|
249
|
+
name: { type: 'string' },
|
|
250
|
+
in: { type: 'string', enum: ['query', 'header', 'cookie', 'user', 'password'] },
|
|
251
|
+
scheme: { type: 'string' },
|
|
252
|
+
bearerFormat: { type: 'string' },
|
|
253
|
+
flows: 'SecuritySchemeFlows',
|
|
254
|
+
openIdConnectUrl: { type: 'string' },
|
|
255
|
+
scopes: { type: 'array', items: { type: 'string' } },
|
|
256
|
+
},
|
|
257
|
+
required(value) {
|
|
258
|
+
switch (value?.type) {
|
|
259
|
+
case 'apiKey':
|
|
260
|
+
return ['type', 'in'];
|
|
261
|
+
case 'httpApiKey':
|
|
262
|
+
return ['type', 'name', 'in'];
|
|
263
|
+
case 'http':
|
|
264
|
+
return ['type', 'scheme'];
|
|
265
|
+
case 'oauth2':
|
|
266
|
+
return ['type', 'flows'];
|
|
267
|
+
case 'openIdConnect':
|
|
268
|
+
return ['type', 'openIdConnectUrl'];
|
|
269
|
+
default:
|
|
270
|
+
return ['type'];
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
allowed(value) {
|
|
274
|
+
switch (value?.type) {
|
|
275
|
+
case 'apiKey':
|
|
276
|
+
return ['type', 'in', 'description'];
|
|
277
|
+
case 'httpApiKey':
|
|
278
|
+
return ['type', 'name', 'in', 'description'];
|
|
279
|
+
case 'http':
|
|
280
|
+
return ['type', 'scheme', 'bearerFormat', 'description'];
|
|
281
|
+
case 'oauth2':
|
|
282
|
+
return ['type', 'flows', 'description', 'scopes'];
|
|
283
|
+
case 'openIdConnect':
|
|
284
|
+
return ['type', 'openIdConnectUrl', 'description', 'scopes'];
|
|
285
|
+
default:
|
|
286
|
+
return ['type', 'description'];
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
extensionsPrefix: 'x-',
|
|
290
|
+
};
|
|
291
|
+
exports.AsyncApi3Types = {
|
|
292
|
+
// from asyncapi2
|
|
293
|
+
...asyncapi2_1.AsyncApi2Bindings,
|
|
294
|
+
CorrelationId: asyncapi2_1.CorrelationId,
|
|
295
|
+
SecuritySchemeFlows: asyncapi2_1.SecuritySchemeFlows,
|
|
296
|
+
ServerVariable: asyncapi2_1.ServerVariable,
|
|
297
|
+
Contact: asyncapi2_1.Contact,
|
|
298
|
+
License: asyncapi2_1.License,
|
|
299
|
+
MessageExample: asyncapi2_1.MessageExample,
|
|
300
|
+
Tag: asyncapi2_1.Tag,
|
|
301
|
+
Dependencies: asyncapi2_1.Dependencies,
|
|
302
|
+
Schema: asyncapi2_1.Schema,
|
|
303
|
+
Discriminator: asyncapi2_1.Discriminator,
|
|
304
|
+
DiscriminatorMapping: asyncapi2_1.DiscriminatorMapping,
|
|
305
|
+
SchemaProperties: asyncapi2_1.SchemaProperties,
|
|
306
|
+
ServerMap: asyncapi2_1.ServerMap,
|
|
307
|
+
ExternalDocs: asyncapi2_1.ExternalDocs,
|
|
308
|
+
Root,
|
|
309
|
+
Channel,
|
|
310
|
+
Parameter,
|
|
311
|
+
Info,
|
|
312
|
+
Server,
|
|
313
|
+
MessageTrait,
|
|
314
|
+
Operation,
|
|
315
|
+
OperationReply,
|
|
316
|
+
OperationReplyAddress,
|
|
317
|
+
Components,
|
|
318
|
+
ImplicitFlow,
|
|
319
|
+
PasswordFlow,
|
|
320
|
+
ClientCredentials,
|
|
321
|
+
AuthorizationCode,
|
|
322
|
+
SecurityScheme,
|
|
323
|
+
Message,
|
|
324
|
+
OperationTrait,
|
|
325
|
+
ServerVariablesMap: (0, _1.mapOf)('ServerVariable'),
|
|
326
|
+
NamedTags: (0, _1.mapOf)('Tag'),
|
|
327
|
+
NamedExternalDocs: (0, _1.mapOf)('ExternalDocs'),
|
|
328
|
+
NamedChannels: (0, _1.mapOf)('Channel'),
|
|
329
|
+
ParametersMap: (0, _1.mapOf)('Parameter'),
|
|
330
|
+
NamedOperations: (0, _1.mapOf)('Operation'),
|
|
331
|
+
NamedOperationReplies: (0, _1.mapOf)('OperationReply'),
|
|
332
|
+
NamedOperationRelyAddresses: (0, _1.mapOf)('OperationReplyAddress'),
|
|
333
|
+
NamedSchemas: (0, _1.mapOf)('Schema'),
|
|
334
|
+
NamedMessages: (0, _1.mapOf)('Message'),
|
|
335
|
+
NamedMessageTraits: (0, _1.mapOf)('MessageTrait'),
|
|
336
|
+
NamedOperationTraits: (0, _1.mapOf)('OperationTrait'),
|
|
337
|
+
NamedParameters: (0, _1.mapOf)('Parameter'),
|
|
338
|
+
NamedSecuritySchemes: (0, _1.mapOf)('SecurityScheme'),
|
|
339
|
+
NamedCorrelationIds: (0, _1.mapOf)('CorrelationId'),
|
|
340
|
+
ServerList: (0, _1.listOf)('Server'),
|
|
341
|
+
SecuritySchemeList: (0, _1.listOf)('SecurityScheme'),
|
|
342
|
+
MessageList: (0, _1.listOf)('Message'),
|
|
343
|
+
OperationTraitList: (0, _1.listOf)('OperationTrait'),
|
|
344
|
+
MessageTraitList: (0, _1.listOf)('MessageTrait'),
|
|
345
|
+
MessageExampleList: (0, _1.listOf)('MessageExample'),
|
|
346
|
+
TagList: (0, _1.listOf)('Tag'),
|
|
347
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type ScalarSchema = {
|
|
2
|
+
name?: never;
|
|
3
|
+
type?: 'string' | 'boolean' | 'number' | 'integer' | 'object' | 'array';
|
|
4
|
+
items?: ScalarSchema;
|
|
5
|
+
enum?: string[];
|
|
6
|
+
isExample?: boolean;
|
|
7
|
+
directResolveAs?: string;
|
|
8
|
+
minimum?: number;
|
|
9
|
+
};
|
|
10
|
+
export type NormalizedScalarSchema = {
|
|
11
|
+
name?: never;
|
|
12
|
+
type?: 'string' | 'boolean' | 'number' | 'integer' | 'object' | 'array';
|
|
13
|
+
items?: ScalarSchema;
|
|
14
|
+
enum?: string[];
|
|
15
|
+
directResolveAs?: NormalizedNodeType;
|
|
16
|
+
resolvable: boolean;
|
|
17
|
+
minimum?: number;
|
|
18
|
+
};
|
|
19
|
+
export type NodeType = {
|
|
20
|
+
properties: Record<string, PropType | ResolveTypeFn>;
|
|
21
|
+
additionalProperties?: PropType | ResolveTypeFn;
|
|
22
|
+
items?: PropType | ResolveTypeFn;
|
|
23
|
+
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
24
|
+
requiredOneOf?: string[];
|
|
25
|
+
allowed?: (value: any) => string[] | undefined;
|
|
26
|
+
extensionsPrefix?: string;
|
|
27
|
+
};
|
|
28
|
+
export type PropType = string | NodeType | ScalarSchema | undefined | null;
|
|
29
|
+
export type ResolveTypeFn = (value: any, key: string) => string | PropType;
|
|
30
|
+
export type NormalizedNodeType = {
|
|
31
|
+
name: string;
|
|
32
|
+
properties: Record<string, NormalizedPropType | NormalizedResolveTypeFn>;
|
|
33
|
+
additionalProperties?: NormalizedPropType | NormalizedResolveTypeFn;
|
|
34
|
+
items?: NormalizedPropType | NormalizedResolveTypeFn;
|
|
35
|
+
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
36
|
+
requiredOneOf?: string[];
|
|
37
|
+
allowed?: (value: any) => string[] | undefined;
|
|
38
|
+
extensionsPrefix?: string;
|
|
39
|
+
};
|
|
40
|
+
type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | null | undefined;
|
|
41
|
+
type NormalizedResolveTypeFn = (value: any, key: string) => NormalizedPropType;
|
|
42
|
+
export declare function listOf(typeName: string): {
|
|
43
|
+
name: string;
|
|
44
|
+
properties: {};
|
|
45
|
+
items: string;
|
|
46
|
+
};
|
|
47
|
+
export declare function mapOf(typeName: string): {
|
|
48
|
+
name: string;
|
|
49
|
+
properties: {};
|
|
50
|
+
additionalProperties: () => string;
|
|
51
|
+
};
|
|
52
|
+
export declare const SpecExtension: NormalizedNodeType;
|
|
53
|
+
export declare function normalizeTypes(types: Record<string, NodeType>, options?: {
|
|
54
|
+
doNotResolveExamples?: boolean;
|
|
55
|
+
}): Record<string, NormalizedNodeType>;
|
|
56
|
+
export declare function isNamedType(t: NormalizedPropType): t is NormalizedNodeType;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpecExtension = void 0;
|
|
4
|
+
exports.listOf = listOf;
|
|
5
|
+
exports.mapOf = mapOf;
|
|
6
|
+
exports.normalizeTypes = normalizeTypes;
|
|
7
|
+
exports.isNamedType = isNamedType;
|
|
8
|
+
function listOf(typeName) {
|
|
9
|
+
return {
|
|
10
|
+
name: `${typeName}List`,
|
|
11
|
+
properties: {},
|
|
12
|
+
items: typeName,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function mapOf(typeName) {
|
|
16
|
+
return {
|
|
17
|
+
name: `${typeName}Map`,
|
|
18
|
+
properties: {},
|
|
19
|
+
additionalProperties: () => typeName,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.SpecExtension = {
|
|
23
|
+
name: 'SpecExtension',
|
|
24
|
+
properties: {},
|
|
25
|
+
// skip validation of additional properties for unknown extensions
|
|
26
|
+
additionalProperties: { resolvable: true },
|
|
27
|
+
};
|
|
28
|
+
function normalizeTypes(types, options = {}) {
|
|
29
|
+
const normalizedTypes = {};
|
|
30
|
+
for (const typeName of Object.keys(types)) {
|
|
31
|
+
normalizedTypes[typeName] = {
|
|
32
|
+
...types[typeName],
|
|
33
|
+
name: typeName,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
for (const type of Object.values(normalizedTypes)) {
|
|
37
|
+
normalizeType(type);
|
|
38
|
+
}
|
|
39
|
+
// all type trees have a SpecExtension type by default
|
|
40
|
+
normalizedTypes['SpecExtension'] = exports.SpecExtension;
|
|
41
|
+
return normalizedTypes;
|
|
42
|
+
function normalizeType(type) {
|
|
43
|
+
if (type.additionalProperties) {
|
|
44
|
+
type.additionalProperties = resolveType(type.additionalProperties);
|
|
45
|
+
}
|
|
46
|
+
if (type.items) {
|
|
47
|
+
type.items = resolveType(type.items);
|
|
48
|
+
}
|
|
49
|
+
if (type.properties) {
|
|
50
|
+
const mappedProps = {};
|
|
51
|
+
for (const [propName, prop] of Object.entries(type.properties)) {
|
|
52
|
+
mappedProps[propName] = resolveType(prop);
|
|
53
|
+
if (options.doNotResolveExamples && prop && prop.isExample) {
|
|
54
|
+
mappedProps[propName] = {
|
|
55
|
+
...prop,
|
|
56
|
+
resolvable: false,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
type.properties = mappedProps;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// typings are painful here...
|
|
64
|
+
function resolveType(type) {
|
|
65
|
+
if (typeof type === 'string') {
|
|
66
|
+
if (!normalizedTypes[type]) {
|
|
67
|
+
throw new Error(`Unknown type name found: ${type}`);
|
|
68
|
+
}
|
|
69
|
+
return normalizedTypes[type];
|
|
70
|
+
}
|
|
71
|
+
else if (typeof type === 'function') {
|
|
72
|
+
return (value, key) => {
|
|
73
|
+
return resolveType(type(value, key));
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
else if (type && type.name) {
|
|
77
|
+
type = { ...type };
|
|
78
|
+
normalizeType(type);
|
|
79
|
+
return type;
|
|
80
|
+
}
|
|
81
|
+
else if (type && type.directResolveAs) {
|
|
82
|
+
return {
|
|
83
|
+
...type,
|
|
84
|
+
directResolveAs: resolveType(type.directResolveAs),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return type;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function isNamedType(t) {
|
|
93
|
+
return typeof t?.name === 'string';
|
|
94
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// For internal usage only
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getNodeTypesFromJSONSchema = getNodeTypesFromJSONSchema;
|
|
5
|
+
const _2020_1 = require("@redocly/ajv/dist/2020");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const ajv = new _2020_1.default({
|
|
8
|
+
strictSchema: false,
|
|
9
|
+
allowUnionTypes: true,
|
|
10
|
+
useDefaults: true,
|
|
11
|
+
allErrors: true,
|
|
12
|
+
discriminator: true,
|
|
13
|
+
strictTypes: false,
|
|
14
|
+
verbose: true,
|
|
15
|
+
});
|
|
16
|
+
function findOneOf(schemaOneOf, oneOfs) {
|
|
17
|
+
if (oneOfs.some((option) => typeof option === 'function')) {
|
|
18
|
+
throw new Error('Unexpected oneOf inside oneOf.');
|
|
19
|
+
}
|
|
20
|
+
return (value) => {
|
|
21
|
+
let index = schemaOneOf.findIndex((option) => ajv.validate(option, value));
|
|
22
|
+
if (index === -1) {
|
|
23
|
+
index = 0;
|
|
24
|
+
}
|
|
25
|
+
return oneOfs[index];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function transformJSONSchemaToNodeType(propertyName, schema, ctx) {
|
|
29
|
+
if (!schema || typeof schema === 'boolean') {
|
|
30
|
+
throw new Error(`Unexpected schema in ${propertyName}.`);
|
|
31
|
+
}
|
|
32
|
+
if (schema instanceof Array) {
|
|
33
|
+
throw new Error(`Unexpected array schema in ${propertyName}. Try using oneOf instead.`);
|
|
34
|
+
}
|
|
35
|
+
if (schema.type === 'null') {
|
|
36
|
+
throw new Error(`Unexpected null schema type in ${propertyName} schema.`);
|
|
37
|
+
}
|
|
38
|
+
if (schema.type instanceof Array) {
|
|
39
|
+
throw new Error(`Unexpected array schema type in ${propertyName} schema. Try using oneOf instead.`);
|
|
40
|
+
}
|
|
41
|
+
if (schema.type === 'string' ||
|
|
42
|
+
schema.type === 'number' ||
|
|
43
|
+
schema.type === 'integer' ||
|
|
44
|
+
schema.type === 'boolean') {
|
|
45
|
+
const { default: _, format: _format, ...rest } = schema;
|
|
46
|
+
return rest;
|
|
47
|
+
}
|
|
48
|
+
if (schema.type === 'object' && !schema.properties && !schema.oneOf) {
|
|
49
|
+
if (schema.additionalProperties === undefined || schema.additionalProperties === true) {
|
|
50
|
+
return { type: 'object' };
|
|
51
|
+
}
|
|
52
|
+
else if (schema.additionalProperties === false) {
|
|
53
|
+
return { type: 'object', properties: {} };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (schema.allOf) {
|
|
57
|
+
throw new Error(`Unexpected allOf in ${propertyName}.`);
|
|
58
|
+
}
|
|
59
|
+
if (schema.anyOf) {
|
|
60
|
+
throw new Error(`Unexpected anyOf in ${propertyName}.`);
|
|
61
|
+
}
|
|
62
|
+
if ((0, utils_1.isPlainObject)(schema.properties) ||
|
|
63
|
+
(0, utils_1.isPlainObject)(schema.additionalProperties) ||
|
|
64
|
+
((0, utils_1.isPlainObject)(schema.items) &&
|
|
65
|
+
((0, utils_1.isPlainObject)(schema.items.properties) ||
|
|
66
|
+
(0, utils_1.isPlainObject)(schema.items.additionalProperties) ||
|
|
67
|
+
schema.items.oneOf)) // exclude scalar array types
|
|
68
|
+
) {
|
|
69
|
+
return extractNodeToContext(propertyName, schema, ctx);
|
|
70
|
+
}
|
|
71
|
+
if (schema.oneOf) {
|
|
72
|
+
if (schema.discriminator) {
|
|
73
|
+
const discriminatedPropertyName = schema.discriminator?.propertyName;
|
|
74
|
+
if (!discriminatedPropertyName) {
|
|
75
|
+
throw new Error(`Unexpected discriminator without a propertyName in ${propertyName}.`);
|
|
76
|
+
}
|
|
77
|
+
const oneOfs = schema.oneOf.map((option, i) => {
|
|
78
|
+
if (typeof option === 'boolean') {
|
|
79
|
+
throw new Error(`Unexpected boolean schema in ${propertyName} at position ${i} in oneOf.`);
|
|
80
|
+
}
|
|
81
|
+
const discriminatedProperty = option?.properties?.[discriminatedPropertyName];
|
|
82
|
+
if (!discriminatedProperty || typeof discriminatedProperty === 'boolean') {
|
|
83
|
+
throw new Error(`Unexpected property '${discriminatedProperty}' schema in ${propertyName} at position ${i} in oneOf.`);
|
|
84
|
+
}
|
|
85
|
+
const name = discriminatedProperty.const;
|
|
86
|
+
return transformJSONSchemaToNodeType(name, option, ctx);
|
|
87
|
+
});
|
|
88
|
+
return (value, key) => {
|
|
89
|
+
if ((0, utils_1.isPlainObject)(value)) {
|
|
90
|
+
const discriminatedTypeName = value[discriminatedPropertyName];
|
|
91
|
+
if (typeof discriminatedTypeName === 'string' && ctx[discriminatedTypeName]) {
|
|
92
|
+
return discriminatedTypeName;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return findOneOf(schema.oneOf, oneOfs)(value, key);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const oneOfs = schema.oneOf.map((option, i) => transformJSONSchemaToNodeType(propertyName + '_' + i, option, ctx));
|
|
100
|
+
return findOneOf(schema.oneOf, oneOfs);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return schema;
|
|
104
|
+
}
|
|
105
|
+
function extractNodeToContext(propertyName, schema, ctx) {
|
|
106
|
+
if (!schema || typeof schema === 'boolean') {
|
|
107
|
+
throw new Error(`Unexpected schema in ${propertyName}.`);
|
|
108
|
+
}
|
|
109
|
+
if (schema instanceof Array) {
|
|
110
|
+
throw new Error(`Unexpected array schema in ${propertyName}. Try using oneOf instead.`);
|
|
111
|
+
}
|
|
112
|
+
if (schema.type === 'null') {
|
|
113
|
+
throw new Error(`Unexpected null schema type in ${propertyName} schema.`);
|
|
114
|
+
}
|
|
115
|
+
if (schema.type instanceof Array) {
|
|
116
|
+
throw new Error(`Unexpected array schema type in ${propertyName} schema. Try using oneOf instead.`);
|
|
117
|
+
}
|
|
118
|
+
const properties = {};
|
|
119
|
+
for (const [name, property] of Object.entries(schema.properties || {})) {
|
|
120
|
+
properties[name] = transformJSONSchemaToNodeType(propertyName + '.' + name, property, ctx);
|
|
121
|
+
}
|
|
122
|
+
let additionalProperties;
|
|
123
|
+
if ((0, utils_1.isPlainObject)(schema.additionalProperties)) {
|
|
124
|
+
additionalProperties = transformJSONSchemaToNodeType(propertyName + '_additionalProperties', schema.additionalProperties, ctx);
|
|
125
|
+
}
|
|
126
|
+
if (schema.additionalProperties === true) {
|
|
127
|
+
additionalProperties = {};
|
|
128
|
+
}
|
|
129
|
+
let items;
|
|
130
|
+
if ((0, utils_1.isPlainObject)(schema.items) &&
|
|
131
|
+
((0, utils_1.isPlainObject)(schema.items.properties) ||
|
|
132
|
+
(0, utils_1.isPlainObject)(schema.items.additionalProperties) ||
|
|
133
|
+
schema.items.oneOf) // exclude scalar array types
|
|
134
|
+
) {
|
|
135
|
+
items = transformJSONSchemaToNodeType(propertyName + '_items', schema.items, ctx);
|
|
136
|
+
}
|
|
137
|
+
let required = schema.required;
|
|
138
|
+
// Translate required in oneOfs into a ResolveTypeFn.
|
|
139
|
+
if (schema.oneOf && schema.oneOf.every((option) => !!option.required)) {
|
|
140
|
+
required = (value) => {
|
|
141
|
+
const requiredList = schema.oneOf.map((option) => [
|
|
142
|
+
...(schema.required || []),
|
|
143
|
+
...option.required,
|
|
144
|
+
]);
|
|
145
|
+
let index = requiredList.findIndex((r) => r.every((requiredProp) => value[requiredProp] !== undefined));
|
|
146
|
+
if (index === -1) {
|
|
147
|
+
index = 0;
|
|
148
|
+
}
|
|
149
|
+
return requiredList[index];
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
ctx[propertyName] = { properties, additionalProperties, items, required };
|
|
153
|
+
return propertyName;
|
|
154
|
+
}
|
|
155
|
+
function getNodeTypesFromJSONSchema(schemaName, entrySchema) {
|
|
156
|
+
const ctx = {};
|
|
157
|
+
transformJSONSchemaToNodeType(schemaName, entrySchema, ctx);
|
|
158
|
+
return ctx;
|
|
159
|
+
}
|