docusaurus-plugin-openapi-docs 0.0.0-528 → 0.0.0-529
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 +5 -2
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +7 -6
- package/lib/openapi/openapi.test.js +1 -1
- package/lib/options.js +1 -0
- package/lib/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/index.ts +5 -1
- package/src/openapi/openapi.test.ts +1 -2
- package/src/openapi/openapi.ts +11 -4
- package/src/options.ts +1 -0
- package/src/types.ts +1 -0
package/lib/index.js
CHANGED
|
@@ -87,8 +87,8 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
87
87
|
? specPath
|
|
88
88
|
: path_1.default.resolve(siteDir, specPath);
|
|
89
89
|
try {
|
|
90
|
-
const openapiFiles = await (0, openapi_1.readOpenapiFiles)(contentPath
|
|
91
|
-
const [loadedApi, tags] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, sidebarOptions);
|
|
90
|
+
const openapiFiles = await (0, openapi_1.readOpenapiFiles)(contentPath);
|
|
91
|
+
const [loadedApi, tags] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, options, sidebarOptions);
|
|
92
92
|
if (!fs_1.default.existsSync(outputDir)) {
|
|
93
93
|
try {
|
|
94
94
|
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
@@ -144,6 +144,9 @@ sidebar_class_name: "{{{api.method}}} api-method"
|
|
|
144
144
|
info_path: {{{infoPath}}}
|
|
145
145
|
{{/infoPath}}
|
|
146
146
|
custom_edit_url: null
|
|
147
|
+
{{#frontMatter.proxy}}
|
|
148
|
+
proxy: {{{frontMatter.proxy}}}
|
|
149
|
+
{{/frontMatter.proxy}}
|
|
147
150
|
---
|
|
148
151
|
|
|
149
152
|
{{{markdown}}}
|
package/lib/openapi/openapi.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ interface OpenApiFiles {
|
|
|
5
5
|
sourceDirName: string;
|
|
6
6
|
data: OpenApiObject;
|
|
7
7
|
}
|
|
8
|
-
export declare function readOpenapiFiles(openapiPath: string
|
|
9
|
-
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][]]>;
|
|
10
|
-
export declare function processOpenapiFile(openapiData: OpenApiObject, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
8
|
+
export declare function readOpenapiFiles(openapiPath: string): Promise<OpenApiFiles[]>;
|
|
9
|
+
export declare function processOpenapiFiles(files: OpenApiFiles[], options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][]]>;
|
|
10
|
+
export declare function processOpenapiFile(openapiData: OpenApiObject, options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
11
11
|
export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
|
|
12
12
|
export {};
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -60,7 +60,7 @@ async function createPostmanCollection(openapiData) {
|
|
|
60
60
|
}
|
|
61
61
|
return await jsonToCollection(data);
|
|
62
62
|
}
|
|
63
|
-
function createItems(openapiData, sidebarOptions) {
|
|
63
|
+
function createItems(openapiData, options, sidebarOptions) {
|
|
64
64
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
65
65
|
// TODO: Find a better way to handle this
|
|
66
66
|
let items = [];
|
|
@@ -172,6 +172,7 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
172
172
|
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
173
173
|
.replace(/\s+$/, "")
|
|
174
174
|
: "",
|
|
175
|
+
...((options === null || options === void 0 ? void 0 : options.proxy) && { proxy: options.proxy }),
|
|
175
176
|
},
|
|
176
177
|
api: {
|
|
177
178
|
...defaults,
|
|
@@ -249,7 +250,7 @@ function bindCollectionToApiItems(items, postmanCollection) {
|
|
|
249
250
|
}
|
|
250
251
|
});
|
|
251
252
|
}
|
|
252
|
-
async function readOpenapiFiles(openapiPath
|
|
253
|
+
async function readOpenapiFiles(openapiPath) {
|
|
253
254
|
if (!(0, index_1.isURL)(openapiPath)) {
|
|
254
255
|
const stat = await fs_extra_1.default.lstat(openapiPath);
|
|
255
256
|
if (stat.isDirectory()) {
|
|
@@ -282,10 +283,10 @@ async function readOpenapiFiles(openapiPath, options) {
|
|
|
282
283
|
];
|
|
283
284
|
}
|
|
284
285
|
exports.readOpenapiFiles = readOpenapiFiles;
|
|
285
|
-
async function processOpenapiFiles(files, sidebarOptions) {
|
|
286
|
+
async function processOpenapiFiles(files, options, sidebarOptions) {
|
|
286
287
|
const promises = files.map(async (file) => {
|
|
287
288
|
if (file.data !== undefined) {
|
|
288
|
-
const processedFile = await processOpenapiFile(file.data, sidebarOptions);
|
|
289
|
+
const processedFile = await processOpenapiFile(file.data, options, sidebarOptions);
|
|
289
290
|
const itemsObjectsArray = processedFile[0].map((item) => ({
|
|
290
291
|
...item,
|
|
291
292
|
}));
|
|
@@ -316,9 +317,9 @@ async function processOpenapiFiles(files, sidebarOptions) {
|
|
|
316
317
|
return [items, tags];
|
|
317
318
|
}
|
|
318
319
|
exports.processOpenapiFiles = processOpenapiFiles;
|
|
319
|
-
async function processOpenapiFile(openapiData, sidebarOptions) {
|
|
320
|
+
async function processOpenapiFile(openapiData, options, sidebarOptions) {
|
|
320
321
|
const postmanCollection = await createPostmanCollection(openapiData);
|
|
321
|
-
const items = createItems(openapiData, sidebarOptions);
|
|
322
|
+
const items = createItems(openapiData, options, sidebarOptions);
|
|
322
323
|
bindCollectionToApiItems(items, postmanCollection);
|
|
323
324
|
let tags = [];
|
|
324
325
|
if (openapiData.tags !== undefined) {
|
|
@@ -16,7 +16,7 @@ const _1 = require(".");
|
|
|
16
16
|
describe("openapi", () => {
|
|
17
17
|
describe("readOpenapiFiles", () => {
|
|
18
18
|
it("readOpenapiFiles", async () => {
|
|
19
|
-
const results = await (0, _1.readOpenapiFiles)((0, utils_1.posixPath)(path_1.default.join(__dirname, "__fixtures__/examples"))
|
|
19
|
+
const results = await (0, _1.readOpenapiFiles)((0, utils_1.posixPath)(path_1.default.join(__dirname, "__fixtures__/examples")));
|
|
20
20
|
const categoryMeta = results.find((x) => x.source.endsWith("_category_.json"));
|
|
21
21
|
expect(categoryMeta).toBeFalsy();
|
|
22
22
|
// console.log(results);
|
package/lib/options.js
CHANGED
|
@@ -21,6 +21,7 @@ exports.OptionsSchema = utils_validation_1.Joi.object({
|
|
|
21
21
|
config: utils_validation_1.Joi.object()
|
|
22
22
|
.pattern(/^/, utils_validation_1.Joi.object({
|
|
23
23
|
specPath: utils_validation_1.Joi.string().required(),
|
|
24
|
+
proxy: utils_validation_1.Joi.string(),
|
|
24
25
|
outputDir: utils_validation_1.Joi.string().required(),
|
|
25
26
|
template: utils_validation_1.Joi.string(),
|
|
26
27
|
downloadUrl: utils_validation_1.Joi.string(),
|
package/lib/types.d.ts
CHANGED
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-529",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=14"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "f5fc59449765c07686f86df742256acdd2eccb44"
|
|
72
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -106,9 +106,10 @@ export default function pluginOpenAPIDocs(
|
|
|
106
106
|
: path.resolve(siteDir, specPath);
|
|
107
107
|
|
|
108
108
|
try {
|
|
109
|
-
const openapiFiles = await readOpenapiFiles(contentPath
|
|
109
|
+
const openapiFiles = await readOpenapiFiles(contentPath);
|
|
110
110
|
const [loadedApi, tags] = await processOpenapiFiles(
|
|
111
111
|
openapiFiles,
|
|
112
|
+
options,
|
|
112
113
|
sidebarOptions!
|
|
113
114
|
);
|
|
114
115
|
if (!fs.existsSync(outputDir)) {
|
|
@@ -183,6 +184,9 @@ sidebar_class_name: "{{{api.method}}} api-method"
|
|
|
183
184
|
info_path: {{{infoPath}}}
|
|
184
185
|
{{/infoPath}}
|
|
185
186
|
custom_edit_url: null
|
|
187
|
+
{{#frontMatter.proxy}}
|
|
188
|
+
proxy: {{{frontMatter.proxy}}}
|
|
189
|
+
{{/frontMatter.proxy}}
|
|
186
190
|
---
|
|
187
191
|
|
|
188
192
|
{{{markdown}}}
|
|
@@ -17,8 +17,7 @@ describe("openapi", () => {
|
|
|
17
17
|
describe("readOpenapiFiles", () => {
|
|
18
18
|
it("readOpenapiFiles", async () => {
|
|
19
19
|
const results = await readOpenapiFiles(
|
|
20
|
-
posixPath(path.join(__dirname, "__fixtures__/examples"))
|
|
21
|
-
{ specPath: "./", outputDir: "./" }
|
|
20
|
+
posixPath(path.join(__dirname, "__fixtures__/examples"))
|
|
22
21
|
);
|
|
23
22
|
const categoryMeta = results.find((x) =>
|
|
24
23
|
x.source.endsWith("_category_.json")
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -80,6 +80,7 @@ type PartialPage<T> = Omit<T, "permalink" | "source" | "sourceDirName">;
|
|
|
80
80
|
|
|
81
81
|
function createItems(
|
|
82
82
|
openapiData: OpenApiObject,
|
|
83
|
+
options: APIOptions,
|
|
83
84
|
sidebarOptions: SidebarOptions
|
|
84
85
|
): ApiMetadata[] {
|
|
85
86
|
// TODO: Find a better way to handle this
|
|
@@ -219,6 +220,7 @@ function createItems(
|
|
|
219
220
|
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
220
221
|
.replace(/\s+$/, "")
|
|
221
222
|
: "",
|
|
223
|
+
...(options?.proxy && { proxy: options.proxy }),
|
|
222
224
|
},
|
|
223
225
|
api: {
|
|
224
226
|
...defaults,
|
|
@@ -319,8 +321,7 @@ interface OpenApiFiles {
|
|
|
319
321
|
}
|
|
320
322
|
|
|
321
323
|
export async function readOpenapiFiles(
|
|
322
|
-
openapiPath: string
|
|
323
|
-
options: APIOptions
|
|
324
|
+
openapiPath: string
|
|
324
325
|
): Promise<OpenApiFiles[]> {
|
|
325
326
|
if (!isURL(openapiPath)) {
|
|
326
327
|
const stat = await fs.lstat(openapiPath);
|
|
@@ -362,11 +363,16 @@ export async function readOpenapiFiles(
|
|
|
362
363
|
|
|
363
364
|
export async function processOpenapiFiles(
|
|
364
365
|
files: OpenApiFiles[],
|
|
366
|
+
options: APIOptions,
|
|
365
367
|
sidebarOptions: SidebarOptions
|
|
366
368
|
): Promise<[ApiMetadata[], TagObject[][]]> {
|
|
367
369
|
const promises = files.map(async (file) => {
|
|
368
370
|
if (file.data !== undefined) {
|
|
369
|
-
const processedFile = await processOpenapiFile(
|
|
371
|
+
const processedFile = await processOpenapiFile(
|
|
372
|
+
file.data,
|
|
373
|
+
options,
|
|
374
|
+
sidebarOptions
|
|
375
|
+
);
|
|
370
376
|
const itemsObjectsArray = processedFile[0].map((item) => ({
|
|
371
377
|
...item,
|
|
372
378
|
}));
|
|
@@ -403,10 +409,11 @@ export async function processOpenapiFiles(
|
|
|
403
409
|
|
|
404
410
|
export async function processOpenapiFile(
|
|
405
411
|
openapiData: OpenApiObject,
|
|
412
|
+
options: APIOptions,
|
|
406
413
|
sidebarOptions: SidebarOptions
|
|
407
414
|
): Promise<[ApiMetadata[], TagObject[]]> {
|
|
408
415
|
const postmanCollection = await createPostmanCollection(openapiData);
|
|
409
|
-
const items = createItems(openapiData, sidebarOptions);
|
|
416
|
+
const items = createItems(openapiData, options, sidebarOptions);
|
|
410
417
|
|
|
411
418
|
bindCollectionToApiItems(items, postmanCollection);
|
|
412
419
|
|
package/src/options.ts
CHANGED