@mintlify/validation 0.1.923 → 0.1.925
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/mint-config/schemas/v2/index.d.ts +5 -0
- package/dist/mint-config/schemas/v2/properties/api.d.ts +3 -0
- package/dist/mint-config/schemas/v2/properties/api.js +4 -0
- package/dist/mint-config/schemas/v2/themes/almond.d.ts +5 -0
- package/dist/mint-config/schemas/v2/themes/aspen.d.ts +5 -0
- package/dist/mint-config/schemas/v2/themes/linden.d.ts +5 -0
- package/dist/mint-config/schemas/v2/themes/luma.d.ts +5 -0
- package/dist/mint-config/schemas/v2/themes/maple.d.ts +5 -0
- package/dist/mint-config/schemas/v2/themes/mint.d.ts +5 -0
- package/dist/mint-config/schemas/v2/themes/palm.d.ts +5 -0
- package/dist/mint-config/schemas/v2/themes/reusable/index.d.ts +3 -0
- package/dist/mint-config/schemas/v2/themes/sequoia.d.ts +5 -0
- package/dist/mint-config/schemas/v2/themes/willow.d.ts +5 -0
- package/dist/mint-config/validateConfig.d.ts +18 -0
- package/dist/openapi/OpenApiToEndpointConverter.d.ts +1 -1
- package/dist/openapi/OpenApiToEndpointConverter.js +4 -4
- package/dist/openapi/generateExampleFromSchema.d.ts +1 -1
- package/dist/openapi/generateExampleFromSchema.js +26 -6
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -32,7 +32,24 @@ const filterXMint = (schema) => {
|
|
|
32
32
|
}
|
|
33
33
|
return schema;
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
const shouldOmitOptionalObjectExample = (schema, value) => {
|
|
36
|
+
var _a;
|
|
37
|
+
if (schema.type !== 'object' || schema.required === true || schema.minProperties === undefined) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (schema.example !== undefined ||
|
|
41
|
+
((_a = schema.examples) === null || _a === void 0 ? void 0 : _a[0]) !== undefined ||
|
|
42
|
+
schema.default !== undefined ||
|
|
43
|
+
('const' in schema && schema.const !== undefined) ||
|
|
44
|
+
('enum' in schema && Array.isArray(schema.enum) && schema.enum.length === 1)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return Object.keys(value).length < schema.minProperties;
|
|
51
|
+
};
|
|
52
|
+
export const generateExampleFromSchema = (schema, depth = 0, location) => {
|
|
36
53
|
var _a;
|
|
37
54
|
if (schema.example !== undefined) {
|
|
38
55
|
return schema.example;
|
|
@@ -69,17 +86,20 @@ export const generateExampleFromSchema = (schema, depth = 0) => {
|
|
|
69
86
|
const entries = Object.entries(schemaForExampleGeneration.properties)
|
|
70
87
|
// generate examples for all properties until depth reached - then only required properties
|
|
71
88
|
.filter(([_, [{ required }]]) => depth < MAX_DEPTH || required)
|
|
72
|
-
.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
.flatMap(([propName, [subschema]]) => {
|
|
90
|
+
const value = generateExampleFromSchema(subschema, depth + 1, location);
|
|
91
|
+
if (location === 'request' && shouldOmitOptionalObjectExample(subschema, value)) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
return [[propName, value]];
|
|
95
|
+
});
|
|
76
96
|
return Object.fromEntries(entries);
|
|
77
97
|
case 'array':
|
|
78
98
|
return depth < MAX_DEPTH
|
|
79
99
|
? [
|
|
80
100
|
generateExampleFromSchema(schemaForExampleGeneration.items[0],
|
|
81
101
|
// prevent the weird [{}] example value by counting array<object> as one level
|
|
82
|
-
schemaForExampleGeneration.items[0].type === 'object' ? depth : depth + 1),
|
|
102
|
+
schemaForExampleGeneration.items[0].type === 'object' ? depth : depth + 1, location),
|
|
83
103
|
]
|
|
84
104
|
: [];
|
|
85
105
|
}
|