mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
OpenAPI: Fix common parameters
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-openapi': patch
|
||||
---
|
||||
|
||||
Fix common parameters
|
||||
@@ -19,15 +19,15 @@ export function buildRoutes(
|
||||
): Map<string, RouteInformation[]> {
|
||||
const map = new Map<string, RouteInformation[]>();
|
||||
|
||||
for (const [path, value] of Object.entries(document.paths)) {
|
||||
if (!value) continue;
|
||||
for (const [path, pathItem] of Object.entries(document.paths)) {
|
||||
if (!pathItem) continue;
|
||||
const methodMap = new Map<string, MethodInformation[]>();
|
||||
|
||||
for (const methodKey of methodKeys) {
|
||||
const operation = value[methodKey];
|
||||
const operation = pathItem[methodKey];
|
||||
if (!operation) continue;
|
||||
|
||||
const info = createMethod(methodKey, operation);
|
||||
const info = createMethod(methodKey, pathItem, operation);
|
||||
const tags = operation.tags ?? [];
|
||||
|
||||
for (const tag of [...tags, 'all']) {
|
||||
@@ -40,7 +40,7 @@ export function buildRoutes(
|
||||
for (const [tag, methods] of methodMap.entries()) {
|
||||
const list = map.get(tag) ?? [];
|
||||
list.push({
|
||||
...value,
|
||||
...pathItem,
|
||||
path,
|
||||
methods,
|
||||
});
|
||||
|
||||
@@ -172,7 +172,7 @@ export function Schema({
|
||||
<renderer.ObjectCollapsible key="attributes" name={name}>
|
||||
<Schema
|
||||
name={name}
|
||||
schema={combineSchema(schema.allOf.map(noRef))}
|
||||
schema={combineSchema(noRef(schema.allOf))}
|
||||
ctx={{
|
||||
...ctx,
|
||||
parseObject: true,
|
||||
@@ -251,7 +251,7 @@ function combineSchema(schema: OpenAPI.SchemaObject[]): OpenAPI.SchemaObject {
|
||||
}
|
||||
|
||||
if (s.allOf) {
|
||||
add(combineSchema(s.allOf.map(noRef)));
|
||||
add(combineSchema(noRef(s.allOf)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
import type { OpenAPIV3 as OpenAPI } from 'openapi-types';
|
||||
import type { MethodInformation } from '@/types';
|
||||
import { noRef } from '@/utils/schema';
|
||||
|
||||
/**
|
||||
* Summarize method endpoint information
|
||||
*/
|
||||
export function createMethod(
|
||||
method: string,
|
||||
path: OpenAPI.PathItemObject,
|
||||
operation: OpenAPI.OperationObject,
|
||||
): MethodInformation {
|
||||
return {
|
||||
description: path.description,
|
||||
summary: path.summary,
|
||||
...operation,
|
||||
parameters: (operation.parameters ?? []) as OpenAPI.ParameterObject[],
|
||||
parameters: [
|
||||
...noRef(operation.parameters ?? []),
|
||||
...noRef(path.parameters ?? []),
|
||||
],
|
||||
method: method.toUpperCase(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -46,9 +46,13 @@ export async function APIPage(props: ApiPageProps): Promise<ReactElement> {
|
||||
return (
|
||||
<ctx.renderer.Root baseUrl={ctx.baseUrl}>
|
||||
{operations.map((item) => {
|
||||
const operation = document.paths[item.path]?.[item.method];
|
||||
const pathItem = document.paths[item.path];
|
||||
if (!pathItem) return null;
|
||||
|
||||
const operation = pathItem[item.method];
|
||||
if (!operation) return null;
|
||||
const method = createMethod(item.method, operation);
|
||||
|
||||
const method = createMethod(item.method, pathItem, operation);
|
||||
|
||||
return (
|
||||
<Operation
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { OpenAPIV3 as OpenAPI } from 'openapi-types';
|
||||
|
||||
type NoReference<T> = Exclude<T, OpenAPI.ReferenceObject>;
|
||||
type NoReference<T> = T extends (infer I)[]
|
||||
? NoReference<I>[]
|
||||
: Exclude<T, OpenAPI.ReferenceObject>;
|
||||
|
||||
export function noRef<T>(v: T): NoReference<T> {
|
||||
return v as NoReference<T>;
|
||||
|
||||
Reference in New Issue
Block a user