@redocly/openapi-core 1.9.0 → 1.9.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 +6 -0
- package/lib/bundle.d.ts +1 -1
- package/lib/lint.d.ts +1 -0
- package/lib/lint.js +1 -1
- package/lib/oas-types.d.ts +1 -1
- 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 +2 -2
- package/lib/visitors.js +1 -1
- package/lib/walk.js +7 -1
- package/package.json +1 -1
- package/src/__tests__/lint.test.ts +1218 -36
- package/src/__tests__/ref-utils.test.ts +22 -0
- package/src/config/__tests__/load.test.ts +13 -13
- package/src/decorators/oas2/remove-unused-components.ts +3 -2
- package/src/decorators/oas3/remove-unused-components.ts +3 -2
- package/src/lint.ts +2 -1
- 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 +2 -2
- package/src/visitors.ts +1 -1
- package/src/walk.ts +7 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/lib/bundle.d.ts
CHANGED
|
@@ -47,4 +47,4 @@ export declare function bundleDocument(opts: {
|
|
|
47
47
|
removeUnusedComponents?: boolean;
|
|
48
48
|
keepUrlRefs?: boolean;
|
|
49
49
|
}): Promise<BundleResult>;
|
|
50
|
-
export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "
|
|
50
|
+
export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "parameters" | "examples" | "headers" | "schemas" | "responses" | "requestBodies" | "securitySchemes" | "links" | "callbacks" | "definitions" | null;
|
package/lib/lint.d.ts
CHANGED
package/lib/lint.js
CHANGED
|
@@ -96,7 +96,7 @@ function lintConfig(opts) {
|
|
|
96
96
|
plugins,
|
|
97
97
|
rules: { spec: 'error' },
|
|
98
98
|
});
|
|
99
|
-
const types = (0, types_1.normalizeTypes)(redocly_yaml_1.ConfigTypes, config);
|
|
99
|
+
const types = (0, types_1.normalizeTypes)(opts.externalConfigTypes || redocly_yaml_1.ConfigTypes, config);
|
|
100
100
|
const rules = [
|
|
101
101
|
{
|
|
102
102
|
severity: severity || 'error',
|
package/lib/oas-types.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ export type Oas2DecoratorsSet = Record<string, Oas2Preprocessor>;
|
|
|
24
24
|
export type Async2DecoratorsSet = Record<string, Async2Preprocessor>;
|
|
25
25
|
export declare function detectSpec(root: any): SpecVersion;
|
|
26
26
|
export declare function getMajorSpecVersion(version: SpecVersion): SpecMajorVersion;
|
|
27
|
-
export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType>;
|
|
27
|
+
export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "Operation" | "Example" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "Examples" | "ExamplesMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "ParameterItems" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "XServer" | "XServerList", import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "Server" | "ServerVariable" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Callback" | "CallbacksMap" | "Parameter" | "Operation" | "RequestBody" | "MediaTypesMap" | "MediaType" | "Example" | "Encoding" | "Header" | "Responses" | "Response" | "Link" | "Schema" | "Xml" | "SchemaProperties" | "DiscriminatorMapping" | "Discriminator" | "Components" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedExamples" | "NamedRequestBodies" | "NamedHeaders" | "NamedSecuritySchemes" | "NamedLinks" | "NamedCallbacks" | "ImplicitFlow" | "PasswordFlow" | "ClientCredentials" | "AuthorizationCode" | "OAuth2Flows" | "SecurityScheme" | "ServerVariablesMap" | "ExamplesMap" | "EncodingMap" | "HeadersMap" | "LinksMap" | "WebhooksMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "ServerList" | "XUsePkce", import("./types").NodeType> | Record<"Root" | "Info" | "License" | "Operation" | "Schema" | "SchemaProperties" | "Components" | "SecurityScheme" | "NamedPathItems", import("./types").NodeType>;
|
package/lib/ref-utils.js
CHANGED
|
@@ -39,9 +39,9 @@ function escapePointer(fragment) {
|
|
|
39
39
|
}
|
|
40
40
|
exports.escapePointer = escapePointer;
|
|
41
41
|
function parseRef(ref) {
|
|
42
|
-
const [uri, pointer = ''] = ref.split('
|
|
42
|
+
const [uri, pointer = ''] = ref.split('#/');
|
|
43
43
|
return {
|
|
44
|
-
uri: uri || null,
|
|
44
|
+
uri: (uri.endsWith('#') ? uri.slice(0, -1) : uri) || null,
|
|
45
45
|
pointer: parsePointer(pointer),
|
|
46
46
|
};
|
|
47
47
|
}
|
package/lib/resolve.js
CHANGED
|
@@ -211,8 +211,16 @@ function resolveDocument(opts) {
|
|
|
211
211
|
if (itemsType === undefined && type !== unknownType && type !== types_1.SpecExtension) {
|
|
212
212
|
return;
|
|
213
213
|
}
|
|
214
|
+
const isTypeAFunction = typeof itemsType === 'function';
|
|
214
215
|
for (let i = 0; i < node.length; i++) {
|
|
215
|
-
|
|
216
|
+
const itemType = isTypeAFunction
|
|
217
|
+
? itemsType(node[i], (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, i))
|
|
218
|
+
: itemsType;
|
|
219
|
+
// we continue resolving unknown types, but stop early on known scalars
|
|
220
|
+
if (itemType === undefined && type !== unknownType && type !== types_1.SpecExtension) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
walk(node[i], (0, types_1.isNamedType)(itemType) ? itemType : unknownType, (0, ref_utils_1.joinPointer)(nodeAbsoluteRef, i));
|
|
216
224
|
}
|
|
217
225
|
return;
|
|
218
226
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -19,26 +19,26 @@ export type NormalizedScalarSchema = {
|
|
|
19
19
|
export type NodeType = {
|
|
20
20
|
properties: Record<string, PropType | ResolveTypeFn>;
|
|
21
21
|
additionalProperties?: PropType | ResolveTypeFn;
|
|
22
|
-
items?:
|
|
22
|
+
items?: PropType | ResolveTypeFn;
|
|
23
23
|
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
24
24
|
requiredOneOf?: string[];
|
|
25
25
|
allowed?: (value: any) => string[] | undefined;
|
|
26
26
|
extensionsPrefix?: string;
|
|
27
27
|
};
|
|
28
|
-
type PropType = string | NodeType | ScalarSchema | undefined | null;
|
|
29
|
-
type ResolveTypeFn = (value: any, key: string) => string | PropType;
|
|
28
|
+
export type PropType = string | NodeType | ScalarSchema | undefined | null;
|
|
29
|
+
export type ResolveTypeFn = (value: any, key: string) => string | PropType;
|
|
30
30
|
export type NormalizedNodeType = {
|
|
31
31
|
name: string;
|
|
32
32
|
properties: Record<string, NormalizedPropType | NormalizedResolveTypeFn>;
|
|
33
33
|
additionalProperties?: NormalizedPropType | NormalizedResolveTypeFn;
|
|
34
|
-
items?:
|
|
34
|
+
items?: NormalizedPropType | NormalizedResolveTypeFn;
|
|
35
35
|
required?: string[] | ((value: any, key: string | number | undefined) => string[]);
|
|
36
36
|
requiredOneOf?: string[];
|
|
37
37
|
allowed?: (value: any) => string[] | undefined;
|
|
38
38
|
extensionsPrefix?: string;
|
|
39
39
|
};
|
|
40
|
-
type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema |
|
|
41
|
-
type NormalizedResolveTypeFn = (value: any, key: string) =>
|
|
40
|
+
type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | null | undefined;
|
|
41
|
+
type NormalizedResolveTypeFn = (value: any, key: string) => NormalizedPropType;
|
|
42
42
|
export declare function listOf(typeName: string): {
|
|
43
43
|
name: string;
|
|
44
44
|
properties: {};
|
|
@@ -53,5 +53,5 @@ export declare const SpecExtension: NormalizedNodeType;
|
|
|
53
53
|
export declare function normalizeTypes(types: Record<string, NodeType>, options?: {
|
|
54
54
|
doNotResolveExamples?: boolean;
|
|
55
55
|
}): Record<string, NormalizedNodeType>;
|
|
56
|
-
export declare function isNamedType(t:
|
|
56
|
+
export declare function isNamedType(t: NormalizedPropType): t is NormalizedNodeType;
|
|
57
57
|
export {};
|
|
@@ -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>;
|