docusaurus-plugin-openapi-docs 0.0.0-1005 → 0.0.0-1007

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.
@@ -36,6 +36,9 @@ const primitives = {
36
36
  },
37
37
  object: {},
38
38
  array: {},
39
+ null: {
40
+ default: () => "null",
41
+ },
39
42
  };
40
43
  function sampleRequestFromProp(name, prop, obj) {
41
44
  // Handle resolved circular props
@@ -144,10 +147,10 @@ const sampleRequestFromSchema = (schema = {}) => {
144
147
  }
145
148
  if (type === "array") {
146
149
  if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
147
- return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleRequestFromSchema)(item));
150
+ return processArrayItems(items, "anyOf");
148
151
  }
149
152
  if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
150
- return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleRequestFromSchema)(item));
153
+ return processArrayItems(items, "oneOf");
151
154
  }
152
155
  return normalizeArray((0, exports.sampleRequestFromSchema)(items));
153
156
  }
@@ -189,3 +192,22 @@ function normalizeArray(arr) {
189
192
  }
190
193
  return [arr];
191
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
+ }
@@ -36,6 +36,9 @@ const primitives = {
36
36
  },
37
37
  object: {},
38
38
  array: {},
39
+ null: {
40
+ default: () => "null",
41
+ },
39
42
  };
40
43
  function sampleResponseFromProp(name, prop, obj) {
41
44
  // Handle resolved circular props
@@ -145,10 +148,10 @@ const sampleResponseFromSchema = (schema = {}) => {
145
148
  }
146
149
  if (type === "array") {
147
150
  if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
148
- return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleResponseFromSchema)(item));
151
+ return processArrayItems(items, "anyOf");
149
152
  }
150
153
  if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
151
- return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleResponseFromSchema)(item));
154
+ return processArrayItems(items, "oneOf");
152
155
  }
153
156
  return [(0, exports.sampleResponseFromSchema)(items)];
154
157
  }
@@ -190,3 +193,22 @@ function normalizeArray(arr) {
190
193
  }
191
194
  return [arr];
192
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
+ }
@@ -1,4 +1,4 @@
1
- import type { JSONSchema4, JSONSchema6, JSONSchema7 } from "json-schema";
1
+ import type { JSONSchema4, JSONSchema6, JSONSchema7, JSONSchema7TypeName } from "json-schema";
2
2
  interface Map<T> {
3
3
  [key: string]: T;
4
4
  }
@@ -264,8 +264,9 @@ export interface ReferenceObject {
264
264
  $ref: string;
265
265
  }
266
266
  export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
267
+ export type SchemaType = JSONSchema7TypeName;
267
268
  export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
268
- type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
269
+ type?: SchemaType;
269
270
  allOf?: SchemaObject[];
270
271
  oneOf?: SchemaObject[];
271
272
  anyOf?: SchemaObject[];
@@ -285,7 +286,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
285
286
  "x-enumDescriptions"?: Record<string, string>;
286
287
  };
287
288
  export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
288
- type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
289
+ type?: SchemaType;
289
290
  allOf?: (SchemaObject | ReferenceObject)[];
290
291
  oneOf?: (SchemaObject | ReferenceObject)[];
291
292
  anyOf?: (SchemaObject | ReferenceObject)[];
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-1005",
4
+ "version": "0.0.0-1007",
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": "4263fa2f5bae006b1d7328a0f16af378786fed47"
68
+ "gitHead": "864d5355b98d552679472455f533ef15313a0bee"
69
69
  }
@@ -18,6 +18,7 @@ interface OASTypeToTypeMap {
18
18
  boolean: boolean;
19
19
  object: any;
20
20
  array: any[];
21
+ null: string | null;
21
22
  }
22
23
 
23
24
  type Primitives = {
@@ -50,6 +51,9 @@ const primitives: Primitives = {
50
51
  },
51
52
  object: {},
52
53
  array: {},
54
+ null: {
55
+ default: () => "null",
56
+ },
53
57
  };
