Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ function createItems(
jsonRequestBodyExample,
info: openapiData.info,
},
position: operationObject["x-position"] as number | undefined,
};

items.push(apiPage);
Expand Down Expand Up @@ -509,6 +510,22 @@ function createItems(
});
}

items.sort((a, b) => {
// Items with position come first, sorted by position
if (a.position !== undefined && b.position !== undefined) {
return a.position - b.position;
}
// Items with position come before items without position
if (a.position !== undefined) {
return -1;
}
if (b.position !== undefined) {
return 1;
}
// If neither has position, maintain original order
return 0;
});

return items as ApiMetadata[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ export interface OperationObject {
deprecated?: boolean;
security?: SecurityRequirementObject[];
servers?: ServerObject[];

// extensions
"x-position"?: number;
"x-deprecated-description"?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface OpenAPIOperation {
servers?: OpenAPIServer[];
"x-codeSamples"?: OpenAPIXCodeSample[];
"x-code-samples"?: OpenAPIXCodeSample[]; // deprecated
"x-position"?: number;
}

export interface OpenAPIParameter {
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-openapi-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export interface ApiMetadataBase {
frontMatter: Record<string, unknown>;
method?: string;
path?: string;
position?: number;
}

export interface ApiPageMetadata extends ApiMetadataBase {
Expand Down