mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 06:31:49 +00:00
OpenAPI: no longer generate default values for optional params
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-openapi': patch
|
||||
---
|
||||
|
||||
no longer generate default values for optional params
|
||||
@@ -20,31 +20,41 @@ export function getRequestData(
|
||||
|
||||
for (const param of method.parameters ?? []) {
|
||||
let schema = param.schema;
|
||||
let value;
|
||||
let value: unknown | undefined;
|
||||
|
||||
if (!schema && param.content) {
|
||||
const type = getPreferredType(param.content);
|
||||
|
||||
const content = type ? param.content[type] : undefined;
|
||||
if (!content)
|
||||
if (!content || !content.schema)
|
||||
throw new Error(
|
||||
`Cannot find parameter schema for ${param.name} in ${path} ${method.method}`,
|
||||
);
|
||||
|
||||
schema = content.schema;
|
||||
value = content.example ?? param.example ?? sample(schema as object);
|
||||
value = content.example ?? param.example;
|
||||
} else {
|
||||
value = param.example ?? sample(schema as object);
|
||||
value = param.example;
|
||||
}
|
||||
|
||||
if (param.in === 'cookie') {
|
||||
result.cookie[param.name] = value;
|
||||
} else if (param.in === 'header') {
|
||||
result.header[param.name] = value;
|
||||
} else if (param.in === 'query') {
|
||||
result.query[param.name] = value;
|
||||
} else if (param.in === 'path') {
|
||||
result.path[param.name] = value;
|
||||
if (param.required) {
|
||||
value ??= sample(schema as object);
|
||||
} else if (value === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (param.in) {
|
||||
case 'cookie':
|
||||
result.cookie[param.name] = value;
|
||||
break;
|
||||
case 'header':
|
||||
result.header[param.name] = value;
|
||||
break;
|
||||
case 'query':
|
||||
result.query[param.name] = value;
|
||||
break;
|
||||
default:
|
||||
result.path[param.name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from 'react';
|
||||
import { useActiveAnchors } from 'fumadocs-core/toc';
|
||||
|
||||
export type TOCThumb = [top: number, height: number];
|
||||
type TocThumb = [top: number, height: number];
|
||||
|
||||
interface RefProps {
|
||||
containerRef: RefObject<HTMLElement | null>;
|
||||
@@ -38,8 +38,6 @@ function Updater({
|
||||
update(thumbRef.current, calc(containerRef.current, active));
|
||||
});
|
||||
|
||||
useEffect(() => onPrint(), [active]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef.current) return;
|
||||
const container = containerRef.current;
|
||||
@@ -52,10 +50,14 @@ function Updater({
|
||||
};
|
||||
}, [containerRef]);
|
||||
|
||||
if (containerRef.current && thumbRef.current) {
|
||||
update(thumbRef.current, calc(containerRef.current, active));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function calc(container: HTMLElement, active: string[]): TOCThumb {
|
||||
function calc(container: HTMLElement, active: string[]): TocThumb {
|
||||
if (active.length === 0 || container.clientHeight === 0) {
|
||||
return [0, 0];
|
||||
}
|
||||
@@ -80,7 +82,7 @@ function calc(container: HTMLElement, active: string[]): TOCThumb {
|
||||
return [upper, lower - upper];
|
||||
}
|
||||
|
||||
function update(element: HTMLElement, info: TOCThumb): void {
|
||||
function update(element: HTMLElement, info: TocThumb): void {
|
||||
element.style.setProperty('--fd-top', `${info[0]}px`);
|
||||
element.style.setProperty('--fd-height', `${info[1]}px`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user