@redocly/openapi-core 1.0.0 → 1.0.1
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/CHANGELOG.md +7 -0
- package/__tests__/utils.ts +88 -0
- package/lib/config/all.js +0 -1
- package/lib/config/minimal.js +0 -1
- package/lib/config/recommended.js +0 -1
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/bundle.test.ts.snap +437 -0
- package/src/__tests__/bundle.test.ts +236 -0
- package/src/__tests__/codeframes.test.ts +530 -0
- package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +5 -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__/format.test.ts +76 -0
- package/src/__tests__/js-yaml.test.ts +73 -0
- package/src/__tests__/lint.test.ts +392 -0
- package/src/__tests__/logger-browser.test.ts +53 -0
- package/src/__tests__/logger.test.ts +47 -0
- package/src/__tests__/login.test.ts +17 -0
- package/src/__tests__/normalizeVisitors.test.ts +151 -0
- package/src/__tests__/output-browser.test.ts +18 -0
- package/src/__tests__/output.test.ts +15 -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 +431 -0
- package/src/__tests__/utils-browser.test.ts +11 -0
- package/src/__tests__/utils.test.ts +144 -0
- package/src/__tests__/walk.test.ts +1545 -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 +35 -0
- package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +32 -0
- package/src/benchmark/benches/rebilly.yaml +32275 -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 +311 -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 +417 -0
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +164 -0
- package/src/config/__tests__/__snapshots__/config.test.ts.snap +144 -0
- package/src/config/__tests__/config-resolvers.test.ts +491 -0
- package/src/config/__tests__/config.test.ts +312 -0
- package/src/config/__tests__/fixtures/ingore-file.ts +8 -0
- package/src/config/__tests__/fixtures/load-redocly.yaml +2 -0
- package/src/config/__tests__/fixtures/plugin-config.yaml +2 -0
- package/src/config/__tests__/fixtures/plugin.js +56 -0
- package/src/config/__tests__/fixtures/resolve-config/api/nested-config.yaml +11 -0
- package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +69 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-circular.yaml +7 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-custom-function.yaml +17 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-file.yaml +18 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config-with-wrong-custom-function.yaml +15 -0
- package/src/config/__tests__/fixtures/resolve-config/local-config.yaml +9 -0
- package/src/config/__tests__/fixtures/resolve-config/plugin.js +80 -0
- package/src/config/__tests__/fixtures/resolve-remote-configs/nested-remote-config.yaml +3 -0
- package/src/config/__tests__/fixtures/resolve-remote-configs/remote-config.yaml +4 -0
- package/src/config/__tests__/load.test.ts +167 -0
- package/src/config/__tests__/resolve-plugins.test.ts +27 -0
- package/src/config/__tests__/utils.test.ts +204 -0
- package/src/config/all.ts +74 -0
- package/src/config/builtIn.ts +37 -0
- package/src/config/config-resolvers.ts +474 -0
- package/src/config/config.ts +332 -0
- package/src/config/index.ts +7 -0
- package/src/config/load.ts +144 -0
- package/src/config/minimal.ts +61 -0
- package/src/config/recommended.ts +61 -0
- package/src/config/rules.ts +54 -0
- package/src/config/types.ts +231 -0
- package/src/config/utils.ts +349 -0
- package/src/decorators/__tests__/filter-in.test.ts +310 -0
- package/src/decorators/__tests__/filter-out.test.ts +335 -0
- package/src/decorators/__tests__/media-type-examples-override.test.ts +665 -0
- package/src/decorators/__tests__/remove-x-internal.test.ts +316 -0
- package/src/decorators/__tests__/resources/request.yaml +3 -0
- package/src/decorators/__tests__/resources/response.yaml +3 -0
- package/src/decorators/common/filters/filter-helper.ts +72 -0
- package/src/decorators/common/filters/filter-in.ts +18 -0
- package/src/decorators/common/filters/filter-out.ts +18 -0
- package/src/decorators/common/info-description-override.ts +24 -0
- package/src/decorators/common/info-override.ts +15 -0
- package/src/decorators/common/media-type-examples-override.ts +79 -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 +20 -0
- package/src/decorators/oas3/index.ts +22 -0
- package/src/env.ts +5 -0
- package/src/format/codeframes.ts +216 -0
- package/src/format/format.ts +375 -0
- package/src/index.ts +71 -0
- package/src/js-yaml/index.ts +14 -0
- package/src/lint.ts +148 -0
- package/src/logger.ts +34 -0
- package/src/oas-types.ts +57 -0
- package/src/output.ts +7 -0
- package/src/redocly/__tests__/redocly-client.test.ts +146 -0
- package/src/redocly/index.ts +187 -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 +150 -0
- package/src/ref-utils.ts +85 -0
- package/src/resolve.ts +417 -0
- package/src/rules/__tests__/fixtures/code-sample.php +9 -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 +257 -0
- package/src/rules/__tests__/utils.test.ts +160 -0
- package/src/rules/ajv.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 +210 -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 +192 -0
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +231 -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-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 +202 -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__/security-defined.test.ts +175 -0
- package/src/rules/common/__tests__/spec-strict-refs.test.ts +69 -0
- package/src/rules/common/__tests__/spec.test.ts +610 -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 +869 -0
- package/src/rules/common/assertions/__tests__/index.test.ts +100 -0
- package/src/rules/common/assertions/__tests__/utils.test.ts +236 -0
- package/src/rules/common/assertions/asserts.ts +357 -0
- package/src/rules/common/assertions/index.ts +53 -0
- package/src/rules/common/assertions/utils.ts +331 -0
- package/src/rules/common/info-contact.ts +15 -0
- package/src/rules/common/info-license-url.ts +10 -0
- package/src/rules/common/info-license.ts +15 -0
- package/src/rules/common/no-ambiguous-paths.ts +50 -0
- package/src/rules/common/no-enum-type-mismatch.ts +52 -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 +24 -0
- package/src/rules/common/operation-4xx-response.ts +24 -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-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 +65 -0
- package/src/rules/common/path-segment-plural.ts +31 -0
- package/src/rules/common/paths-kebab-case.ts +19 -0
- package/src/rules/common/required-string-property-missing-min-length.ts +44 -0
- package/src/rules/common/response-contains-header.ts +35 -0
- package/src/rules/common/scalar-property-missing-example.ts +58 -0
- package/src/rules/common/security-defined.ts +65 -0
- package/src/rules/common/spec-strict-refs.ts +30 -0
- package/src/rules/common/spec.ts +175 -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 +35 -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 +91 -0
- package/src/rules/oas2/remove-unused-components.ts +81 -0
- package/src/rules/oas2/request-mime-type.ts +16 -0
- package/src/rules/oas2/response-contains-property.ts +36 -0
- package/src/rules/oas2/response-mime-type.ts +16 -0
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +111 -0
- package/src/rules/oas3/__tests__/component-name-unique.test.ts +823 -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 +473 -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__/operation-4xx-problem-details-rfc7807.test.ts +145 -0
- package/src/rules/oas3/__tests__/response-contains-header.test.ts +389 -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 +505 -0
- package/src/rules/oas3/__tests__/spec/spec.test.ts +298 -0
- package/src/rules/oas3/__tests__/spec/utils.ts +32 -0
- package/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts +276 -0
- package/src/rules/oas3/__tests__/utils/lint-document-for-test.ts +23 -0
- package/src/rules/oas3/boolean-parameter-prefixes.ts +28 -0
- package/src/rules/oas3/component-name-unique.ts +158 -0
- package/src/rules/oas3/index.ts +113 -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 +49 -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-server-variables-empty-enum.ts +66 -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/operation-4xx-problem-details-rfc7807.ts +35 -0
- package/src/rules/oas3/remove-unused-components.ts +95 -0
- package/src/rules/oas3/request-mime-type.ts +30 -0
- package/src/rules/oas3/response-contains-property.ts +38 -0
- package/src/rules/oas3/response-mime-type.ts +30 -0
- package/src/rules/oas3/spec-components-invalid-map-name.ts +69 -0
- package/src/rules/other/stats.ts +73 -0
- package/src/rules/utils.ts +193 -0
- package/src/types/config-external-schemas.ts +917 -0
- package/src/types/index.ts +149 -0
- package/src/types/oas2.ts +478 -0
- package/src/types/oas3.ts +597 -0
- package/src/types/oas3_1.ts +258 -0
- package/src/types/redocly-yaml.ts +1040 -0
- package/src/typings/common.ts +17 -0
- package/src/typings/openapi.ts +298 -0
- package/src/typings/swagger.ts +236 -0
- package/src/utils.ts +276 -0
- package/src/visitors.ts +491 -0
- package/src/walk.ts +439 -0
- package/tsconfig.json +8 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import { NodeType, listOf, mapOf } from '.';
|
|
2
|
+
import { isMappingRef } from '../ref-utils';
|
|
3
|
+
const responseCodeRegexp = /^[0-9][0-9Xx]{2}$/;
|
|
4
|
+
|
|
5
|
+
const Root: NodeType = {
|
|
6
|
+
properties: {
|
|
7
|
+
openapi: null,
|
|
8
|
+
info: 'Info',
|
|
9
|
+
servers: 'ServerList',
|
|
10
|
+
security: 'SecurityRequirementList',
|
|
11
|
+
tags: 'TagList',
|
|
12
|
+
externalDocs: 'ExternalDocs',
|
|
13
|
+
paths: 'Paths',
|
|
14
|
+
components: 'Components',
|
|
15
|
+
'x-webhooks': 'WebhooksMap',
|
|
16
|
+
'x-tagGroups': 'TagGroups',
|
|
17
|
+
'x-ignoredHeaderParameters': { type: 'array', items: { type: 'string' } },
|
|
18
|
+
},
|
|
19
|
+
required: ['openapi', 'paths', 'info'],
|
|
20
|
+
extensionsPrefix: 'x-',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const Tag: NodeType = {
|
|
24
|
+
properties: {
|
|
25
|
+
name: { type: 'string' },
|
|
26
|
+
description: { type: 'string' },
|
|
27
|
+
externalDocs: 'ExternalDocs',
|
|
28
|
+
'x-traitTag': { type: 'boolean' },
|
|
29
|
+
'x-displayName': { type: 'string' },
|
|
30
|
+
},
|
|
31
|
+
required: ['name'],
|
|
32
|
+
extensionsPrefix: 'x-',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const TagGroup: NodeType = {
|
|
36
|
+
properties: {
|
|
37
|
+
name: { type: 'string' },
|
|
38
|
+
tags: { type: 'array', items: { type: 'string' } },
|
|
39
|
+
},
|
|
40
|
+
extensionsPrefix: 'x-',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const ExternalDocs: NodeType = {
|
|
44
|
+
properties: {
|
|
45
|
+
description: { type: 'string' },
|
|
46
|
+
url: { type: 'string' },
|
|
47
|
+
},
|
|
48
|
+
required: ['url'],
|
|
49
|
+
extensionsPrefix: 'x-',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const Server: NodeType = {
|
|
53
|
+
properties: {
|
|
54
|
+
url: { type: 'string' },
|
|
55
|
+
description: { type: 'string' },
|
|
56
|
+
variables: 'ServerVariablesMap',
|
|
57
|
+
},
|
|
58
|
+
required: ['url'],
|
|
59
|
+
extensionsPrefix: 'x-',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const ServerVariable: NodeType = {
|
|
63
|
+
properties: {
|
|
64
|
+
enum: {
|
|
65
|
+
type: 'array',
|
|
66
|
+
items: { type: 'string' },
|
|
67
|
+
},
|
|
68
|
+
default: { type: 'string' },
|
|
69
|
+
description: { type: 'string' },
|
|
70
|
+
},
|
|
71
|
+
required: ['default'],
|
|
72
|
+
extensionsPrefix: 'x-',
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const SecurityRequirement: NodeType = {
|
|
76
|
+
properties: {},
|
|
77
|
+
additionalProperties: { type: 'array', items: { type: 'string' } },
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const Info: NodeType = {
|
|
81
|
+
properties: {
|
|
82
|
+
title: { type: 'string' },
|
|
83
|
+
version: { type: 'string' },
|
|
84
|
+
description: { type: 'string' },
|
|
85
|
+
termsOfService: { type: 'string' },
|
|
86
|
+
contact: 'Contact',
|
|
87
|
+
license: 'License',
|
|
88
|
+
'x-logo': 'Logo',
|
|
89
|
+
},
|
|
90
|
+
required: ['title', 'version'],
|
|
91
|
+
extensionsPrefix: 'x-',
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const Logo: NodeType = {
|
|
95
|
+
properties: {
|
|
96
|
+
url: { type: 'string' },
|
|
97
|
+
altText: { type: 'string' },
|
|
98
|
+
backgroundColor: { type: 'string' },
|
|
99
|
+
href: { type: 'string' },
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const Contact: NodeType = {
|
|
104
|
+
properties: {
|
|
105
|
+
name: { type: 'string' },
|
|
106
|
+
url: { type: 'string' },
|
|
107
|
+
email: { type: 'string' },
|
|
108
|
+
},
|
|
109
|
+
extensionsPrefix: 'x-',
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const License: NodeType = {
|
|
113
|
+
properties: {
|
|
114
|
+
name: { type: 'string' },
|
|
115
|
+
url: { type: 'string' },
|
|
116
|
+
},
|
|
117
|
+
required: ['name'],
|
|
118
|
+
extensionsPrefix: 'x-',
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const Paths: NodeType = {
|
|
122
|
+
properties: {},
|
|
123
|
+
additionalProperties: (_value: any, key: string) =>
|
|
124
|
+
key.startsWith('/') ? 'PathItem' : undefined,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const WebhooksMap: NodeType = {
|
|
128
|
+
properties: {},
|
|
129
|
+
additionalProperties: () => 'PathItem',
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const PathItem: NodeType = {
|
|
133
|
+
properties: {
|
|
134
|
+
$ref: { type: 'string' }, // TODO: verify special $ref handling for Path Item
|
|
135
|
+
servers: 'ServerList',
|
|
136
|
+
parameters: 'ParameterList',
|
|
137
|
+
summary: { type: 'string' },
|
|
138
|
+
description: { type: 'string' },
|
|
139
|
+
get: 'Operation',
|
|
140
|
+
put: 'Operation',
|
|
141
|
+
post: 'Operation',
|
|
142
|
+
delete: 'Operation',
|
|
143
|
+
options: 'Operation',
|
|
144
|
+
head: 'Operation',
|
|
145
|
+
patch: 'Operation',
|
|
146
|
+
trace: 'Operation',
|
|
147
|
+
},
|
|
148
|
+
extensionsPrefix: 'x-',
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const Parameter: NodeType = {
|
|
152
|
+
properties: {
|
|
153
|
+
name: { type: 'string' },
|
|
154
|
+
in: { enum: ['query', 'header', 'path', 'cookie'] },
|
|
155
|
+
description: { type: 'string' },
|
|
156
|
+
required: { type: 'boolean' },
|
|
157
|
+
deprecated: { type: 'boolean' },
|
|
158
|
+
allowEmptyValue: { type: 'boolean' },
|
|
159
|
+
style: {
|
|
160
|
+
enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
|
|
161
|
+
},
|
|
162
|
+
explode: { type: 'boolean' },
|
|
163
|
+
allowReserved: { type: 'boolean' },
|
|
164
|
+
schema: 'Schema',
|
|
165
|
+
example: { isExample: true },
|
|
166
|
+
examples: 'ExamplesMap',
|
|
167
|
+
content: 'MediaTypesMap',
|
|
168
|
+
},
|
|
169
|
+
required: ['name', 'in'],
|
|
170
|
+
requiredOneOf: ['schema', 'content'],
|
|
171
|
+
extensionsPrefix: 'x-',
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const Operation: NodeType = {
|
|
175
|
+
properties: {
|
|
176
|
+
tags: {
|
|
177
|
+
type: 'array',
|
|
178
|
+
items: { type: 'string' },
|
|
179
|
+
},
|
|
180
|
+
summary: { type: 'string' },
|
|
181
|
+
description: { type: 'string' },
|
|
182
|
+
externalDocs: 'ExternalDocs',
|
|
183
|
+
operationId: { type: 'string' },
|
|
184
|
+
parameters: 'ParameterList',
|
|
185
|
+
security: 'SecurityRequirementList',
|
|
186
|
+
servers: 'ServerList',
|
|
187
|
+
requestBody: 'RequestBody',
|
|
188
|
+
responses: 'Responses',
|
|
189
|
+
deprecated: { type: 'boolean' },
|
|
190
|
+
callbacks: 'CallbacksMap',
|
|
191
|
+
'x-codeSamples': 'XCodeSampleList',
|
|
192
|
+
'x-code-samples': 'XCodeSampleList', // deprecated
|
|
193
|
+
'x-hideTryItPanel': { type: 'boolean' },
|
|
194
|
+
},
|
|
195
|
+
required: ['responses'],
|
|
196
|
+
extensionsPrefix: 'x-',
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const XCodeSample: NodeType = {
|
|
200
|
+
properties: {
|
|
201
|
+
lang: { type: 'string' },
|
|
202
|
+
label: { type: 'string' },
|
|
203
|
+
source: { type: 'string' },
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const RequestBody: NodeType = {
|
|
208
|
+
properties: {
|
|
209
|
+
description: { type: 'string' },
|
|
210
|
+
required: { type: 'boolean' },
|
|
211
|
+
content: 'MediaTypesMap',
|
|
212
|
+
},
|
|
213
|
+
required: ['content'],
|
|
214
|
+
extensionsPrefix: 'x-',
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const MediaTypesMap: NodeType = {
|
|
218
|
+
properties: {},
|
|
219
|
+
additionalProperties: 'MediaType',
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const MediaType: NodeType = {
|
|
223
|
+
properties: {
|
|
224
|
+
schema: 'Schema',
|
|
225
|
+
example: { isExample: true },
|
|
226
|
+
examples: 'ExamplesMap',
|
|
227
|
+
encoding: 'EncodingMap',
|
|
228
|
+
},
|
|
229
|
+
extensionsPrefix: 'x-',
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const Example: NodeType = {
|
|
233
|
+
properties: {
|
|
234
|
+
value: { isExample: true },
|
|
235
|
+
summary: { type: 'string' },
|
|
236
|
+
description: { type: 'string' },
|
|
237
|
+
externalValue: { type: 'string' },
|
|
238
|
+
},
|
|
239
|
+
extensionsPrefix: 'x-',
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const Encoding: NodeType = {
|
|
243
|
+
properties: {
|
|
244
|
+
contentType: { type: 'string' },
|
|
245
|
+
headers: 'HeadersMap',
|
|
246
|
+
style: {
|
|
247
|
+
enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
|
|
248
|
+
},
|
|
249
|
+
explode: { type: 'boolean' },
|
|
250
|
+
allowReserved: { type: 'boolean' },
|
|
251
|
+
},
|
|
252
|
+
extensionsPrefix: 'x-',
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const EnumDescriptions: NodeType = {
|
|
256
|
+
properties: {},
|
|
257
|
+
additionalProperties: { type: 'string' },
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const Header: NodeType = {
|
|
261
|
+
properties: {
|
|
262
|
+
description: { type: 'string' },
|
|
263
|
+
required: { type: 'boolean' },
|
|
264
|
+
deprecated: { type: 'boolean' },
|
|
265
|
+
allowEmptyValue: { type: 'boolean' },
|
|
266
|
+
style: {
|
|
267
|
+
enum: ['form', 'simple', 'label', 'matrix', 'spaceDelimited', 'pipeDelimited', 'deepObject'],
|
|
268
|
+
},
|
|
269
|
+
explode: { type: 'boolean' },
|
|
270
|
+
allowReserved: { type: 'boolean' },
|
|
271
|
+
schema: 'Schema',
|
|
272
|
+
example: { isExample: true },
|
|
273
|
+
examples: 'ExamplesMap',
|
|
274
|
+
content: 'MediaTypesMap',
|
|
275
|
+
},
|
|
276
|
+
requiredOneOf: ['schema', 'content'],
|
|
277
|
+
extensionsPrefix: 'x-',
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const Responses: NodeType = {
|
|
281
|
+
properties: { default: 'Response' },
|
|
282
|
+
additionalProperties: (_v: any, key: string) =>
|
|
283
|
+
responseCodeRegexp.test(key) ? 'Response' : undefined,
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const Response: NodeType = {
|
|
287
|
+
properties: {
|
|
288
|
+
description: { type: 'string' },
|
|
289
|
+
headers: 'HeadersMap',
|
|
290
|
+
content: 'MediaTypesMap',
|
|
291
|
+
links: 'LinksMap',
|
|
292
|
+
'x-summary': { type: 'string' },
|
|
293
|
+
},
|
|
294
|
+
required: ['description'],
|
|
295
|
+
extensionsPrefix: 'x-',
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const Link: NodeType = {
|
|
299
|
+
properties: {
|
|
300
|
+
operationRef: { type: 'string' },
|
|
301
|
+
operationId: { type: 'string' },
|
|
302
|
+
parameters: null, // TODO: figure out how to describe/validate this
|
|
303
|
+
requestBody: null, // TODO: figure out how to describe/validate this
|
|
304
|
+
description: { type: 'string' },
|
|
305
|
+
server: 'Server',
|
|
306
|
+
},
|
|
307
|
+
extensionsPrefix: 'x-',
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const Schema: NodeType = {
|
|
311
|
+
properties: {
|
|
312
|
+
externalDocs: 'ExternalDocs',
|
|
313
|
+
discriminator: 'Discriminator',
|
|
314
|
+
title: { type: 'string' },
|
|
315
|
+
multipleOf: { type: 'number', minimum: 0 },
|
|
316
|
+
maximum: { type: 'number' },
|
|
317
|
+
minimum: { type: 'number' },
|
|
318
|
+
exclusiveMaximum: { type: 'boolean' },
|
|
319
|
+
exclusiveMinimum: { type: 'boolean' },
|
|
320
|
+
maxLength: { type: 'integer', minimum: 0 },
|
|
321
|
+
minLength: { type: 'integer', minimum: 0 },
|
|
322
|
+
pattern: { type: 'string' },
|
|
323
|
+
maxItems: { type: 'integer', minimum: 0 },
|
|
324
|
+
minItems: { type: 'integer', minimum: 0 },
|
|
325
|
+
uniqueItems: { type: 'boolean' },
|
|
326
|
+
maxProperties: { type: 'integer', minimum: 0 },
|
|
327
|
+
minProperties: { type: 'integer', minimum: 0 },
|
|
328
|
+
required: { type: 'array', items: { type: 'string' } },
|
|
329
|
+
enum: { type: 'array' },
|
|
330
|
+
type: {
|
|
331
|
+
enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'],
|
|
332
|
+
},
|
|
333
|
+
allOf: listOf('Schema'),
|
|
334
|
+
anyOf: listOf('Schema'),
|
|
335
|
+
oneOf: listOf('Schema'),
|
|
336
|
+
not: 'Schema',
|
|
337
|
+
properties: 'SchemaProperties',
|
|
338
|
+
items: (value: any) => {
|
|
339
|
+
if (Array.isArray(value)) {
|
|
340
|
+
return listOf('Schema');
|
|
341
|
+
} else {
|
|
342
|
+
return 'Schema';
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
additionalItems: (value: any) => {
|
|
346
|
+
if (typeof value === 'boolean') {
|
|
347
|
+
return { type: 'boolean' };
|
|
348
|
+
} else {
|
|
349
|
+
return 'Schema';
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
additionalProperties: (value: any) => {
|
|
353
|
+
if (typeof value === 'boolean') {
|
|
354
|
+
return { type: 'boolean' };
|
|
355
|
+
} else {
|
|
356
|
+
return 'Schema';
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
description: { type: 'string' },
|
|
360
|
+
format: { type: 'string' },
|
|
361
|
+
default: null,
|
|
362
|
+
nullable: { type: 'boolean' },
|
|
363
|
+
readOnly: { type: 'boolean' },
|
|
364
|
+
writeOnly: { type: 'boolean' },
|
|
365
|
+
xml: 'Xml',
|
|
366
|
+
example: { isExample: true },
|
|
367
|
+
deprecated: { type: 'boolean' },
|
|
368
|
+
'x-tags': { type: 'array', items: { type: 'string' } },
|
|
369
|
+
'x-additionalPropertiesName': { type: 'string' },
|
|
370
|
+
'x-explicitMappingOnly': { type: 'boolean' },
|
|
371
|
+
},
|
|
372
|
+
extensionsPrefix: 'x-',
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const Xml: NodeType = {
|
|
376
|
+
properties: {
|
|
377
|
+
name: { type: 'string' },
|
|
378
|
+
namespace: { type: 'string' },
|
|
379
|
+
prefix: { type: 'string' },
|
|
380
|
+
attribute: { type: 'boolean' },
|
|
381
|
+
wrapped: { type: 'boolean' },
|
|
382
|
+
},
|
|
383
|
+
extensionsPrefix: 'x-',
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const SchemaProperties: NodeType = {
|
|
387
|
+
properties: {},
|
|
388
|
+
additionalProperties: 'Schema',
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const DiscriminatorMapping: NodeType = {
|
|
392
|
+
properties: {},
|
|
393
|
+
additionalProperties: (value: any) => {
|
|
394
|
+
if (isMappingRef(value)) {
|
|
395
|
+
return { type: 'string', directResolveAs: 'Schema' };
|
|
396
|
+
} else {
|
|
397
|
+
return { type: 'string' };
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
const Discriminator: NodeType = {
|
|
403
|
+
properties: {
|
|
404
|
+
propertyName: { type: 'string' },
|
|
405
|
+
mapping: 'DiscriminatorMapping',
|
|
406
|
+
},
|
|
407
|
+
required: ['propertyName'],
|
|
408
|
+
extensionsPrefix: 'x-',
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const Components: NodeType = {
|
|
412
|
+
properties: {
|
|
413
|
+
parameters: 'NamedParameters',
|
|
414
|
+
schemas: 'NamedSchemas',
|
|
415
|
+
responses: 'NamedResponses',
|
|
416
|
+
examples: 'NamedExamples',
|
|
417
|
+
requestBodies: 'NamedRequestBodies',
|
|
418
|
+
headers: 'NamedHeaders',
|
|
419
|
+
securitySchemes: 'NamedSecuritySchemes',
|
|
420
|
+
links: 'NamedLinks',
|
|
421
|
+
callbacks: 'NamedCallbacks',
|
|
422
|
+
},
|
|
423
|
+
extensionsPrefix: 'x-',
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
const ImplicitFlow: NodeType = {
|
|
427
|
+
properties: {
|
|
428
|
+
refreshUrl: { type: 'string' },
|
|
429
|
+
scopes: { type: 'object', additionalProperties: { type: 'string' } }, // TODO: validate scopes
|
|
430
|
+
authorizationUrl: { type: 'string' },
|
|
431
|
+
},
|
|
432
|
+
required: ['authorizationUrl', 'scopes'],
|
|
433
|
+
extensionsPrefix: 'x-',
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const PasswordFlow: NodeType = {
|
|
437
|
+
properties: {
|
|
438
|
+
refreshUrl: { type: 'string' },
|
|
439
|
+
scopes: { type: 'object', additionalProperties: { type: 'string' } }, // TODO: validate scopes
|
|
440
|
+
tokenUrl: { type: 'string' },
|
|
441
|
+
},
|
|
442
|
+
required: ['tokenUrl', 'scopes'],
|
|
443
|
+
extensionsPrefix: 'x-',
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
const ClientCredentials: NodeType = {
|
|
447
|
+
properties: {
|
|
448
|
+
refreshUrl: { type: 'string' },
|
|
449
|
+
scopes: { type: 'object', additionalProperties: { type: 'string' } }, // TODO: validate scopes
|
|
450
|
+
tokenUrl: { type: 'string' },
|
|
451
|
+
},
|
|
452
|
+
required: ['tokenUrl', 'scopes'],
|
|
453
|
+
extensionsPrefix: 'x-',
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const AuthorizationCode: NodeType = {
|
|
457
|
+
properties: {
|
|
458
|
+
refreshUrl: { type: 'string' },
|
|
459
|
+
authorizationUrl: { type: 'string' },
|
|
460
|
+
scopes: { type: 'object', additionalProperties: { type: 'string' } }, // TODO: validate scopes
|
|
461
|
+
tokenUrl: { type: 'string' },
|
|
462
|
+
'x-usePkce': (value: any) => {
|
|
463
|
+
if (typeof value === 'boolean') {
|
|
464
|
+
return { type: 'boolean' };
|
|
465
|
+
} else {
|
|
466
|
+
return 'XUsePkce';
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
required: ['authorizationUrl', 'tokenUrl', 'scopes'],
|
|
471
|
+
extensionsPrefix: 'x-',
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
const OAuth2Flows: NodeType = {
|
|
475
|
+
properties: {
|
|
476
|
+
implicit: 'ImplicitFlow',
|
|
477
|
+
password: 'PasswordFlow',
|
|
478
|
+
clientCredentials: 'ClientCredentials',
|
|
479
|
+
authorizationCode: 'AuthorizationCode',
|
|
480
|
+
},
|
|
481
|
+
extensionsPrefix: 'x-',
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
const SecurityScheme: NodeType = {
|
|
485
|
+
properties: {
|
|
486
|
+
type: { enum: ['apiKey', 'http', 'oauth2', 'openIdConnect'] },
|
|
487
|
+
description: { type: 'string' },
|
|
488
|
+
name: { type: 'string' },
|
|
489
|
+
in: { type: 'string', enum: ['query', 'header', 'cookie'] },
|
|
490
|
+
scheme: { type: 'string' },
|
|
491
|
+
bearerFormat: { type: 'string' },
|
|
492
|
+
flows: 'OAuth2Flows',
|
|
493
|
+
openIdConnectUrl: { type: 'string' },
|
|
494
|
+
'x-defaultClientId': { type: 'string' },
|
|
495
|
+
},
|
|
496
|
+
required(value) {
|
|
497
|
+
switch (value?.type) {
|
|
498
|
+
case 'apiKey':
|
|
499
|
+
return ['type', 'name', 'in'];
|
|
500
|
+
case 'http':
|
|
501
|
+
return ['type', 'scheme'];
|
|
502
|
+
case 'oauth2':
|
|
503
|
+
return ['type', 'flows'];
|
|
504
|
+
case 'openIdConnect':
|
|
505
|
+
return ['type', 'openIdConnectUrl'];
|
|
506
|
+
default:
|
|
507
|
+
return ['type'];
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
allowed(value) {
|
|
511
|
+
switch (value?.type) {
|
|
512
|
+
case 'apiKey':
|
|
513
|
+
return ['type', 'name', 'in', 'description'];
|
|
514
|
+
case 'http':
|
|
515
|
+
return ['type', 'scheme', 'bearerFormat', 'description'];
|
|
516
|
+
case 'oauth2':
|
|
517
|
+
return ['type', 'flows', 'description'];
|
|
518
|
+
case 'openIdConnect':
|
|
519
|
+
return ['type', 'openIdConnectUrl', 'description'];
|
|
520
|
+
default:
|
|
521
|
+
return ['type', 'description'];
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
extensionsPrefix: 'x-',
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
const XUsePkce: NodeType = {
|
|
528
|
+
properties: {
|
|
529
|
+
disableManualConfiguration: { type: 'boolean' },
|
|
530
|
+
hideClientSecretInput: { type: 'boolean' },
|
|
531
|
+
},
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
export const Oas3Types: Record<string, NodeType> = {
|
|
535
|
+
Root,
|
|
536
|
+
Tag,
|
|
537
|
+
TagList: listOf('Tag'),
|
|
538
|
+
TagGroups: listOf('TagGroup'),
|
|
539
|
+
TagGroup,
|
|
540
|
+
ExternalDocs,
|
|
541
|
+
Server,
|
|
542
|
+
ServerList: listOf('Server'),
|
|
543
|
+
ServerVariable,
|
|
544
|
+
ServerVariablesMap: mapOf('ServerVariable'),
|
|
545
|
+
SecurityRequirement,
|
|
546
|
+
SecurityRequirementList: listOf('SecurityRequirement'),
|
|
547
|
+
Info,
|
|
548
|
+
Contact,
|
|
549
|
+
License,
|
|
550
|
+
Paths,
|
|
551
|
+
PathItem,
|
|
552
|
+
Parameter,
|
|
553
|
+
ParameterList: listOf('Parameter'),
|
|
554
|
+
Operation,
|
|
555
|
+
Callback: mapOf('PathItem'),
|
|
556
|
+
CallbacksMap: mapOf('Callback'),
|
|
557
|
+
RequestBody,
|
|
558
|
+
MediaTypesMap,
|
|
559
|
+
MediaType,
|
|
560
|
+
Example,
|
|
561
|
+
ExamplesMap: mapOf('Example'),
|
|
562
|
+
Encoding,
|
|
563
|
+
EncodingMap: mapOf('Encoding'),
|
|
564
|
+
EnumDescriptions,
|
|
565
|
+
Header,
|
|
566
|
+
HeadersMap: mapOf('Header'),
|
|
567
|
+
Responses,
|
|
568
|
+
Response,
|
|
569
|
+
Link,
|
|
570
|
+
Logo,
|
|
571
|
+
Schema,
|
|
572
|
+
Xml,
|
|
573
|
+
SchemaProperties,
|
|
574
|
+
DiscriminatorMapping,
|
|
575
|
+
Discriminator,
|
|
576
|
+
Components,
|
|
577
|
+
LinksMap: mapOf('Link'),
|
|
578
|
+
NamedSchemas: mapOf('Schema'),
|
|
579
|
+
NamedResponses: mapOf('Response'),
|
|
580
|
+
NamedParameters: mapOf('Parameter'),
|
|
581
|
+
NamedExamples: mapOf('Example'),
|
|
582
|
+
NamedRequestBodies: mapOf('RequestBody'),
|
|
583
|
+
NamedHeaders: mapOf('Header'),
|
|
584
|
+
NamedSecuritySchemes: mapOf('SecurityScheme'),
|
|
585
|
+
NamedLinks: mapOf('Link'),
|
|
586
|
+
NamedCallbacks: mapOf('Callback'),
|
|
587
|
+
ImplicitFlow,
|
|
588
|
+
PasswordFlow,
|
|
589
|
+
ClientCredentials,
|
|
590
|
+
AuthorizationCode,
|
|
591
|
+
OAuth2Flows,
|
|
592
|
+
SecurityScheme,
|
|
593
|
+
XCodeSample,
|
|
594
|
+
XCodeSampleList: listOf('XCodeSample'),
|
|
595
|
+
XUsePkce,
|
|
596
|
+
WebhooksMap,
|
|
597
|
+
};
|