docusaurus-theme-openapi-docs 0.0.0-1078 → 0.0.0-1079

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.
@@ -82,6 +82,8 @@ function Body({
82
82
  const schema = requestBodyMetadata?.content?.[contentType]?.schema;
83
83
  const example = requestBodyMetadata?.content?.[contentType]?.example;
84
84
  const examples = requestBodyMetadata?.content?.[contentType]?.examples;
85
+ // OpenAPI 3.1 / JSON Schema: schema.examples is an array of example values
86
+ const schemaExamples = schema?.examples;
85
87
  if (schema?.format === "binary") {
86
88
  return react_1.default.createElement(
87
89
  FormItem_1.default,
@@ -236,6 +238,17 @@ function Body({
236
238
  });
237
239
  }
238
240
  }
241
+ // OpenAPI 3.1: schema.examples is an array of example values
242
+ if (schemaExamples && Array.isArray(schemaExamples)) {
243
+ schemaExamples.forEach((schemaExample, index) => {
244
+ const body = JSON.stringify(schemaExample, null, 2);
245
+ examplesBodies.push({
246
+ label: `Example ${index + 1}`,
247
+ body,
248
+ summary: undefined,
249
+ });
250
+ });
251
+ }
239
252
  language = "json";
240
253
  }
241
254
  if (contentType === "application/xml" || contentType.endsWith("+xml")) {
@@ -286,6 +299,29 @@ function Body({
286
299
  });
287
300
  }
288
301
  }
302
+ // OpenAPI 3.1: schema.examples is an array of example values
303
+ if (schemaExamples && Array.isArray(schemaExamples)) {
304
+ schemaExamples.forEach((schemaExample, index) => {
305
+ let formattedXmlBody;
306
+ try {
307
+ formattedXmlBody = (0, xml_formatter_1.default)(
308
+ (0, json2xml_1.default)(schemaExample, ""),
309
+ {
310
+ indentation: " ",
311
+ lineSeparator: "\n",
312
+ collapseContent: true,
313
+ }
314
+ );
315
+ } catch {
316
+ formattedXmlBody = (0, json2xml_1.default)(schemaExample);
317
+ }
318
+ examplesBodies.push({
319
+ label: `Example ${index + 1}`,
320
+ body: formattedXmlBody,
321
+ summary: undefined,
322
+ });
323
+ });
324
+ }
289
325
  language = "xml";
290
326
  }
291
327
  if (exampleBody) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-theme-openapi-docs",
3
3
  "description": "OpenAPI theme for Docusaurus.",
4
- "version": "0.0.0-1078",
4
+ "version": "0.0.0-1079",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -38,7 +38,7 @@
38
38
  "@types/postman-collection": "^3.5.11",
39
39
  "@types/react-modal": "^3.16.3",
40
40
  "concurrently": "^9.2.0",
41
- "docusaurus-plugin-openapi-docs": "0.0.0-1078",
41
+ "docusaurus-plugin-openapi-docs": "0.0.0-1079",
42
42
  "docusaurus-plugin-sass": "^0.2.6",
43
43
  "eslint-plugin-prettier": "^5.5.1"
44
44
  },
@@ -81,5 +81,5 @@
81
81
  "engines": {
82
82
  "node": ">=14"
83
83
  },
84
- "gitHead": "39f7ab524f1f703df01e188fa168923e3657a49b"
84
+ "gitHead": "85d510d246cd12692f7a784f7668332a34bc0233"
85
85
  }
@@ -96,6 +96,8 @@ function Body({
96
96
  const schema = requestBodyMetadata?.content?.[contentType]?.schema;
97
97
  const example = requestBodyMetadata?.content?.[contentType]?.example;
98
98
  const examples = requestBodyMetadata?.content?.[contentType]?.examples;
99
+ // OpenAPI 3.1 / JSON Schema: schema.examples is an array of example values
100
+ const schemaExamples = schema?.examples as any[] | undefined;
99
101
 
100
102
  if (schema?.format === "binary") {
101
103
  return (
@@ -254,6 +256,17 @@ function Body({
254
256
  });
255
257
  }
256
258
  }
259
+ // OpenAPI 3.1: schema.examples is an array of example values
260
+ if (schemaExamples && Array.isArray(schemaExamples)) {
261
+ schemaExamples.forEach((schemaExample, index) => {
262
+ const body = JSON.stringify(schemaExample, null, 2);
263
+ examplesBodies.push({
264
+ label: `Example ${index + 1}`,
265
+ body,
266
+ summary: undefined,
267
+ });
268
+ });
269
+ }
257
270
  language = "json";
258
271
  }
259
272
 
@@ -299,6 +312,26 @@ function Body({
299
312
  });
300
313
  }
301
314
  }
315
+ // OpenAPI 3.1: schema.examples is an array of example values
316
+ if (schemaExamples && Array.isArray(schemaExamples)) {
317
+ schemaExamples.forEach((schemaExample, index) => {
318
+ let formattedXmlBody;
319
+ try {
320
+ formattedXmlBody = format(json2xml(schemaExample, ""), {
321
+ indentation: " ",
322
+ lineSeparator: "\n",
323
+ collapseContent: true,
324
+ });
325
+ } catch {
326
+ formattedXmlBody = json2xml(schemaExample);
327
+ }
328
+ examplesBodies.push({
329
+ label: `Example ${index + 1}`,
330
+ body: formattedXmlBody,
331
+ summary: undefined,
332
+ });
333
+ });
334
+ }
302
335
  language = "xml";
303
336
  }
304
337