@redocly/openapi-core 1.9.0 → 1.10.0
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 +12 -0
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +2 -2
- package/lib/config/config.d.ts +0 -6
- package/lib/config/config.js +1 -19
- package/lib/config/load.js +2 -2
- package/lib/decorators/common/registry-dependencies.js +2 -2
- package/lib/index.d.ts +3 -2
- package/lib/index.js +17 -2
- package/lib/lint.d.ts +1 -0
- package/lib/lint.js +1 -1
- package/lib/oas-types.d.ts +1 -1
- package/lib/redocly/domains.d.ts +14 -0
- package/lib/redocly/domains.js +41 -0
- package/lib/redocly/index.d.ts +1 -2
- package/lib/redocly/index.js +14 -24
- package/lib/redocly/registry-api.d.ts +2 -2
- package/lib/redocly/registry-api.js +9 -9
- package/lib/ref-utils.js +2 -2
- package/lib/resolve.js +9 -1
- package/lib/types/index.d.ts +7 -7
- package/lib/types/json-schema-adapter.d.ts +3 -0
- package/lib/types/json-schema-adapter.js +173 -0
- package/lib/types/oas2.d.ts +3 -2
- package/lib/types/oas3.d.ts +3 -2
- package/lib/types/oas3_1.d.ts +3 -2
- package/lib/types/portal-config-schema.d.ts +5261 -52
- package/lib/types/portal-config-schema.js +71 -55
- package/lib/types/redocly-yaml.d.ts +13 -1
- package/lib/types/redocly-yaml.js +101 -39
- package/lib/types/theme-config.d.ts +819 -36
- package/lib/types/theme-config.js +67 -29
- package/lib/utils.d.ts +4 -2
- package/lib/utils.js +7 -1
- package/lib/visitors.js +1 -1
- package/lib/walk.js +7 -1
- package/package.json +2 -1
- package/src/__tests__/lint.test.ts +1218 -36
- package/src/__tests__/ref-utils.test.ts +22 -0
- package/src/bundle.ts +1 -1
- package/src/config/__tests__/load.test.ts +13 -13
- package/src/config/config.ts +1 -23
- package/src/config/load.ts +2 -1
- package/src/decorators/common/registry-dependencies.ts +1 -1
- package/src/decorators/oas2/remove-unused-components.ts +3 -2
- package/src/decorators/oas3/remove-unused-components.ts +3 -2
- package/src/index.ts +11 -2
- package/src/lint.ts +2 -1
- package/src/redocly/__tests__/domains.test.ts +52 -0
- package/src/redocly/__tests__/redocly-client.test.ts +5 -3
- package/src/redocly/domains.ts +48 -0
- package/src/redocly/index.ts +14 -24
- package/src/redocly/registry-api.ts +25 -31
- package/src/ref-utils.ts +2 -2
- package/src/resolve.ts +13 -1
- package/src/types/index.ts +7 -12
- package/src/types/json-schema-adapter.ts +217 -0
- package/src/types/oas2.ts +5 -2
- package/src/types/oas3.ts +6 -2
- package/src/types/oas3_1.ts +5 -2
- package/src/types/portal-config-schema.ts +111 -61
- package/src/types/redocly-yaml.ts +118 -43
- package/src/types/theme-config.ts +125 -27
- package/src/utils.ts +9 -3
- package/src/visitors.ts +1 -1
- package/src/walk.ts +7 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// For internal usage only
|
|
3
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
8
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
9
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
10
|
+
t[p[i]] = s[p[i]];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getNodeTypesFromJSONSchema = void 0;
|
|
16
|
+
const _2020_1 = require("@redocly/ajv/dist/2020");
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const ajv = new _2020_1.default({
|
|
19
|
+
strictSchema: false,
|
|
20
|
+
allowUnionTypes: true,
|
|
21
|
+
useDefaults: true,
|
|
22
|
+
allErrors: true,
|
|
23
|
+
discriminator: true,
|
|
24
|
+
strictTypes: false,
|
|
25
|
+
verbose: true,
|
|
26
|
+
});
|
|
27
|
+
function findOneOf(schemaOneOf, oneOfs) {
|
|
28
|
+
if (oneOfs.some((option) => typeof option === 'function')) {
|
|
29
|
+
throw new Error('Unexpected oneOf inside oneOf.');
|
|
30
|
+
}
|
|
31
|
+
return (value) => {
|
|
32
|
+
let index = schemaOneOf.findIndex((option) => ajv.validate(option, value));
|
|
33
|
+
if (index === -1) {
|
|
34
|
+
index = 0;
|
|
35
|
+
}
|
|
36
|
+
return oneOfs[index];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function transformJSONSchemaToNodeType(propertyName, schema, ctx) {
|
|
40
|
+
var _a;
|
|
41
|
+
if (!schema || typeof schema === 'boolean') {
|
|
42
|
+
throw new Error(`Unexpected schema in ${propertyName}.`);
|
|
43
|
+
}
|
|
44
|
+
if (schema instanceof Array) {
|
|
45
|
+
throw new Error(`Unexpected array schema in ${propertyName}. Try using oneOf instead.`);
|
|
46
|
+
}
|
|
47
|
+
if (schema.type === 'null') {
|
|
48
|
+
throw new Error(`Unexpected null schema type in ${propertyName} schema.`);
|
|
49
|
+
}
|
|
50
|
+
if (schema.type instanceof Array) {
|
|
51
|
+
throw new Error(`Unexpected array schema type in ${propertyName} schema. Try using oneOf instead.`);
|
|
52
|
+
}
|
|
53
|
+
if (schema.type === 'string' ||
|
|
54
|
+
schema.type === 'number' ||
|
|
55
|
+
schema.type === 'integer' ||
|
|
56
|
+
schema.type === 'boolean') {
|
|
57
|
+
const { default: _, format: _format } = schema, rest = __rest(schema, ["default", "format"]);
|
|
58
|
+
return rest;
|
|
59
|
+
}
|
|
60
|
+
if (schema.type === 'object' && !schema.properties && !schema.oneOf) {
|
|
61
|
+
if (schema.additionalProperties === undefined || schema.additionalProperties === true) {
|
|
62
|
+
return { type: 'object' };
|
|
63
|
+
}
|
|
64
|
+
else if (schema.additionalProperties === false) {
|
|
65
|
+
return { type: 'object', properties: {} };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (schema.allOf) {
|
|
69
|
+
throw new Error(`Unexpected allOf in ${propertyName}.`);
|
|
70
|
+
}
|
|
71
|
+
if (schema.anyOf) {
|
|
72
|
+
throw new Error(`Unexpected anyOf in ${propertyName}.`);
|
|
73
|
+
}
|
|
74
|
+
if ((0, utils_1.isPlainObject)(schema.properties) ||
|
|
75
|
+
(0, utils_1.isPlainObject)(schema.additionalProperties) ||
|
|
76
|
+
((0, utils_1.isPlainObject)(schema.items) &&
|
|
77
|
+
((0, utils_1.isPlainObject)(schema.items.properties) ||
|
|
78
|
+
(0, utils_1.isPlainObject)(schema.items.additionalProperties) ||
|
|
79
|
+
schema.items.oneOf)) // exclude scalar array types
|
|
80
|
+
) {
|
|
81
|
+
return extractNodeToContext(propertyName, schema, ctx);
|
|
82
|
+
}
|
|
83
|
+
if (schema.oneOf) {
|
|
84
|
+
if (schema.discriminator) {
|
|
85
|
+
const discriminatedPropertyName = (_a = schema.discriminator) === null || _a === void 0 ? void 0 : _a.propertyName;
|
|
86
|
+
if (!discriminatedPropertyName) {
|
|
87
|
+
throw new Error(`Unexpected discriminator without a propertyName in ${propertyName}.`);
|
|
88
|
+
}
|
|
89
|
+
const oneOfs = schema.oneOf.map((option, i) => {
|
|
90
|
+
var _a;
|
|
91
|
+
if (typeof option === 'boolean') {
|
|
92
|
+
throw new Error(`Unexpected boolean schema in ${propertyName} at position ${i} in oneOf.`);
|
|
93
|
+
}
|
|
94
|
+
const discriminatedProperty = (_a = option === null || option === void 0 ? void 0 : option.properties) === null || _a === void 0 ? void 0 : _a[discriminatedPropertyName];
|
|
95
|
+
if (!discriminatedProperty || typeof discriminatedProperty === 'boolean') {
|
|
96
|
+
throw new Error(`Unexpected property '${discriminatedProperty}' schema in ${propertyName} at position ${i} in oneOf.`);
|
|
97
|
+
}
|
|
98
|
+
const name = discriminatedProperty.const;
|
|
99
|
+
return transformJSONSchemaToNodeType(name, option, ctx);
|
|
100
|
+
});
|
|
101
|
+
return (value, key) => {
|
|
102
|
+
if ((0, utils_1.isPlainObject)(value)) {
|
|
103
|
+
const discriminatedTypeName = value[discriminatedPropertyName];
|
|
104
|
+
if (typeof discriminatedTypeName === 'string' && ctx[discriminatedTypeName]) {
|
|
105
|
+
return discriminatedTypeName;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return findOneOf(schema.oneOf, oneOfs)(value, key);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const oneOfs = schema.oneOf.map((option, i) => transformJSONSchemaToNodeType(propertyName + '_' + i, option, ctx));
|
|
113
|
+
return findOneOf(schema.oneOf, oneOfs);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return schema;
|
|
117
|
+
}
|
|
118
|
+
function extractNodeToContext(propertyName, schema, ctx) {
|
|
119
|
+
if (!schema || typeof schema === 'boolean') {
|
|
120
|
+
throw new Error(`Unexpected schema in ${propertyName}.`);
|
|
121
|
+
}
|
|
122
|
+
if (schema instanceof Array) {
|
|
123
|
+
throw new Error(`Unexpected array schema in ${propertyName}. Try using oneOf instead.`);
|
|
124
|
+
}
|
|
125
|
+
if (schema.type === 'null') {
|
|
126
|
+
throw new Error(`Unexpected null schema type in ${propertyName} schema.`);
|
|
127
|
+
}
|
|
128
|
+
if (schema.type instanceof Array) {
|
|
129
|
+
throw new Error(`Unexpected array schema type in ${propertyName} schema. Try using oneOf instead.`);
|
|
130
|
+
}
|
|
131
|
+
const properties = {};
|
|
132
|
+
for (const [name, property] of Object.entries(schema.properties || {})) {
|
|
133
|
+
properties[name] = transformJSONSchemaToNodeType(propertyName + '.' + name, property, ctx);
|
|
134
|
+
}
|
|
135
|
+
let additionalProperties;
|
|
136
|
+
if ((0, utils_1.isPlainObject)(schema.additionalProperties)) {
|
|
137
|
+
additionalProperties = transformJSONSchemaToNodeType(propertyName + '_additionalProperties', schema.additionalProperties, ctx);
|
|
138
|
+
}
|
|
139
|
+
if (schema.additionalProperties === true) {
|
|
140
|
+
additionalProperties = {};
|
|
141
|
+
}
|
|
142
|
+
let items;
|
|
143
|
+
if ((0, utils_1.isPlainObject)(schema.items) &&
|
|
144
|
+
((0, utils_1.isPlainObject)(schema.items.properties) ||
|
|
145
|
+
(0, utils_1.isPlainObject)(schema.items.additionalProperties) ||
|
|
146
|
+
schema.items.oneOf) // exclude scalar array types
|
|
147
|
+
) {
|
|
148
|
+
items = transformJSONSchemaToNodeType(propertyName + '_items', schema.items, ctx);
|
|
149
|
+
}
|
|
150
|
+
let required = schema.required;
|
|
151
|
+
// Translate required in oneOfs into a ResolveTypeFn.
|
|
152
|
+
if (schema.oneOf && schema.oneOf.every((option) => !!option.required)) {
|
|
153
|
+
required = (value) => {
|
|
154
|
+
const requiredList = schema.oneOf.map((option) => [
|
|
155
|
+
...(schema.required || []),
|
|
156
|
+
...option.required,
|
|
157
|
+
]);
|
|
158
|
+
let index = requiredList.findIndex((r) => r.every((requiredProp) => value[requiredProp] !== undefined));
|
|
159
|
+
if (index === -1) {
|
|
160
|
+
index = 0;
|
|
161
|
+
}
|
|
162
|
+
return requiredList[index];
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
ctx[propertyName] = { properties, additionalProperties, items, required };
|
|
166
|
+
return propertyName;
|
|
167
|
+
}
|
|
168
|
+
function getNodeTypesFromJSONSchema(schemaName, entrySchema) {
|
|
169
|
+
const ctx = {};
|
|
170
|
+
transformJSONSchemaToNodeType(schemaName, entrySchema, ctx);
|
|
171
|
+
return ctx;
|
|
172
|
+
}
|
|
173
|
+
exports.getNodeTypesFromJSONSchema = getNodeTypesFromJSONSchema;
|
package/lib/types/oas2.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { NodeType } from '.';
|
|
2
|
-
|
|
1
|
+
import type { NodeType } from '.';
|
|
2
|
+
import type { Oas2NodeType } from './redocly-yaml';
|
|
3
|
+
export declare const Oas2Types: Record<Oas2NodeType, NodeType>;
|
package/lib/types/oas3.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { NodeType } from '.';
|
|
2
|
-
|
|
1
|
+
import type { NodeType } from '.';
|
|
2
|
+
import type { Oas3NodeType } from './redocly-yaml';
|
|
3
|
+
export declare const Oas3Types: Record<Oas3NodeType, NodeType>;
|
package/lib/types/oas3_1.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { NodeType } from '.';
|
|
2
|
-
|
|
1
|
+
import type { NodeType } from '.';
|
|
2
|
+
import type { Oas3_1NodeType } from './redocly-yaml';
|
|
3
|
+
export declare const Oas3_1Types: Record<Oas3_1NodeType, NodeType>;
|