docusaurus-plugin-openapi-docs 0.0.0-527 → 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 +9 -7
- 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 +13 -5
- 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,11 +60,12 @@ 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 = [];
|
|
67
|
-
const
|
|
67
|
+
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
68
|
+
const infoId = (0, kebabCase_1.default)(infoIdSpaces);
|
|
68
69
|
if (openapiData.info.description) {
|
|
69
70
|
// Only create an info page if we have a description.
|
|
70
71
|
const infoDescription = (_a = openapiData.info) === null || _a === void 0 ? void 0 : _a.description;
|
|
@@ -171,6 +172,7 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
171
172
|
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
172
173
|
.replace(/\s+$/, "")
|
|
173
174
|
: "",
|
|
175
|
+
...((options === null || options === void 0 ? void 0 : options.proxy) && { proxy: options.proxy }),
|
|
174
176
|
},
|
|
175
177
|
api: {
|
|
176
178
|
...defaults,
|
|
@@ -248,7 +250,7 @@ function bindCollectionToApiItems(items, postmanCollection) {
|
|
|
248
250
|
}
|
|
249
251
|
});
|
|
250
252
|
}
|
|
251
|
-
async function readOpenapiFiles(openapiPath
|
|
253
|
+
async function readOpenapiFiles(openapiPath) {
|
|
252
254
|
if (!(0, index_1.isURL)(openapiPath)) {
|
|
253
255
|
const stat = await fs_extra_1.default.lstat(openapiPath);
|
|
254
256
|
if (stat.isDirectory()) {
|
|
@@ -281,10 +283,10 @@ async function readOpenapiFiles(openapiPath, options) {
|
|
|
281
283
|
];
|
|
282
284
|
}
|
|
283
285
|
exports.readOpenapiFiles = readOpenapiFiles;
|
|
284
|
-
async function processOpenapiFiles(files, sidebarOptions) {
|
|
286
|
+
async function processOpenapiFiles(files, options, sidebarOptions) {
|
|
285
287
|
const promises = files.map(async (file) => {
|
|
286
288
|
if (file.data !== undefined) {
|
|
287
|
-
const processedFile = await processOpenapiFile(file.data, sidebarOptions);
|
|
289
|
+
const processedFile = await processOpenapiFile(file.data, options, sidebarOptions);
|
|
288
290
|
const itemsObjectsArray = processedFile[0].map((item) => ({
|
|
289
291
|
...item,
|
|
290
292
|
}));
|
|
@@ -315,9 +317,9 @@ async function processOpenapiFiles(files, sidebarOptions) {
|
|
|
315
317
|
return [items, tags];
|
|
316
318
|
}
|
|
317
319
|
exports.processOpenapiFiles = processOpenapiFiles;
|
|
318
|
-
async function processOpenapiFile(openapiData, sidebarOptions) {
|
|
320
|
+
async function processOpenapiFile(openapiData, options, sidebarOptions) {
|
|
319
321
|
const postmanCollection = await createPostmanCollection(openapiData);
|
|
320
|
-
const items = createItems(openapiData, sidebarOptions);
|
|
322
|
+
const items = createItems(openapiData, options, sidebarOptions);
|
|
321
323
|
bindCollectionToApiItems(items, postmanCollection);
|
|
322
324
|
let tags = [];
|
|
323
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,11 +80,13 @@ 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
|
|
86
87
|
let items: PartialPage<ApiMetadata>[] = [];
|
|
87
|
-
const
|
|
88
|
+
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
89
|
+
const infoId = kebabCase(infoIdSpaces);
|
|
88
90
|
|
|
89
91
|
if (openapiData.info.description) {
|
|
90
92
|
// Only create an info page if we have a description.
|
|
@@ -218,6 +220,7 @@ function createItems(
|
|
|
218
220
|
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
219
221
|
.replace(/\s+$/, "")
|
|
220
222
|
: "",
|
|
223
|
+
...(options?.proxy && { proxy: options.proxy }),
|
|
221
224
|
},
|
|
222
225
|
api: {
|
|
223
226
|
...defaults,
|
|
@@ -318,8 +321,7 @@ interface OpenApiFiles {
|
|
|
318
321
|
}
|
|
319
322
|
|
|
320
323
|
export async function readOpenapiFiles(
|
|
321
|
-
openapiPath: string
|
|
322
|
-
options: APIOptions
|
|
324
|
+
openapiPath: string
|
|
323
325
|
): Promise<OpenApiFiles[]> {
|
|
324
326
|
if (!isURL(openapiPath)) {
|
|
325
327
|
const stat = await fs.lstat(openapiPath);
|
|
@@ -361,11 +363,16 @@ export async function readOpenapiFiles(
|
|
|
361
363
|
|
|
362
364
|
export async function processOpenapiFiles(
|
|
363
365
|
files: OpenApiFiles[],
|
|
366
|
+
options: APIOptions,
|
|
364
367
|
sidebarOptions: SidebarOptions
|
|
365
368
|
): Promise<[ApiMetadata[], TagObject[][]]> {
|
|
366
369
|
const promises = files.map(async (file) => {
|
|
367
370
|
if (file.data !== undefined) {
|
|
368
|
-
const processedFile = await processOpenapiFile(
|
|
371
|
+
const processedFile = await processOpenapiFile(
|
|
372
|
+
file.data,
|
|
373
|
+
options,
|
|
374
|
+
sidebarOptions
|
|
375
|
+
);
|
|
369
376
|
const itemsObjectsArray = processedFile[0].map((item) => ({
|
|
370
377
|
...item,
|
|
371
378
|
}));
|
|
@@ -402,10 +409,11 @@ export async function processOpenapiFiles(
|
|
|
402
409
|
|
|
403
410
|
export async function processOpenapiFile(
|
|
404
411
|
openapiData: OpenApiObject,
|
|
412
|
+
options: APIOptions,
|
|
405
413
|
sidebarOptions: SidebarOptions
|
|
406
414
|
): Promise<[ApiMetadata[], TagObject[]]> {
|
|
407
415
|
const postmanCollection = await createPostmanCollection(openapiData);
|
|
408
|
-
const items = createItems(openapiData, sidebarOptions);
|
|
416
|
+
const items = createItems(openapiData, options, sidebarOptions);
|
|
409
417
|
|
|
410
418
|
bindCollectionToApiItems(items, postmanCollection);
|
|
411
419
|
|
package/src/options.ts
CHANGED