Skip to content

Commit 7765e7e

Browse files
committed
apply changes to ParamsItem
1 parent e941b41 commit 7765e7e

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

packages/docusaurus-theme-openapi-docs/src/theme/ParamsItem/index.tsx

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ function ParamsItem({ param, ...rest }: Props) {
7676
schema = { type: "any" };
7777
}
7878

79+
let defaultValue: string | undefined;
80+
81+
if (
82+
schema && schema.items
83+
? schema.items.default
84+
: schema
85+
? schema.default
86+
: undefined
87+
) {
88+
}
89+
90+
if (schema) {
91+
if (schema.items) {
92+
defaultValue = schema.items.default;
93+
}
94+
defaultValue = schema.default;
95+
}
96+
7997
const renderSchemaName = guard(schema, (schema) => (
8098
<span className="openapi-schema__type"> {getSchemaName(schema)}</span>
8199
));
@@ -131,18 +149,29 @@ function ParamsItem({ param, ...rest }: Props) {
131149
}
132150
);
133151

134-
const renderDefaultValue = guard(
135-
schema && schema.items
136-
? schema.items.default
137-
: schema
138-
? schema.default
139-
: undefined,
140-
(value) => (
141-
<div>
142-
<ReactMarkdown children={`**Default value:** \`${value}\``} />
143-
</div>
144-
)
145-
);
152+
function renderDefaultValue() {
153+
if (defaultValue !== undefined) {
154+
if (typeof defaultValue === "string") {
155+
return (
156+
<div>
157+
<strong>Default value: </strong>
158+
<span>
159+
<code>{defaultValue}</code>
160+
</span>
161+
</div>
162+
);
163+
}
164+
return (
165+
<div>
166+
<strong>Default value: </strong>
167+
<span>
168+
<code>{JSON.stringify(defaultValue)}</code>
169+
</span>
170+
</div>
171+
);
172+
}
173+
return undefined;
174+
}
146175

147176
const renderExample = guard(toString(example), (example) => (
148177
<div>
@@ -196,7 +225,7 @@ function ParamsItem({ param, ...rest }: Props) {
196225
{renderDeprecated}
197226
</span>
198227
{renderSchema}
199-
{renderDefaultValue}
228+
{renderDefaultValue()}
200229
{renderDescription}
201230
{renderEnumDescriptions}
202231
{renderExample}

packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,19 @@ export default function SchemaItem(props: Props) {
138138
if (typeof defaultValue === "string") {
139139
return (
140140
<div>
141-
<strong>
142-
Default value:{" "}
143-
<span>
144-
<code>{defaultValue}</code>
145-
</span>
146-
</strong>
141+
<strong>Default value: </strong>
142+
<span>
143+
<code>{defaultValue}</code>
144+
</span>
147145
</div>
148146
);
149147
}
150148
return (
151149
<div>
152-
<strong>
153-
Default value:{" "}
154-
<span>
155-
<code>{JSON.stringify(defaultValue)}</code>
156-
</span>
157-
</strong>
150+
<strong>Default value: </strong>
151+
<span>
152+
<code>{JSON.stringify(defaultValue)}</code>
153+
</span>
158154
</div>
159155
);
160156
}

0 commit comments

Comments
 (0)