@mintlify/common 1.0.904 → 1.0.905
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.
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { getEnumValues } from '../getEnumValues.js';
|
|
2
|
+
const combinationKeys = ['oneOf', 'anyOf', 'allOf'];
|
|
3
|
+
const getCombinationKey = (value) => {
|
|
4
|
+
return combinationKeys.find((key) => key in value && Array.isArray(value[key]));
|
|
5
|
+
};
|
|
6
|
+
const getTypeFromCombination = (value, combKey) => {
|
|
7
|
+
var _a;
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
const schemas = value[combKey];
|
|
10
|
+
const types = [
|
|
11
|
+
...new Set(schemas
|
|
12
|
+
.map((s) => (typeof s === 'object' ? s.type : undefined))
|
|
13
|
+
.filter((t) => typeof t === 'string' && t !== 'null')),
|
|
14
|
+
];
|
|
15
|
+
if (types.length === 1)
|
|
16
|
+
return (_a = types[0]) !== null && _a !== void 0 ? _a : combKey;
|
|
17
|
+
return combKey;
|
|
18
|
+
};
|
|
2
19
|
const getSchemaType = (value, keys) => {
|
|
3
20
|
if ('type' in value) {
|
|
4
21
|
return value.type;
|
|
@@ -61,18 +78,93 @@ export const extractSchemaProperties = (schema) => {
|
|
|
61
78
|
const prop = {
|
|
62
79
|
name: name,
|
|
63
80
|
type,
|
|
81
|
+
title: value.title,
|
|
64
82
|
description: value.description || value['const'],
|
|
65
83
|
enumValues: getEnumValues(value),
|
|
84
|
+
examples: value.examples,
|
|
66
85
|
deprecated: value.deprecated,
|
|
67
86
|
required: requiredFields.has(name),
|
|
68
87
|
};
|
|
69
88
|
if (value.properties) {
|
|
70
89
|
prop.properties = extractSchemaProperties(value.properties);
|
|
71
90
|
}
|
|
91
|
+
else if (type === 'array' &&
|
|
92
|
+
value.items &&
|
|
93
|
+
typeof value.items === 'object' &&
|
|
94
|
+
!Array.isArray(value.items)) {
|
|
95
|
+
if (value.items.properties) {
|
|
96
|
+
const itemSchemaWithRequired = Object.assign(Object.assign({}, value.items.properties), { required: value.items.required });
|
|
97
|
+
prop.properties = extractSchemaProperties(itemSchemaWithRequired);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const itemProps = extractSchemaProperties({ item: value.items });
|
|
101
|
+
if (itemProps.length > 0) {
|
|
102
|
+
prop.properties = itemProps;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
72
106
|
properties.push(prop);
|
|
73
107
|
}
|
|
74
108
|
else {
|
|
75
|
-
|
|
109
|
+
const combKey = getCombinationKey(value);
|
|
110
|
+
if (combKey) {
|
|
111
|
+
const inferredType = getTypeFromCombination(value, combKey);
|
|
112
|
+
const prop = {
|
|
113
|
+
name,
|
|
114
|
+
type: inferredType,
|
|
115
|
+
title: value.title,
|
|
116
|
+
description: value.description,
|
|
117
|
+
enumValues: getEnumValues(value),
|
|
118
|
+
examples: value.examples,
|
|
119
|
+
deprecated: value.deprecated,
|
|
120
|
+
required: requiredFields.has(name),
|
|
121
|
+
};
|
|
122
|
+
// Extract child properties from combination schemas
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
|
+
const combSchemas = value[combKey];
|
|
125
|
+
if (combKey === 'allOf') {
|
|
126
|
+
// allOf: merge all sub-schema properties together
|
|
127
|
+
const mergedProps = combSchemas.flatMap(
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
|
+
(item) => {
|
|
130
|
+
if (item.properties) {
|
|
131
|
+
const schemaWithRequired = Object.assign(Object.assign({}, item.properties), { required: item.required });
|
|
132
|
+
return extractSchemaProperties(schemaWithRequired);
|
|
133
|
+
}
|
|
134
|
+
return [];
|
|
135
|
+
});
|
|
136
|
+
if (mergedProps.length > 0) {
|
|
137
|
+
prop.properties = mergedProps;
|
|
138
|
+
if (inferredType === 'allOf')
|
|
139
|
+
prop.type = 'object';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
// oneOf/anyOf: extract properties from sub-schemas that have them
|
|
144
|
+
const subProps = combSchemas.flatMap(
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
146
|
+
(item) => {
|
|
147
|
+
if (item.properties) {
|
|
148
|
+
const schemaWithRequired = Object.assign(Object.assign({}, item.properties), { required: item.required });
|
|
149
|
+
return extractSchemaProperties(schemaWithRequired);
|
|
150
|
+
}
|
|
151
|
+
if (item.items && typeof item.items === 'object') {
|
|
152
|
+
if (item.items.properties) {
|
|
153
|
+
const schemaWithRequired = Object.assign(Object.assign({}, item.items.properties), { required: item.items.required });
|
|
154
|
+
return extractSchemaProperties(schemaWithRequired);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return [];
|
|
158
|
+
});
|
|
159
|
+
if (subProps.length > 0) {
|
|
160
|
+
prop.properties = subProps;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
properties.push(prop);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
properties.push(...extractSchemaProperties(value));
|
|
167
|
+
}
|
|
76
168
|
}
|
|
77
169
|
}
|
|
78
170
|
else {
|