mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
OpenAPI: Show required label on body parameters
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-openapi': patch
|
||||
---
|
||||
|
||||
Show required label on body parameters
|
||||
@@ -7,7 +7,6 @@ import { Markdown } from './markdown';
|
||||
const keys: {
|
||||
[T in keyof OpenAPI.SchemaObject]: string;
|
||||
} = {
|
||||
example: 'Example',
|
||||
default: 'Default',
|
||||
minimum: 'Minimum',
|
||||
maximum: 'Maximum',
|
||||
@@ -64,21 +63,12 @@ export function Schema({
|
||||
(schema.writeOnly === true && !ctx.writeOnly)
|
||||
)
|
||||
return null;
|
||||
|
||||
const parseObject = ctx.parseObject ?? true;
|
||||
|
||||
const stack = ctx.stack ?? [];
|
||||
|
||||
const { renderer } = ctx.render;
|
||||
const child: ReactNode[] = [];
|
||||
|
||||
function field(key: string, value: string): void {
|
||||
child.push(
|
||||
<span key={key}>
|
||||
{key}: <code>{value}</code>
|
||||
</span>,
|
||||
);
|
||||
}
|
||||
|
||||
// object type
|
||||
if (isObject(schema) && parseObject) {
|
||||
const { additionalProperties, properties } = schema;
|
||||
@@ -130,20 +120,39 @@ export function Schema({
|
||||
|
||||
if (schema.description)
|
||||
child.push(<Markdown key="description" text={schema.description} />);
|
||||
|
||||
const fields: {
|
||||
key: string;
|
||||
value: string;
|
||||
}[] = [];
|
||||
|
||||
for (const [key, value] of Object.entries(keys)) {
|
||||
if (key in schema) {
|
||||
field(value, JSON.stringify(schema[key as keyof OpenAPI.SchemaObject]));
|
||||
fields.push({
|
||||
key: value,
|
||||
value: JSON.stringify(schema[key as keyof OpenAPI.SchemaObject]),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// enum types
|
||||
if (schema.enum) {
|
||||
field(
|
||||
'Value in',
|
||||
schema.enum.map((value) => JSON.stringify(value)).join(' | '),
|
||||
);
|
||||
fields.push({
|
||||
key: 'Value in',
|
||||
value: schema.enum.map((value) => JSON.stringify(value)).join(' | '),
|
||||
});
|
||||
}
|
||||
|
||||
if (fields.length > 0)
|
||||
child.push(
|
||||
<p key="fields">
|
||||
{fields.map((field) => (
|
||||
<span key={field.key}>
|
||||
{field.key}: <code>{field.value}</code>
|
||||
</span>
|
||||
))}
|
||||
</p>,
|
||||
);
|
||||
|
||||
if (isObject(schema) && !parseObject) {
|
||||
child.push(
|
||||
<renderer.ObjectCollapsible key="attributes" name="Attributes">
|
||||
@@ -208,6 +217,7 @@ export function Schema({
|
||||
<renderer.Property
|
||||
name={name}
|
||||
type={getSchemaType(schema, ctx)}
|
||||
required={ctx.required}
|
||||
deprecated={schema.deprecated}
|
||||
>
|
||||
{child}
|
||||
|
||||
Reference in New Issue
Block a user