Skip to content

Commit 5fb1191

Browse files
authored
[Enhancement] Add vendor extension support for positioning sidebar items (PaloAltoNetworks#1160)
* Add support for x-position vendor extension and sorting logic * Add position and x-position types
1 parent 8997017 commit 5fb1191

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ function createItems(
263263
jsonRequestBodyExample,
264264
info: openapiData.info,
265265
},
266+
position: operationObject["x-position"] as number | undefined,
266267
};
267268

268269
items.push(apiPage);
@@ -509,6 +510,22 @@ function createItems(
509510
});
510511
}
511512

513+
items.sort((a, b) => {
514+
// Items with position come first, sorted by position
515+
if (a.position !== undefined && b.position !== undefined) {
516+
return a.position - b.position;
517+
}
518+
// Items with position come before items without position
519+
if (a.position !== undefined) {
520+
return -1;
521+
}
522+
if (b.position !== undefined) {
523+
return 1;
524+
}
525+
// If neither has position, maintain original order
526+
return 0;
527+
});
528+
512529
return items as ApiMetadata[];
513530
}
514531

packages/docusaurus-plugin-openapi-docs/src/openapi/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ export interface OperationObject {
156156
deprecated?: boolean;
157157
security?: SecurityRequirementObject[];
158158
servers?: ServerObject[];
159-
160159
// extensions
160+
"x-position"?: number;
161161
"x-deprecated-description"?: string;
162162
}
163163

packages/docusaurus-plugin-openapi-docs/src/openapi/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export interface OpenAPIOperation {
8989
servers?: OpenAPIServer[];
9090
"x-codeSamples"?: OpenAPIXCodeSample[];
9191
"x-code-samples"?: OpenAPIXCodeSample[]; // deprecated
92+
"x-position"?: number;
9293
}
9394

9495
export interface OpenAPIParameter {

packages/docusaurus-plugin-openapi-docs/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export interface ApiMetadataBase {
118118
frontMatter: Record<string, unknown>;
119119
method?: string;
120120
path?: string;
121+
position?: number;
121122
}
122123

123124
export interface ApiPageMetadata extends ApiMetadataBase {

0 commit comments

Comments
 (0)