@mintlify/common 1.0.806 → 1.0.807
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/dist/asyncapi/getEnumValues.d.ts +2 -0
- package/dist/asyncapi/getEnumValues.js +7 -0
- package/dist/asyncapi/index.d.ts +1 -0
- package/dist/asyncapi/index.js +1 -0
- package/dist/asyncapi/parser/extractSchemaProperties.js +24 -3
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/asyncapi.d.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const getEnumValues = (value) => {
|
|
2
|
+
if (!Array.isArray(value === null || value === void 0 ? void 0 : value.enum)) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
const enumValues = value.enum.filter((option) => typeof option === 'string' || typeof option === 'number' || typeof option === 'boolean');
|
|
6
|
+
return enumValues.length > 0 ? enumValues : undefined;
|
|
7
|
+
};
|
package/dist/asyncapi/index.d.ts
CHANGED
package/dist/asyncapi/index.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
import { getEnumValues } from '../getEnumValues.js';
|
|
2
|
+
const getSchemaType = (value, keys) => {
|
|
3
|
+
if ('type' in value) {
|
|
4
|
+
return value.type;
|
|
5
|
+
}
|
|
6
|
+
const customTypeKey = keys.find((key) => /^x-.*type$/.test(key));
|
|
7
|
+
if (customTypeKey) {
|
|
8
|
+
return value[customTypeKey];
|
|
9
|
+
}
|
|
10
|
+
const enumValues = getEnumValues(value);
|
|
11
|
+
if (enumValues === null || enumValues === void 0 ? void 0 : enumValues.length) {
|
|
12
|
+
const firstValue = enumValues[0];
|
|
13
|
+
if (typeof firstValue === 'boolean')
|
|
14
|
+
return 'boolean';
|
|
15
|
+
if (typeof firstValue === 'number')
|
|
16
|
+
return 'number';
|
|
17
|
+
return 'string';
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
};
|
|
1
21
|
export const extractSchemaProperties = (schema) => {
|
|
2
22
|
if (!schema) {
|
|
3
23
|
return [];
|
|
@@ -36,12 +56,13 @@ export const extractSchemaProperties = (schema) => {
|
|
|
36
56
|
}
|
|
37
57
|
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
38
58
|
const keys = Object.keys(value);
|
|
39
|
-
|
|
40
|
-
|
|
59
|
+
const type = getSchemaType(value, keys);
|
|
60
|
+
if (type !== undefined) {
|
|
41
61
|
const prop = {
|
|
42
62
|
name: name,
|
|
43
|
-
type
|
|
63
|
+
type,
|
|
44
64
|
description: value.description || value['const'],
|
|
65
|
+
enumValues: getEnumValues(value),
|
|
45
66
|
deprecated: value.deprecated,
|
|
46
67
|
required: requiredFields.has(name),
|
|
47
68
|
};
|