@salesforcedevs/docs-components 1.29.0-alpha1 → 1.29.0
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/LICENSE +12 -0
- package/lwc.config.json +2 -1
- package/package.json +28 -28
- package/src/modules/doc/amfReference/amfReference.ts +52 -10
- package/src/modules/doc/amfReference/types.ts +5 -0
- package/src/modules/doc/banner/banner.css +88 -0
- package/src/modules/doc/banner/banner.html +47 -0
- package/src/modules/doc/banner/banner.ts +73 -0
- package/src/modules/doc/contentLayout/contentLayout.html +1 -1
- package/src/modules/doc/contentLayout/contentLayout.ts +42 -0
- package/src/modules/doc/header/header.html +0 -1
- package/src/modules/doc/localeBanner/localeBanner.css +3 -0
- package/src/modules/doc/localeBanner/localeBanner.html +9 -0
- package/src/modules/doc/localeBanner/localeBanner.ts +195 -0
- package/src/modules/doc/lwcContentLayout/lwcContentLayout.html +5 -2
- package/src/modules/doc/redocReference/redocReference.ts +157 -121
- package/src/modules/doc/xmlContent/xmlContent.html +1 -1
- package/src/modules/doc/xmlContent/xmlContent.ts +28 -1
- package/src/modules/doc/apiPlayground/apiPlayground.css +0 -186
- package/src/modules/doc/apiPlayground/apiPlayground.html +0 -136
- package/src/modules/doc/apiPlayground/apiPlayground.ts +0 -240
- package/src/modules/docUtils/apiRequestExecutor/apiRequestExecutor.ts +0 -96
- package/src/modules/docUtils/openApiParser/openApiParser.ts +0 -187
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
export type ParameterDefinition = {
|
|
2
|
-
name: string;
|
|
3
|
-
in: "path" | "query" | "header" | "cookie";
|
|
4
|
-
required: boolean;
|
|
5
|
-
description: string;
|
|
6
|
-
schema: any;
|
|
7
|
-
example?: any;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type RequestBodyDefinition = {
|
|
11
|
-
description: string;
|
|
12
|
-
required: boolean;
|
|
13
|
-
content: Record<string, { schema: any }>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type OperationDefinition = {
|
|
17
|
-
operationId: string;
|
|
18
|
-
method: string;
|
|
19
|
-
path: string;
|
|
20
|
-
summary: string;
|
|
21
|
-
description: string;
|
|
22
|
-
parameters: ParameterDefinition[];
|
|
23
|
-
requestBody: RequestBodyDefinition | null;
|
|
24
|
-
responses: Record<string, any>;
|
|
25
|
-
tags: string[];
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export function resolveRef(ref: string, spec: any): any {
|
|
29
|
-
if (!ref || !ref.startsWith("#/")) {
|
|
30
|
-
return ref;
|
|
31
|
-
}
|
|
32
|
-
const parts = ref.replace("#/", "").split("/");
|
|
33
|
-
let current = spec;
|
|
34
|
-
for (const part of parts) {
|
|
35
|
-
current = current?.[part];
|
|
36
|
-
if (current === undefined) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return current;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function generateSampleFromSchema(schema: any, spec: any): any {
|
|
44
|
-
if (!schema) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (schema.$ref) {
|
|
49
|
-
return generateSampleFromSchema(resolveRef(schema.$ref, spec), spec);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (schema.example !== undefined) {
|
|
53
|
-
return schema.example;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (schema.default !== undefined) {
|
|
57
|
-
return schema.default;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (schema.enum && schema.enum.length > 0) {
|
|
61
|
-
return schema.enum[0];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
switch (schema.type) {
|
|
65
|
-
case "string":
|
|
66
|
-
return schema.format === "date"
|
|
67
|
-
? "2024-01-01"
|
|
68
|
-
: schema.format === "date-time"
|
|
69
|
-
? "2024-01-01T00:00:00Z"
|
|
70
|
-
: schema.format === "email"
|
|
71
|
-
? "user@example.com"
|
|
72
|
-
: schema.format === "uri"
|
|
73
|
-
? "https://example.com"
|
|
74
|
-
: "string";
|
|
75
|
-
case "integer":
|
|
76
|
-
return schema.minimum ?? 0;
|
|
77
|
-
case "number":
|
|
78
|
-
return schema.minimum ?? 0.0;
|
|
79
|
-
case "boolean":
|
|
80
|
-
return false;
|
|
81
|
-
case "array":
|
|
82
|
-
if (schema.items) {
|
|
83
|
-
return [generateSampleFromSchema(schema.items, spec)];
|
|
84
|
-
}
|
|
85
|
-
return [];
|
|
86
|
-
case "object": {
|
|
87
|
-
const result: Record<string, any> = {};
|
|
88
|
-
if (schema.properties) {
|
|
89
|
-
for (const [key, propSchema] of Object.entries(
|
|
90
|
-
schema.properties
|
|
91
|
-
)) {
|
|
92
|
-
result[key] = generateSampleFromSchema(
|
|
93
|
-
propSchema as any,
|
|
94
|
-
spec
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
default:
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function resolveParameter(param: any, spec: any): ParameterDefinition {
|
|
106
|
-
const resolved = param.$ref ? resolveRef(param.$ref, spec) : param;
|
|
107
|
-
return {
|
|
108
|
-
name: resolved.name ?? "",
|
|
109
|
-
in: resolved.in ?? "query",
|
|
110
|
-
required: resolved.required ?? false,
|
|
111
|
-
description: resolved.description ?? "",
|
|
112
|
-
schema: resolved.schema ?? {},
|
|
113
|
-
example: resolved.example
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function parseOpenApiSpec(spec: any): OperationDefinition[] {
|
|
118
|
-
if (!spec?.paths) {
|
|
119
|
-
return [];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const operations: OperationDefinition[] = [];
|
|
123
|
-
const httpMethods = [
|
|
124
|
-
"get",
|
|
125
|
-
"post",
|
|
126
|
-
"put",
|
|
127
|
-
"delete",
|
|
128
|
-
"patch",
|
|
129
|
-
"options",
|
|
130
|
-
"head"
|
|
131
|
-
];
|
|
132
|
-
|
|
133
|
-
for (const [path, pathItem] of Object.entries(spec.paths)) {
|
|
134
|
-
const pathObj = pathItem as any;
|
|
135
|
-
const pathLevelParams: any[] = pathObj.parameters ?? [];
|
|
136
|
-
|
|
137
|
-
for (const method of httpMethods) {
|
|
138
|
-
const operation = pathObj[method];
|
|
139
|
-
if (!operation) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const operationParams = (operation.parameters ?? []).map(
|
|
144
|
-
(p: any) => resolveParameter(p, spec)
|
|
145
|
-
);
|
|
146
|
-
const pathParams = pathLevelParams
|
|
147
|
-
.map((p: any) => resolveParameter(p, spec))
|
|
148
|
-
.filter(
|
|
149
|
-
(pp) =>
|
|
150
|
-
!operationParams.some(
|
|
151
|
-
(op: ParameterDefinition) => op.name === pp.name
|
|
152
|
-
)
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
const mergedParams = [...pathParams, ...operationParams];
|
|
156
|
-
|
|
157
|
-
let requestBody: RequestBodyDefinition | null = null;
|
|
158
|
-
if (operation.requestBody) {
|
|
159
|
-
const rb = operation.requestBody.$ref
|
|
160
|
-
? resolveRef(operation.requestBody.$ref, spec)
|
|
161
|
-
: operation.requestBody;
|
|
162
|
-
if (rb) {
|
|
163
|
-
requestBody = {
|
|
164
|
-
description: rb.description ?? "",
|
|
165
|
-
required: rb.required ?? false,
|
|
166
|
-
content: rb.content ?? {}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
operations.push({
|
|
172
|
-
operationId:
|
|
173
|
-
operation.operationId ?? `${method}_${path.replace(/\//g, "_")}`,
|
|
174
|
-
method: method.toUpperCase(),
|
|
175
|
-
path,
|
|
176
|
-
summary: operation.summary ?? "",
|
|
177
|
-
description: operation.description ?? "",
|
|
178
|
-
parameters: mergedParams,
|
|
179
|
-
requestBody,
|
|
180
|
-
responses: operation.responses ?? {},
|
|
181
|
-
tags: operation.tags ?? []
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return operations;
|
|
187
|
-
}
|