docusaurus-plugin-openapi-docs 0.0.0-1080 → 0.0.0-1082
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.
- package/lib/index.js +9 -3
- package/lib/openapi/createSchemaExample.js +13 -2
- package/lib/sidebars/index.js +12 -3
- package/package.json +2 -2
- package/src/index.ts +12 -3
- package/src/openapi/createSchemaExample.ts +12 -1
- package/src/sidebars/index.ts +15 -3
package/lib/index.js
CHANGED
|
@@ -234,6 +234,7 @@ custom_edit_url: null
|
|
|
234
234
|
schema: schemaPageGenerator,
|
|
235
235
|
};
|
|
236
236
|
loadedApi.map(async (item) => {
|
|
237
|
+
var _a, _b;
|
|
237
238
|
if (downloadUrl) {
|
|
238
239
|
item.downloadUrl = downloadUrl;
|
|
239
240
|
}
|
|
@@ -257,9 +258,14 @@ custom_edit_url: null
|
|
|
257
258
|
.toString("base64"));
|
|
258
259
|
let infoBasePath = `${outputDir}/${item.infoId}`;
|
|
259
260
|
if (docRouteBasePath) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
.replace(/^\/+/g, "")
|
|
261
|
+
// Safely extract path segment, handling cases where docPath may not be in outputDir
|
|
262
|
+
const outputSegment = docPath && outputDir.includes(docPath)
|
|
263
|
+
? ((_b = (_a = outputDir.split(docPath)[1]) === null || _a === void 0 ? void 0 : _a.replace(/^\/+/g, "")) !== null && _b !== void 0 ? _b : "")
|
|
264
|
+
: outputDir
|
|
265
|
+
.slice(outputDir.indexOf("/", 1))
|
|
266
|
+
.replace(/^\/+/g, "");
|
|
267
|
+
infoBasePath =
|
|
268
|
+
`${docRouteBasePath}/${outputSegment}/${item.infoId}`.replace(/^\/+/g, "");
|
|
263
269
|
}
|
|
264
270
|
if (item.infoId)
|
|
265
271
|
item.infoPath = infoBasePath;
|
|
@@ -58,7 +58,14 @@ function sampleFromProp(name, prop, obj, context) {
|
|
|
58
58
|
return obj;
|
|
59
59
|
}
|
|
60
60
|
// TODO: handle discriminators
|
|
61
|
-
|
|
61
|
+
// Check for explicit example/examples first (OAS 3.1 support)
|
|
62
|
+
if (prop.example !== undefined) {
|
|
63
|
+
obj[name] = prop.example;
|
|
64
|
+
}
|
|
65
|
+
else if (prop.examples !== undefined && prop.examples.length > 0) {
|
|
66
|
+
obj[name] = prop.examples[0];
|
|
67
|
+
}
|
|
68
|
+
else if (prop.oneOf) {
|
|
62
69
|
obj[name] = (0, exports.sampleFromSchema)(prop.oneOf[0], context);
|
|
63
70
|
}
|
|
64
71
|
else if (prop.anyOf) {
|
|
@@ -77,10 +84,14 @@ const sampleFromSchema = (schema = {}, context) => {
|
|
|
77
84
|
try {
|
|
78
85
|
// deep copy schema before processing
|
|
79
86
|
let schemaCopy = JSON.parse(JSON.stringify(schema));
|
|
80
|
-
let { type, example, allOf, properties, items, oneOf, anyOf, const: constant, } = schemaCopy;
|
|
87
|
+
let { type, example, examples, allOf, properties, items, oneOf, anyOf, const: constant, } = schemaCopy;
|
|
81
88
|
if (example !== undefined) {
|
|
82
89
|
return example;
|
|
83
90
|
}
|
|
91
|
+
// OAS 3.1 / JSON Schema: examples is an array
|
|
92
|
+
if (examples !== undefined && examples.length > 0) {
|
|
93
|
+
return examples[0];
|
|
94
|
+
}
|
|
84
95
|
if (oneOf) {
|
|
85
96
|
if (properties) {
|
|
86
97
|
const combinedSchemas = (0, merge_1.default)(schemaCopy, oneOf[0]);
|
package/lib/sidebars/index.js
CHANGED
|
@@ -81,9 +81,18 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
81
81
|
if (sidebarOptions.groupPathsBy !== "tagGroup") {
|
|
82
82
|
apiTags = (0, uniq_1.default)(apiTags.concat(operationTags, schemaTags));
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
// Extract base path from outputDir, handling cases where docPath may not be in outputDir
|
|
85
|
+
const getBasePathFromOutput = (output, doc) => {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
if (doc && output.includes(doc)) {
|
|
88
|
+
return (_b = (_a = output.split(doc)[1]) === null || _a === void 0 ? void 0 : _a.replace(/^\/+/g, "")) !== null && _b !== void 0 ? _b : "";
|
|
89
|
+
}
|
|
90
|
+
const slashIndex = output.indexOf("/", 1);
|
|
91
|
+
return slashIndex === -1
|
|
92
|
+
? ""
|
|
93
|
+
: output.slice(slashIndex).replace(/^\/+/g, "");
|
|
94
|
+
};
|
|
95
|
+
const basePath = getBasePathFromOutput(outputDir, docPath);
|
|
87
96
|
const createDocItemFnContext = {
|
|
88
97
|
sidebarOptions,
|
|
89
98
|
basePath,
|
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-
|
|
4
|
+
"version": "0.0.0-1082",
|
|
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": "
|
|
68
|
+
"gitHead": "7e23eae947f6c077f3a087f2b42368dbbadcb6bb"
|
|
69
69
|
}
|
package/src/index.ts
CHANGED
|
@@ -353,9 +353,18 @@ custom_edit_url: null
|
|
|
353
353
|
.toString("base64"));
|
|
354
354
|
let infoBasePath = `${outputDir}/${item.infoId}`;
|
|
355
355
|
if (docRouteBasePath) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
356
|
+
// Safely extract path segment, handling cases where docPath may not be in outputDir
|
|
357
|
+
const outputSegment =
|
|
358
|
+
docPath && outputDir.includes(docPath)
|
|
359
|
+
? (outputDir.split(docPath)[1]?.replace(/^\/+/g, "") ?? "")
|
|
360
|
+
: outputDir
|
|
361
|
+
.slice(outputDir.indexOf("/", 1))
|
|
362
|
+
.replace(/^\/+/g, "");
|
|
363
|
+
infoBasePath =
|
|
364
|
+
`${docRouteBasePath}/${outputSegment}/${item.infoId}`.replace(
|
|
365
|
+
/^\/+/g,
|
|
366
|
+
""
|
|
367
|
+
);
|
|
359
368
|
}
|
|
360
369
|
if (item.infoId) item.infoPath = infoBasePath;
|
|
361
370
|
}
|
|
@@ -91,7 +91,12 @@ function sampleFromProp(
|
|
|
91
91
|
|
|
92
92
|
// TODO: handle discriminators
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
// Check for explicit example/examples first (OAS 3.1 support)
|
|
95
|
+
if (prop.example !== undefined) {
|
|
96
|
+
obj[name] = prop.example;
|
|
97
|
+
} else if (prop.examples !== undefined && prop.examples.length > 0) {
|
|
98
|
+
obj[name] = prop.examples[0];
|
|
99
|
+
} else if (prop.oneOf) {
|
|
95
100
|
obj[name] = sampleFromSchema(prop.oneOf[0], context);
|
|
96
101
|
} else if (prop.anyOf) {
|
|
97
102
|
obj[name] = sampleFromSchema(prop.anyOf[0], context);
|
|
@@ -114,6 +119,7 @@ export const sampleFromSchema = (
|
|
|
114
119
|
let {
|
|
115
120
|
type,
|
|
116
121
|
example,
|
|
122
|
+
examples,
|
|
117
123
|
allOf,
|
|
118
124
|
properties,
|
|
119
125
|
items,
|
|
@@ -126,6 +132,11 @@ export const sampleFromSchema = (
|
|
|
126
132
|
return example;
|
|
127
133
|
}
|
|
128
134
|
|
|
135
|
+
// OAS 3.1 / JSON Schema: examples is an array
|
|
136
|
+
if (examples !== undefined && examples.length > 0) {
|
|
137
|
+
return examples[0];
|
|
138
|
+
}
|
|
139
|
+
|
|
129
140
|
if (oneOf) {
|
|
130
141
|
if (properties) {
|
|
131
142
|
const combinedSchemas = merge(schemaCopy, oneOf[0]);
|
package/src/sidebars/index.ts
CHANGED
|
@@ -125,9 +125,21 @@ function groupByTags(
|
|
|
125
125
|
apiTags = uniq(apiTags.concat(operationTags, schemaTags));
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
:
|
|
128
|
+
// Extract base path from outputDir, handling cases where docPath may not be in outputDir
|
|
129
|
+
const getBasePathFromOutput = (
|
|
130
|
+
output: string,
|
|
131
|
+
doc: string | undefined
|
|
132
|
+
): string => {
|
|
133
|
+
if (doc && output.includes(doc)) {
|
|
134
|
+
return output.split(doc)[1]?.replace(/^\/+/g, "") ?? "";
|
|
135
|
+
}
|
|
136
|
+
const slashIndex = output.indexOf("/", 1);
|
|
137
|
+
return slashIndex === -1
|
|
138
|
+
? ""
|
|
139
|
+
: output.slice(slashIndex).replace(/^\/+/g, "");
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const basePath = getBasePathFromOutput(outputDir, docPath);
|
|
131
143
|
|
|
132
144
|
const createDocItemFnContext = {
|
|
133
145
|
sidebarOptions,
|