docusaurus-plugin-openapi-docs 0.0.0-1006 → 0.0.0-1008

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -147,10 +147,10 @@ const sampleRequestFromSchema = (schema = {}) => {
147
147
  }
148
148
  if (type === "array") {
149
149
  if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
150
- return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleRequestFromSchema)(item));
150
+ return processArrayItems(items, "anyOf");
151
151
  }
152
152
  if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
153
- return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleRequestFromSchema)(item));
153
+ return processArrayItems(items, "oneOf");
154
154
  }
155
155
  return normalizeArray((0, exports.sampleRequestFromSchema)(items));
156
156
  }
@@ -192,3 +192,22 @@ function normalizeArray(arr) {
192
192
  }
193
193
  return [arr];
194
194
  }
195
+ function processArrayItems(items, schemaType) {
196
+ const itemsArray = items[schemaType];
197
+ return itemsArray.map((item) => {
198
+ // If items has properties, merge them with each item
199
+ if (items.properties) {
200
+ const combinedSchema = {
201
+ ...item,
202
+ properties: {
203
+ ...items.properties, // Common properties from parent
204
+ ...item.properties, // Specific properties from this anyOf/oneOf item
205
+ },
206
+ };
207
+ // Remove anyOf/oneOf to prevent infinite recursion when calling sampleRequestFromSchema
208
+ delete combinedSchema[schemaType];
209
+ return (0, exports.sampleRequestFromSchema)(combinedSchema);
210
+ }
211
+ return (0, exports.sampleRequestFromSchema)(item);
212
+ });
213
+ }
@@ -148,10 +148,10 @@ const sampleResponseFromSchema = (schema = {}) => {
148
148
  }
149
149
  if (type === "array") {
150
150
  if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
151
- return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleResponseFromSchema)(item));
151
+ return processArrayItems(items, "anyOf");
152
152
  }
153
153
  if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
154
- return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleResponseFromSchema)(item));
154
+ return processArrayItems(items, "oneOf");
155
155
  }
156
156
  return [(0, exports.sampleResponseFromSchema)(items)];
157
157
  }
@@ -193,3 +193,22 @@ function normalizeArray(arr) {
193
193
  }
194
194
  return [arr];
195
195
  }
196
+ function processArrayItems(items, schemaType) {
197
+ const itemsArray = items[schemaType];
198
+ return itemsArray.map((item) => {
199
+ // If items has properties, merge them with each item
200
+ if (items.properties) {
201
+ const combinedSchema = {
202
+ ...item,
203
+ properties: {
204
+ ...items.properties, // Common properties from parent
205
+ ...item.properties, // Specific properties from this anyOf/oneOf item
206
+ },
207
+ };
208
+ // Remove anyOf/oneOf to prevent infinite recursion when calling sampleResponseFromSchema
209
+ delete combinedSchema[schemaType];
210
+ return (0, exports.sampleResponseFromSchema)(combinedSchema);
211
+ }
212
+ return (0, exports.sampleResponseFromSchema)(item);
213
+ });
214
+ }
@@ -211,6 +211,7 @@ function createItems(openapiData, options, sidebarOptions) {
211
211
  jsonRequestBodyExample,
212
212
  info: openapiData.info,
213
213
  },
214
+ position: operationObject["x-position"],
214
215
  };
215
216
  items.push(apiPage);
216
217
  }
@@ -406,6 +407,21 @@ function createItems(openapiData, options, sidebarOptions) {
406
407
  items.push(tagPage);
407
408
  });
408
409
  }
410
+ items.sort((a, b) => {
411
+ // Items with position come first, sorted by position
412
+ if (a.position !== undefined && b.position !== undefined) {
413
+ return a.position - b.position;
414
+ }
415
+ // Items with position come before items without position
416
+ if (a.position !== undefined) {
417
+ return -1;
418
+ }
419
+ if (b.position !== undefined) {
420
+ return 1;
421
+ }
422
+ // If neither has position, maintain original order
423
+ return 0;
424
+ });
409
425
  return items;
410
426
  }
