radiant-docs 0.1.64 → 0.1.65
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/package.json +4 -3
- package/template/package-lock.json +1991 -4096
- package/template/package.json +7 -19
- package/template/src/components/OpenApiPage.astro +107 -18
- package/template/src/components/Sidebar.astro +1 -0
- package/template/src/components/endpoint/PlaygroundBar.astro +1 -1
- package/template/src/components/endpoint/PlaygroundField.astro +433 -71
- package/template/src/components/endpoint/PlaygroundForm.astro +470 -87
- package/template/src/components/endpoint/RequestSnippets.astro +6 -1
- package/template/src/components/endpoint/ResponseDisplay.astro +109 -2
- package/template/src/components/endpoint/ResponseFieldTree.astro +1 -1
- package/template/src/components/endpoint/ResponseFields.astro +97 -28
- package/template/src/components/endpoint/ResponseSnippets.astro +19 -7
- package/template/src/layouts/Layout.astro +94 -0
- package/template/src/lib/openapi/operation-doc.ts +308 -70
- package/template/src/lib/openapi/response-content.ts +133 -0
- package/template/src/lib/openapi/schema-variant-labels.ts +213 -0
- package/template/.vscode/extensions.json +0 -4
- package/template/.vscode/launch.json +0 -11
- package/template/scripts/generate-og-images.mjs +0 -667
- package/template/scripts/generate-og-metadata.mjs +0 -206
- package/template/scripts/generate-proxy-allowed-origins.mjs +0 -48
- package/template/scripts/generate-robots-txt.mjs +0 -47
- package/template/scripts/publish-shiki-platform-assets.mjs +0 -1177
- package/template/scripts/remove-assistant-for-non-pro.mjs +0 -28
- package/template/scripts/stamp-image-versions.mjs +0 -355
- package/template/scripts/stamp-og-image-versions.mjs +0 -199
- package/template/scripts/stamp-pagefind-runtime-version.mjs +0 -140
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
type ObjectPropertiesResolver = (schema: any) => Record<string, any>;
|
|
2
|
+
type TypeLabelResolver = (schema: any) => string;
|
|
3
|
+
|
|
4
|
+
interface SchemaVariantLabelOptions {
|
|
5
|
+
parentSchema?: any;
|
|
6
|
+
siblings?: any[];
|
|
7
|
+
getObjectProperties?: ObjectPropertiesResolver;
|
|
8
|
+
getTypeLabel?: TypeLabelResolver;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getSchemaVariants(schema: any): any[] {
|
|
12
|
+
if (!schema) return [];
|
|
13
|
+
if (Array.isArray(schema.oneOf)) return schema.oneOf;
|
|
14
|
+
if (Array.isArray(schema.anyOf)) return schema.anyOf;
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isNullSchema(schema: any): boolean {
|
|
19
|
+
if (!schema || typeof schema !== "object") return false;
|
|
20
|
+
if (schema.type === "null") return true;
|
|
21
|
+
return Array.isArray(schema.type) && schema.type.includes("null");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function unwrapNullableSchema(schema: any, seen = new Set<any>()): any {
|
|
25
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
26
|
+
if (seen.has(schema)) return schema;
|
|
27
|
+
|
|
28
|
+
const nextSeen = new Set(seen);
|
|
29
|
+
nextSeen.add(schema);
|
|
30
|
+
|
|
31
|
+
if (Array.isArray(schema.type) && schema.type.includes("null")) {
|
|
32
|
+
const nonNullTypes = schema.type.filter((type: string) => type !== "null");
|
|
33
|
+
if (nonNullTypes.length === 1) {
|
|
34
|
+
return unwrapNullableSchema(
|
|
35
|
+
{
|
|
36
|
+
...schema,
|
|
37
|
+
type: nonNullTypes[0],
|
|
38
|
+
},
|
|
39
|
+
nextSeen,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const variants = getSchemaVariants(schema);
|
|
45
|
+
const nonNullVariants = variants.filter((variant) => !isNullSchema(variant));
|
|
46
|
+
if (nonNullVariants.length === 1 && nonNullVariants.length < variants.length) {
|
|
47
|
+
return unwrapNullableSchema(nonNullVariants[0], nextSeen);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return schema;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getSchemaRefName(schema: any): string | undefined {
|
|
54
|
+
if (typeof schema?.$ref !== "string" || !schema.$ref.trim()) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const refParts = schema.$ref.split("/");
|
|
59
|
+
const refName = refParts[refParts.length - 1]?.trim();
|
|
60
|
+
if (!refName) return undefined;
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
return decodeURIComponent(refName);
|
|
64
|
+
} catch {
|
|
65
|
+
return refName;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getSingleLiteralValue(schema: any): string | undefined {
|
|
70
|
+
const renderSchema = unwrapNullableSchema(schema);
|
|
71
|
+
if (!renderSchema || typeof renderSchema !== "object") return undefined;
|
|
72
|
+
|
|
73
|
+
const constValue = renderSchema.const;
|
|
74
|
+
if (
|
|
75
|
+
typeof constValue === "string" ||
|
|
76
|
+
typeof constValue === "number" ||
|
|
77
|
+
typeof constValue === "boolean"
|
|
78
|
+
) {
|
|
79
|
+
return String(constValue);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (Array.isArray(renderSchema.enum) && renderSchema.enum.length === 1) {
|
|
83
|
+
const [enumValue] = renderSchema.enum;
|
|
84
|
+
if (
|
|
85
|
+
typeof enumValue === "string" ||
|
|
86
|
+
typeof enumValue === "number" ||
|
|
87
|
+
typeof enumValue === "boolean"
|
|
88
|
+
) {
|
|
89
|
+
return String(enumValue);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getDefaultObjectProperties(schema: any): Record<string, any> {
|
|
97
|
+
if (!schema || typeof schema !== "object") return {};
|
|
98
|
+
|
|
99
|
+
let properties: Record<string, any> = {};
|
|
100
|
+
if (schema.properties && typeof schema.properties === "object") {
|
|
101
|
+
properties = { ...properties, ...schema.properties };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (Array.isArray(schema.allOf)) {
|
|
105
|
+
schema.allOf.forEach((part: any) => {
|
|
106
|
+
properties = { ...properties, ...getDefaultObjectProperties(part) };
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return properties;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function getSingleLiteralPropertyLabels(
|
|
114
|
+
schema: any,
|
|
115
|
+
getObjectProperties: ObjectPropertiesResolver,
|
|
116
|
+
): Record<string, string> {
|
|
117
|
+
return Object.fromEntries(
|
|
118
|
+
Object.entries(getObjectProperties(schema))
|
|
119
|
+
.map(([name, propertySchema]) => [
|
|
120
|
+
name,
|
|
121
|
+
getSingleLiteralValue(propertySchema),
|
|
122
|
+
])
|
|
123
|
+
.filter((entry): entry is [string, string] => Boolean(entry[1])),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getDiscriminatorVariantLabel(
|
|
128
|
+
schema: any,
|
|
129
|
+
parentSchema: any,
|
|
130
|
+
getObjectProperties: ObjectPropertiesResolver,
|
|
131
|
+
): string | undefined {
|
|
132
|
+
const propertyName = parentSchema?.discriminator?.propertyName;
|
|
133
|
+
if (typeof propertyName !== "string" || !propertyName.trim()) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return getSingleLiteralPropertyLabels(schema, getObjectProperties)[
|
|
138
|
+
propertyName
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function getUniqueLiteralVariantLabel(
|
|
143
|
+
schema: any,
|
|
144
|
+
siblings: any[],
|
|
145
|
+
getObjectProperties: ObjectPropertiesResolver,
|
|
146
|
+
): string | undefined {
|
|
147
|
+
if (siblings.length < 2) return undefined;
|
|
148
|
+
|
|
149
|
+
const siblingLabels = siblings.map((variant) =>
|
|
150
|
+
getSingleLiteralPropertyLabels(variant, getObjectProperties),
|
|
151
|
+
);
|
|
152
|
+
const currentLabels = getSingleLiteralPropertyLabels(
|
|
153
|
+
schema,
|
|
154
|
+
getObjectProperties,
|
|
155
|
+
);
|
|
156
|
+
const preferredNames = ["type", "kind", "event", "object", "role"];
|
|
157
|
+
const propertyNames = Object.keys(currentLabels).sort((nameA, nameB) => {
|
|
158
|
+
const preferenceA = preferredNames.indexOf(nameA);
|
|
159
|
+
const preferenceB = preferredNames.indexOf(nameB);
|
|
160
|
+
if (preferenceA !== -1 || preferenceB !== -1) {
|
|
161
|
+
return (
|
|
162
|
+
(preferenceA === -1 ? Number.POSITIVE_INFINITY : preferenceA) -
|
|
163
|
+
(preferenceB === -1 ? Number.POSITIVE_INFINITY : preferenceB)
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return nameA.localeCompare(nameB);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
for (const propertyName of propertyNames) {
|
|
170
|
+
const labels = siblingLabels.map(
|
|
171
|
+
(labelsByName) => labelsByName[propertyName],
|
|
172
|
+
);
|
|
173
|
+
if (labels.some((label) => !label)) continue;
|
|
174
|
+
if (new Set(labels).size === siblings.length) {
|
|
175
|
+
return currentLabels[propertyName];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function getSchemaVariantLabel(
|
|
183
|
+
schema: any,
|
|
184
|
+
index: number,
|
|
185
|
+
options: SchemaVariantLabelOptions = {},
|
|
186
|
+
): string {
|
|
187
|
+
if (typeof schema?.title === "string" && schema.title.trim()) {
|
|
188
|
+
return schema.title.trim();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const refName = getSchemaRefName(schema);
|
|
192
|
+
if (refName) return refName;
|
|
193
|
+
|
|
194
|
+
const getObjectProperties =
|
|
195
|
+
options.getObjectProperties || getDefaultObjectProperties;
|
|
196
|
+
const discriminatorLabel = getDiscriminatorVariantLabel(
|
|
197
|
+
schema,
|
|
198
|
+
options.parentSchema,
|
|
199
|
+
getObjectProperties,
|
|
200
|
+
);
|
|
201
|
+
if (discriminatorLabel) return discriminatorLabel;
|
|
202
|
+
|
|
203
|
+
const uniqueLiteralLabel = getUniqueLiteralVariantLabel(
|
|
204
|
+
schema,
|
|
205
|
+
options.siblings || [],
|
|
206
|
+
getObjectProperties,
|
|
207
|
+
);
|
|
208
|
+
if (uniqueLiteralLabel) return uniqueLiteralLabel;
|
|
209
|
+
|
|
210
|
+
const typeLabel = options.getTypeLabel?.(schema);
|
|
211
|
+
if (typeLabel && typeLabel !== "unknown") return typeLabel;
|
|
212
|
+
return `Variant ${index + 1}`;
|
|
213
|
+
}
|