Skip to content

Commit 3421242

Browse files
rsbhclaude
andauthored
feat: show example values in API fields, increase section spacing (#60)
- Add example field to SchemaField from OpenAPI schema examples - Display example values inline with field description - Increase divider margin between sections for better readability Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 682ce9f commit 3421242

6 files changed

Lines changed: 24 additions & 4 deletions

File tree

packages/chronicle/src/components/api/api-field-list.module.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@
3030
color: var(--rs-color-foreground-base-secondary);
3131
}
3232

33+
.fieldExample {
34+
font-size: var(--rs-font-size-small);
35+
line-height: var(--rs-line-height-small);
36+
color: var(--rs-color-foreground-base-tertiary);
37+
}
38+
39+
.fieldExample code {
40+
font-family: var(--rs-font-mono);
41+
font-size: var(--rs-font-size-mono-small);
42+
background: var(--rs-color-background-neutral-secondary);
43+
padding: 1px var(--rs-space-2);
44+
border-radius: 3px;
45+
}
46+
3347
.statusDescription {
3448
font-size: var(--rs-font-size-regular);
3549
line-height: var(--rs-line-height-regular);

packages/chronicle/src/components/api/api-field-list.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ function FieldItem({ field }: { field: SchemaField }) {
4444
<Flex align="center" gap={3}>
4545
<Badge variant="neutral" size="micro">{field.name}</Badge>
4646
<span className={styles.fieldType}>{field.type}</span>
47+
{field.required && <Badge variant="danger" size="micro">required</Badge>}
4748
</Flex>
4849
{field.description && (
4950
<span className={styles.fieldDescription}>{field.description}</span>
5051
)}
52+
{field.example !== undefined && (
53+
<span className={styles.fieldExample}>Example: <code>{JSON.stringify(field.example)}</code></span>
54+
)}
5155
{hasChildren && <ExpandableChildren field={field} />}
5256
</Flex>
5357
)

packages/chronicle/src/components/api/api-overview.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
.divider {
5151
padding: 0;
52-
margin: var(--rs-space-2) 0;
52+
margin: var(--rs-space-4) 0;
5353
}
5454

5555
@media (max-width: 1100px) {

packages/chronicle/src/components/api/api-overview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function ApiOverview({ method, path, operation, auth }: ApiOverviewProps)
4747

4848
return (
4949
<Flex className={styles.layout}>
50-
<Flex direction='column' gap={10} className={styles.left}>
50+
<Flex direction='column' gap={9} className={styles.left}>
5151
<Flex direction='column' gap={7}>
5252
<Flex direction='column' gap={4}>
5353
{operation.summary && (

packages/chronicle/src/components/api/playground-dialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ function BodyFieldRow({ field, value, onChange }: {
486486
return (
487487
<div className={styles.arrayField}>
488488
<div className={styles.fieldRow}>
489-
<span className={styles.fieldLabel}>{field.name}</span>
489+
<span className={styles.fieldLabel}>{field.name} {field.required && <Badge variant="danger" size="micro">required</Badge>}</span>
490490
<IconButton size={2} onClick={() => onChange([...items, ''])} aria-label="Add item">
491491
<PlusIcon />
492492
</IconButton>
@@ -537,7 +537,7 @@ function BodyFieldRow({ field, value, onChange }: {
537537

538538
return (
539539
<div className={styles.fieldRow}>
540-
<span className={styles.fieldLabel}>{field.name}</span>
540+
<span className={styles.fieldLabel}>{field.name} {field.required && <Badge variant="danger" size="micro">required</Badge>}</span>
541541
<div className={styles.fieldInput}>
542542
<InputField
543543
size="small"

packages/chronicle/src/lib/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface SchemaField {
1919
required: boolean
2020
description?: string
2121
default?: unknown
22+
example?: unknown
2223
enum?: unknown[]
2324
children?: SchemaField[]
2425
}
@@ -90,6 +91,7 @@ export function flattenSchema(
9091
required: required.includes(name),
9192
description: rawProp.description ?? prop.description,
9293
default: prop.default,
94+
example: prop.example,
9395
enum: prop.enum,
9496
children: children?.length ? children : undefined,
9597
}

0 commit comments

Comments
 (0)