@mintlify/common 1.0.341 → 1.0.342
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,6 +1,7 @@
|
|
|
1
1
|
import { MessageInterface, AnyRecord, AsyncApiExtension } from '../../types/asyncapi.js';
|
|
2
|
-
export declare const getExamplesData: ({ message, payloadSchema, extensions, }: {
|
|
2
|
+
export declare const getExamplesData: ({ message, jsonSchema, payloadSchema, extensions, }: {
|
|
3
3
|
message: MessageInterface;
|
|
4
|
-
|
|
4
|
+
jsonSchema: AnyRecord;
|
|
5
|
+
payloadSchema: AnyRecord | undefined;
|
|
5
6
|
extensions: AsyncApiExtension[];
|
|
6
7
|
}) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { generateExampleFromSchema } from '@mintlify/validation';
|
|
2
|
-
export const getExamplesData = ({ message, payloadSchema, extensions, }) => {
|
|
3
|
-
var _a, _b;
|
|
2
|
+
export const getExamplesData = ({ message, jsonSchema, payloadSchema, extensions, }) => {
|
|
3
|
+
var _a, _b, _c;
|
|
4
4
|
const id = message.id().toLowerCase();
|
|
5
5
|
const examples = message.examples();
|
|
6
6
|
const hasInlineExamples = examples.length > 0;
|
|
@@ -8,13 +8,28 @@ export const getExamplesData = ({ message, payloadSchema, extensions, }) => {
|
|
|
8
8
|
const example = (_b = (_a = examples[0]) === null || _a === void 0 ? void 0 : _a['_json']) === null || _b === void 0 ? void 0 : _b['payload'];
|
|
9
9
|
return JSON.stringify(example, null, 2);
|
|
10
10
|
}
|
|
11
|
+
const jsonExamples = (_c = jsonSchema['schema']) === null || _c === void 0 ? void 0 : _c['examples'];
|
|
12
|
+
const hasJsonExamples = jsonExamples && jsonExamples.length > 0;
|
|
13
|
+
if (hasJsonExamples) {
|
|
14
|
+
return JSON.stringify(jsonExamples[0], null, 2);
|
|
15
|
+
}
|
|
11
16
|
const extensionExamples = createMessageExamplesMap(extensions);
|
|
12
17
|
const hasExtensionExamples = extensionExamples.has(id);
|
|
13
18
|
if (hasExtensionExamples) {
|
|
14
19
|
return JSON.stringify(extensionExamples.get(id), null, 2);
|
|
15
20
|
}
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
if (payloadSchema) {
|
|
22
|
+
const generatedExample = generateMessageExample(payloadSchema);
|
|
23
|
+
if (generatedExample) {
|
|
24
|
+
return JSON.stringify(generatedExample, null, 2);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return 'No examples found';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return 'No examples found';
|
|
32
|
+
}
|
|
18
33
|
};
|
|
19
34
|
const generateMessageExample = (payloadSchema) => {
|
|
20
35
|
const schema = {
|
|
@@ -48,8 +63,14 @@ const generateMessageExample = (payloadSchema) => {
|
|
|
48
63
|
return acc;
|
|
49
64
|
}, {}),
|
|
50
65
|
};
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
try {
|
|
67
|
+
const example = generateExampleFromSchema(schema, 0);
|
|
68
|
+
return example;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error('Error generating example from schema', error);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
53
74
|
};
|
|
54
75
|
const createMessageExamplesMap = (extensions) => {
|
|
55
76
|
const examplesMap = new Map();
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { AnyRecord, AsyncApiMessage, AsyncApiExtension, MessageInterface } from '../../types/asyncapi.js';
|
|
2
2
|
export declare const getMessagesData: (messages: MessageInterface[], extensions: AsyncApiExtension[]) => AsyncApiMessage[];
|
|
3
|
-
export declare const getMessagePayloadSchema: (title: string, description: string | undefined, payload: AnyRecord) =>
|
|
4
|
-
name: string;
|
|
5
|
-
description: string | undefined;
|
|
6
|
-
type: string | undefined;
|
|
7
|
-
properties: import("../../types/asyncapi.js").SchemaProperty[] | undefined;
|
|
8
|
-
}[];
|
|
3
|
+
export declare const getMessagePayloadSchema: (title: string, description: string | undefined, payload: AnyRecord) => any[] | undefined;
|
|
@@ -13,11 +13,7 @@ export const getMessagesData = (messages, extensions) => {
|
|
|
13
13
|
const payload = (_d = message.payload()) === null || _d === void 0 ? void 0 : _d['_json'];
|
|
14
14
|
const headers = (_e = message.headers()) === null || _e === void 0 ? void 0 : _e['_json'];
|
|
15
15
|
const payloadSchema = getMessagePayloadSchema(title, description, payload);
|
|
16
|
-
const example = getExamplesData({
|
|
17
|
-
message,
|
|
18
|
-
payloadSchema,
|
|
19
|
-
extensions,
|
|
20
|
-
});
|
|
16
|
+
const example = getExamplesData({ message, jsonSchema: payload, payloadSchema, extensions });
|
|
21
17
|
return {
|
|
22
18
|
id,
|
|
23
19
|
contentType: message.contentType(),
|
|
@@ -33,23 +29,37 @@ export const getMessagesData = (messages, extensions) => {
|
|
|
33
29
|
};
|
|
34
30
|
});
|
|
35
31
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const requiredAndProperties = Object.assign(Object.assign({}, schemaProperties), { required: schemaRequired });
|
|
41
|
-
const properties = requiredAndProperties
|
|
42
|
-
? extractSchemaProperties(requiredAndProperties)
|
|
43
|
-
: undefined;
|
|
44
|
-
const schema = [
|
|
32
|
+
const expandObjectSchema = (title, description, schema, requiredProperties) => {
|
|
33
|
+
const schemaWithRequiredAndProperties = Object.assign(Object.assign({}, schema), { required: requiredProperties });
|
|
34
|
+
const properties = extractSchemaProperties(schemaWithRequiredAndProperties);
|
|
35
|
+
const expandedSchema = [
|
|
45
36
|
{
|
|
46
37
|
name: title,
|
|
47
38
|
description,
|
|
48
|
-
type:
|
|
39
|
+
type: 'object',
|
|
49
40
|
properties,
|
|
50
41
|
},
|
|
51
42
|
];
|
|
52
|
-
return
|
|
43
|
+
return expandedSchema;
|
|
44
|
+
};
|
|
45
|
+
export const getMessagePayloadSchema = (title, description, payload) => {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
const objectSchema = payload.properties || ((_a = payload['schema']) === null || _a === void 0 ? void 0 : _a.properties);
|
|
48
|
+
const unknownTypeSchema = payload['schema'] || payload;
|
|
49
|
+
const schemaRequired = payload.required || ((_b = payload['schema']) === null || _b === void 0 ? void 0 : _b.required);
|
|
50
|
+
if (objectSchema) {
|
|
51
|
+
return expandObjectSchema(title, description, objectSchema, schemaRequired);
|
|
52
|
+
}
|
|
53
|
+
else if (unknownTypeSchema) {
|
|
54
|
+
if (unknownTypeSchema.type === 'object') {
|
|
55
|
+
return expandObjectSchema(title, description, unknownTypeSchema, schemaRequired);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return [
|
|
59
|
+
Object.assign(Object.assign({}, unknownTypeSchema), { name: title, description, type: unknownTypeSchema.type || undefined }),
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
53
63
|
};
|
|
54
64
|
const getMessageHeaders = (headers) => {
|
|
55
65
|
if (!headers)
|