411
427
  /**
@@ -128,6 +128,7 @@ export interface OperationObject {
128
128
  deprecated?: boolean;
129
129
  security?: SecurityRequirementObject[];
130
130
  servers?: ServerObject[];
131
+ "x-position"?: number;
131
132
  "x-deprecated-description"?: string;
132
133
  }
133
134
  export interface OperationObjectWithRef {
@@ -76,6 +76,7 @@ export interface OpenAPIOperation {
76
76
  servers?: OpenAPIServer[];
77
77
  "x-codeSamples"?: OpenAPIXCodeSample[];
78
78
  "x-code-samples"?: OpenAPIXCodeSample[];
79
+ "x-position"?: number;
79
80
  }
80
81
  export interface OpenAPIParameter {
81
82
  name: string;
package/lib/types.d.ts CHANGED
@@ -85,6 +85,7 @@ export interface ApiMetadataBase {
85
85
  frontMatter: Record<string, unknown>;
86
86
  method?: string;
87
87
  path?: string;
88
+ position?: number;
88
89
  }
89
90
  export interface ApiPageMetadata extends ApiMetadataBase {
90
91
  json?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "0.0.0-1006",
4
+ "version": "0.0.0-1008",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -65,5 +65,5 @@
65
65
  "engines": {
66
66
  "node": ">=14"
67
67
  },
68
- "gitHead": "e73c0b0cead279cb3771b546adc1caebabf336ae"
68
+ "gitHead": "d50a1409c5b6097064616bac66c5a079431c61de"
69
69
  }
@@ -178,11 +178,11 @@ export const sampleRequestFromSchema = (schema: SchemaObject = {}): any => {
178
178
 
179
179
  if (type === "array") {
180
180
  if (Array.isArray(items?.anyOf)) {
181
- return items?.anyOf.map((item: any) => sampleRequestFromSchema(item));
181
+ return processArrayItems(items, "anyOf");
182
182
  }
183
183
 
184
184
  if (Array.isArray(items?.oneOf)) {
185
- return items?.oneOf.map((item: any) => sampleRequestFromSchema(item));
185
+ return processArrayItems(items, "oneOf");
186
186
  }
187
187
 
188
188
  return normalizeArray(sampleRequestFromSchema(items));
@@ -237,3 +237,26 @@ function normalizeArray(arr: any) {
237
237
  }
238
238
  return [arr];
239
239
  }
240
+
241
+ function processArrayItems(
242
+ items: SchemaObject,
243
+ schemaType: "anyOf" | "oneOf"
244
+ ): any[] {
245
+ const itemsArray = items[schemaType] as SchemaObject[];
246
+ return itemsArray.map((item: SchemaObject) => {
247
+ // If items has properties, merge them with each item
248
+ if (items.properties) {
249
+ const combinedSchema = {
250
+ ...item,
251
+ properties: {
252
+ ...items.properties, // Common properties from parent
253
+ ...item.properties, // Specific properties from this anyOf/oneOf item
254
+ },
255
+ };
256
+ // Remove anyOf/oneOf to prevent infinite recursion when calling sampleRequestFromSchema
257
+ delete combinedSchema[schemaType];
258
+ return sampleRequestFromSchema(combinedSchema);
259
+ }
260
+ return sampleRequestFromSchema(item);
261
+ });
262
+ }
@@ -181,11 +181,11 @@ export const sampleResponseFromSchema = (schema: SchemaObject = {}): any => {
181
181
 
182
182
  if (type === "array") {
183
183
  if (Array.isArray(items?.anyOf)) {
184
- return items?.anyOf.map((item: any) => sampleResponseFromSchema(item));
184
+ return processArrayItems(items, "anyOf");
185
185
  }
186
186
 
187
187
  if (Array.isArray(items?.oneOf)) {
188
- return items?.oneOf.map((item: any) => sampleResponseFromSchema(item));
188
+ return processArrayItems(items, "oneOf");
189
189
  }
190
190
 
191
191
  return [sampleResponseFromSchema(items)];
@@ -240,3 +240,26 @@ function normalizeArray(arr: any) {
240
240
  }
241
241
  return [arr];
242
242
  }
243
+
244
+ function processArrayItems(
245
+ items: SchemaObject,
246
+ schemaType: "anyOf" | "oneOf"
247
+ ): any[] {
248
+ const itemsArray = items[schemaType] as SchemaObject[];
249
+ return itemsArray.map((item: SchemaObject) => {
250
+ // If items has properties, merge them with each item
251
+ if (items.properties) {
252
+ const combinedSchema = {
253
+ ...item,
254
+ properties: {
255
+ ...items.properties, // Common properties from parent
256
+ ...item.properties, // Specific properties from this anyOf/oneOf item
257
+ },
258
+ };
259
+ // Remove anyOf/oneOf to prevent infinite recursion when calling sampleResponseFromSchema
260
+ delete combinedSchema[schemaType];
261
+ return sampleResponseFromSchema(combinedSchema);
262
+ }
263
+ return sampleResponseFromSchema(item);
264
+ });
265
+ }
@@ -263,6 +263,7 @@ function createItems(
263
263
  jsonRequestBodyExample,
264
264
  info: openapiData.info,
265
265
  },
266
+ position: operationObject["x-position"] as number | undefined,
266
267
  };
267
268
 
268
269
  items.push(apiPage);
@@ -509,6 +510,22 @@ function createItems(
509
510
  });
510
511
  }
511
512
 
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
+
512
529
  return items as ApiMetadata[];
513
530
  }
514
531
 
@@ -156,8 +156,8 @@ export interface OperationObject {
156
156
  deprecated?: boolean;
157
157
  security?: SecurityRequirementObject[];
158
158
  servers?: ServerObject[];
159
-
160
159
  // extensions
160
+ "x-position"?: number;
161
161
  "x-deprecated-description"?: string;
162
162
  }
163
163
 
@@ -89,6 +89,7 @@ export interface OpenAPIOperation {
89
89
  servers?: OpenAPIServer[];
90
90
  "x-codeSamples"?: OpenAPIXCodeSample[];
91
91
  "x-code-samples"?: OpenAPIXCodeSample[]; // deprecated
92
+ "x-position"?: number;
92
93
  }
93
94
 
94
95
  export interface OpenAPIParameter {
package/src/types.ts CHANGED
@@ -118,6 +118,7 @@ export interface ApiMetadataBase {
118
118
  frontMatter: Record<string, unknown>;
119
119
  method?: string;
120
120
  path?: string;
121
+ position?: number;
121
122
  }
122
123
 
123
124
  export interface ApiPageMetadata extends ApiMetadataBase {