Skip to content

Commit 9fa2940

Browse files
committed
Wired up optionality
1 parent e2be55c commit 9fa2940

File tree

1 file changed

+14
-2
lines changed
  • packages/docs-md/src/generator/mdx/chunks

1 file changed

+14
-2
lines changed

packages/docs-md/src/generator/mdx/chunks/schema.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,24 +273,29 @@ function renderSchemaFrontmatter({
273273
baseHeadingLevel,
274274
propertyName,
275275
displayType,
276+
isOptional,
276277
}: {
277278
renderer: Renderer;
278279
schema: SchemaValue;
279280
baseHeadingLevel: number;
280281
propertyName: string;
281282
displayType: DisplayType;
283+
isOptional: boolean;
282284
}) {
283285
const computedDisplayType = computeDisplayType(
284286
displayType.typeLabel,
285287
propertyName
286288
);
289+
const propertyNameWithOptional = isOptional
290+
? `${propertyName} (optional)`
291+
: propertyName;
287292
if (computedDisplayType.multiline) {
288-
renderer.appendHeading(baseHeadingLevel, propertyName);
293+
renderer.appendHeading(baseHeadingLevel, propertyNameWithOptional);
289294
renderer.appendParagraph(`\`\`\`\n${computedDisplayType.content}\n\`\`\``);
290295
} else {
291296
renderer.appendHeading(
292297
baseHeadingLevel,
293-
`${renderer.escapeText(propertyName)}: \`${computedDisplayType.content}\``,
298+
`${renderer.escapeText(propertyNameWithOptional)}: \`${computedDisplayType.content}\``,
294299
{ escape: false }
295300
);
296301
}
@@ -372,6 +377,7 @@ export function renderSchema({
372377
isOpenOnLoad,
373378
});
374379
for (const [key, value] of Object.entries(objectValue.properties)) {
380+
const isOptional = objectValue.required?.includes(key) === false;
375381
if (value.type === "chunk") {
376382
const schemaChunk = getSchemaFromId(value.chunkId, data);
377383
const schema = schemaChunk.chunkData.value;
@@ -382,6 +388,7 @@ export function renderSchema({
382388
baseHeadingLevel,
383389
propertyName: key,
384390
displayType,
391+
isOptional,
385392
});
386393
renderSchemaBreakouts({
387394
renderer,
@@ -399,6 +406,7 @@ export function renderSchema({
399406
baseHeadingLevel,
400407
propertyName: key,
401408
displayType,
409+
isOptional,
402410
});
403411
} else {
404412
const displayType = getDisplayType(value, data);
@@ -408,6 +416,7 @@ export function renderSchema({
408416
baseHeadingLevel,
409417
propertyName: key,
410418
displayType,
419+
isOptional,
411420
});
412421
}
413422
}
@@ -424,6 +433,7 @@ export function renderSchema({
424433
baseHeadingLevel,
425434
propertyName: topLevelName,
426435
displayType,
436+
isOptional: false,
427437
});
428438
}
429439

@@ -435,6 +445,7 @@ export function renderSchema({
435445
baseHeadingLevel,
436446
propertyName: topLevelName,
437447
displayType,
448+
isOptional: false,
438449
});
439450
return;
440451
}
@@ -447,6 +458,7 @@ export function renderSchema({
447458
baseHeadingLevel,
448459
propertyName: topLevelName,
449460
displayType,
461+
isOptional: false,
450462
});
451463
}
452464

0 commit comments

Comments
 (0)