54
58
 
55
59
  function sampleRequestFromProp(name: string, prop: any, obj: any): any {
@@ -174,11 +178,11 @@ export const sampleRequestFromSchema = (schema: SchemaObject = {}): any => {
174
178
 
175
179
  if (type === "array") {
176
180
  if (Array.isArray(items?.anyOf)) {
177
- return items?.anyOf.map((item: any) => sampleRequestFromSchema(item));
181
+ return processArrayItems(items, "anyOf");
178
182
  }
179
183
 
180
184
  if (Array.isArray(items?.oneOf)) {
181
- return items?.oneOf.map((item: any) => sampleRequestFromSchema(item));
185
+ return processArrayItems(items, "oneOf");
182
186
  }
183
187
 
184
188
  return normalizeArray(sampleRequestFromSchema(items));
@@ -233,3 +237,26 @@ function normalizeArray(arr: any) {
233
237
  }
234
238
  return [arr];
235
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
+ }
@@ -18,6 +18,7 @@ interface OASTypeToTypeMap {
18
18
  boolean: boolean;
19
19
  object: any;
20
20
  array: any[];
21
+ null: string | null;
21
22
  }
22
23
 
23
24
  type Primitives = {
@@ -50,6 +51,9 @@ const primitives: Primitives = {
50
51
  },
51
52
  object: {},
52
53
  array: {},
54
+ null: {
55
+ default: () => "null",
56
+ },
53
57
  };
54
58
 
55
59
  function sampleResponseFromProp(name: string, prop: any, obj: any): any {
@@ -177,11 +181,11 @@ export const sampleResponseFromSchema = (schema: SchemaObject = {}): any => {
177
181
 
178
182
  if (type === "array") {
179
183
  if (Array.isArray(items?.anyOf)) {
180
- return items?.anyOf.map((item: any) => sampleResponseFromSchema(item));
184
+ return processArrayItems(items, "anyOf");
181
185
  }
182
186
 
183
187
  if (Array.isArray(items?.oneOf)) {
184
- return items?.oneOf.map((item: any) => sampleResponseFromSchema(item));
188
+ return processArrayItems(items, "oneOf");
185
189
  }
186
190
 
187
191
  return [sampleResponseFromSchema(items)];
@@ -236,3 +240,26 @@ function normalizeArray(arr: any) {
236
240
  }
237
241
  return [arr];
238
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
+ }
@@ -5,7 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import type { JSONSchema4, JSONSchema6, JSONSchema7 } from "json-schema";
8
+ import type {
9
+ JSONSchema4,
10
+ JSONSchema6,
11
+ JSONSchema7,
12
+ JSONSchema7TypeName,
13
+ } from "json-schema";
9
14
 
10
15
  interface Map<T> {
11
16
  [key: string]: T;
@@ -325,6 +330,7 @@ export interface ReferenceObject {
325
330
  }
326
331
 
327
332
  export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
333
+ export type SchemaType = JSONSchema7TypeName;
328
334
  export type SchemaObject = Omit<
329
335
  JSONSchema,
330
336
  | "type"
@@ -337,7 +343,7 @@ export type SchemaObject = Omit<
337
343
  | "additionalProperties"
338
344
  > & {
339
345
  // OpenAPI specific overrides
340
- type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
346
+ type?: SchemaType;
341
347
  allOf?: SchemaObject[];
342
348
  oneOf?: SchemaObject[];
343
349
  anyOf?: SchemaObject[];
@@ -371,7 +377,7 @@ export type SchemaObjectWithRef = Omit<
371
377
  | "additionalProperties"
372
378
  > & {
373
379
  // OpenAPI specific overrides
374
- type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
380
+ type?: SchemaType;
375
381
  allOf?: (SchemaObject | ReferenceObject)[];
376
382
  oneOf?: (SchemaObject | ReferenceObject)[];
377
383
  anyOf?: (SchemaObject | ReferenceObject)[];