docusaurus-plugin-openapi-docs 0.0.0-418 → 0.0.0-421
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/markdown/createSchemaDetails.d.ts +1 -1
- package/lib/markdown/createSchemaDetails.js +7 -5
- package/lib/openapi/openapi.js +12 -12
- package/lib/openapi/types.d.ts +1 -1
- package/lib/sidebars/index.js +11 -3
- package/package.json +2 -2
- package/src/markdown/createSchemaDetails.ts +18 -13
- package/src/openapi/openapi.ts +3 -7
- package/src/openapi/types.ts +1 -1
- package/src/sidebars/index.ts +11 -3
|
@@ -192,7 +192,8 @@ function createItems(schema) {
|
|
|
192
192
|
return createAnyOneOf(schema.items);
|
|
193
193
|
}
|
|
194
194
|
if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
|
|
195
|
-
|
|
195
|
+
// TODO: figure out if and how we should pass merged required array
|
|
196
|
+
const { mergedSchemas, } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
|
|
196
197
|
// Handles combo anyOf/oneOf + properties
|
|
197
198
|
if ((mergedSchemas.oneOf !== undefined ||
|
|
198
199
|
mergedSchemas.anyOf !== undefined) &&
|
|
@@ -331,7 +332,7 @@ function createDetailsNode(name, schemaName, schema, required) {
|
|
|
331
332
|
style: { opacity: "0.6" },
|
|
332
333
|
children: ` ${schemaName}`,
|
|
333
334
|
}),
|
|
334
|
-
(0, utils_1.guard)(required, () => [
|
|
335
|
+
(0, utils_1.guard)(schema.required && schema.required === true, () => [
|
|
335
336
|
(0, utils_1.create)("strong", {
|
|
336
337
|
style: {
|
|
337
338
|
fontSize: "var(--ifm-code-font-size)",
|
|
@@ -427,6 +428,7 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
|
|
|
427
428
|
function createEdges({ name, schema, required, discriminator, }) {
|
|
428
429
|
var _a, _b;
|
|
429
430
|
const schemaName = (0, schema_1.getSchemaName)(schema);
|
|
431
|
+
// if (name === "id") console.log(name, schema, required);
|
|
430
432
|
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
431
433
|
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
432
434
|
}
|
|
@@ -453,7 +455,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
453
455
|
return (0, utils_1.create)("SchemaItem", {
|
|
454
456
|
collapsible: false,
|
|
455
457
|
name,
|
|
456
|
-
required,
|
|
458
|
+
required: Array.isArray(required) ? required.includes(name) : required,
|
|
457
459
|
schemaDescription: mergedSchemas.description,
|
|
458
460
|
schemaName: schemaName,
|
|
459
461
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
@@ -474,7 +476,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
474
476
|
return (0, utils_1.create)("SchemaItem", {
|
|
475
477
|
collapsible: false,
|
|
476
478
|
name,
|
|
477
|
-
required,
|
|
479
|
+
required: Array.isArray(required) ? required.includes(name) : required,
|
|
478
480
|
schemaDescription: schema.description,
|
|
479
481
|
schemaName: schemaName,
|
|
480
482
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
@@ -573,7 +575,7 @@ function createSchemaDetails({ title, body, ...rest }) {
|
|
|
573
575
|
style: { opacity: "0.6" },
|
|
574
576
|
children: ` array`,
|
|
575
577
|
})),
|
|
576
|
-
(0, utils_1.guard)(body.required, () => [
|
|
578
|
+
(0, utils_1.guard)(body.required && body.required === true, () => [
|
|
577
579
|
(0, utils_1.create)("strong", {
|
|
578
580
|
style: {
|
|
579
581
|
fontSize: "var(--ifm-code-font-size)",
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -59,7 +59,7 @@ async function createPostmanCollection(openapiData) {
|
|
|
59
59
|
return await jsonToCollection(data);
|
|
60
60
|
}
|
|
61
61
|
function createItems(openapiData, sidebarOptions) {
|
|
62
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
63
63
|
// TODO: Find a better way to handle this
|
|
64
64
|
let items = [];
|
|
65
65
|
const infoId = (0, kebabCase_1.default)(openapiData.info.title);
|
|
@@ -100,8 +100,8 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
100
100
|
securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
|
|
101
101
|
info: {
|
|
102
102
|
...openapiData.info,
|
|
103
|
-
tags:
|
|
104
|
-
title: (
|
|
103
|
+
tags: openapiData.tags,
|
|
104
|
+
title: (_c = openapiData.info.title) !== null && _c !== void 0 ? _c : "Introduction",
|
|
105
105
|
logo: openapiData.info["x-logo"],
|
|
106
106
|
darkLogo: openapiData.info["x-dark-logo"],
|
|
107
107
|
},
|
|
@@ -111,18 +111,18 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
111
111
|
for (let [path, pathObject] of Object.entries(openapiData.paths)) {
|
|
112
112
|
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
113
113
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
114
|
-
const title = (
|
|
114
|
+
const title = (_e = (_d = operationObject.summary) !== null && _d !== void 0 ? _d : operationObject.operationId) !== null && _e !== void 0 ? _e : "Missing summary";
|
|
115
115
|
if (operationObject.description === undefined) {
|
|
116
116
|
operationObject.description =
|
|
117
|
-
(
|
|
117
|
+
(_g = (_f = operationObject.summary) !== null && _f !== void 0 ? _f : operationObject.operationId) !== null && _g !== void 0 ? _g : "";
|
|
118
118
|
}
|
|
119
119
|
const baseId = operationObject.operationId
|
|
120
120
|
? (0, kebabCase_1.default)(operationObject.operationId)
|
|
121
121
|
: (0, kebabCase_1.default)(operationObject.summary);
|
|
122
|
-
const servers = (
|
|
123
|
-
const security = (
|
|
122
|
+
const servers = (_j = (_h = operationObject.servers) !== null && _h !== void 0 ? _h : pathObject.servers) !== null && _j !== void 0 ? _j : openapiData.servers;
|
|
123
|
+
const security = (_k = operationObject.security) !== null && _k !== void 0 ? _k : openapiData.security;
|
|
124
124
|
// Add security schemes so we know how to handle security.
|
|
125
|
-
const securitySchemes = (
|
|
125
|
+
const securitySchemes = (_l = openapiData.components) === null || _l === void 0 ? void 0 : _l.securitySchemes;
|
|
126
126
|
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
127
127
|
if (securitySchemes) {
|
|
128
128
|
for (let securityScheme of Object.values(securitySchemes)) {
|
|
@@ -132,12 +132,12 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
let jsonRequestBodyExample;
|
|
135
|
-
const body = (
|
|
135
|
+
const body = (_o = (_m = operationObject.requestBody) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o["application/json"];
|
|
136
136
|
if (body === null || body === void 0 ? void 0 : body.schema) {
|
|
137
137
|
jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(body.schema);
|
|
138
138
|
}
|
|
139
139
|
// Handle vendor JSON media types
|
|
140
|
-
const bodyContent = (
|
|
140
|
+
const bodyContent = (_p = operationObject.requestBody) === null || _p === void 0 ? void 0 : _p.content;
|
|
141
141
|
if (bodyContent) {
|
|
142
142
|
const firstBodyContentKey = Object.keys(bodyContent)[0];
|
|
143
143
|
if (firstBodyContentKey.endsWith("+json")) {
|
|
@@ -159,7 +159,7 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
159
159
|
frontMatter: {},
|
|
160
160
|
api: {
|
|
161
161
|
...defaults,
|
|
162
|
-
tags:
|
|
162
|
+
tags: operationObject.tags,
|
|
163
163
|
method,
|
|
164
164
|
path,
|
|
165
165
|
servers,
|
|
@@ -259,7 +259,7 @@ async function processOpenapiFiles(files, sidebarOptions) {
|
|
|
259
259
|
// Remove undefined tags due to transient parsing errors
|
|
260
260
|
return x !== undefined;
|
|
261
261
|
});
|
|
262
|
-
return [items, tags];
|
|
262
|
+
return [items, tags[0]];
|
|
263
263
|
}
|
|
264
264
|
exports.processOpenapiFiles = processOpenapiFiles;
|
|
265
265
|
async function processOpenapiFile(openapiData, sidebarOptions) {
|
package/lib/openapi/types.d.ts
CHANGED
package/lib/sidebars/index.js
CHANGED
|
@@ -33,9 +33,16 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
33
33
|
};
|
|
34
34
|
});
|
|
35
35
|
// TODO: make sure we only take the first tag
|
|
36
|
-
const
|
|
36
|
+
const operationTags = (0, uniq_1.default)(apiItems
|
|
37
37
|
.flatMap((item) => item.api.tags)
|
|
38
38
|
.filter((item) => !!item));
|
|
39
|
+
// Only include operation tags that are globally defined
|
|
40
|
+
const apiTags = [];
|
|
41
|
+
tags.forEach((tag) => {
|
|
42
|
+
if (operationTags.includes(tag.name)) {
|
|
43
|
+
apiTags.push(tag.name);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
39
46
|
const basePath = docPath
|
|
40
47
|
? outputDir.split(docPath)[1].replace(/^\/+/g, "")
|
|
41
48
|
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
@@ -66,11 +73,12 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
66
73
|
}
|
|
67
74
|
const tagged = apiTags
|
|
68
75
|
.map((tag) => {
|
|
76
|
+
var _a;
|
|
69
77
|
// Map info object to tag
|
|
70
78
|
const taggedInfoObject = intros.find((i) => i.tags ? i.tags.includes(tag) : undefined);
|
|
71
79
|
const tagObject = tags.flat().find((t) => {
|
|
72
80
|
var _a;
|
|
73
|
-
return (_a =
|
|
81
|
+
return (_a = tag === t.name) !== null && _a !== void 0 ? _a : {
|
|
74
82
|
name: tag,
|
|
75
83
|
description: `${tag} Index`,
|
|
76
84
|
};
|
|
@@ -105,7 +113,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
105
113
|
}
|
|
106
114
|
return {
|
|
107
115
|
type: "category",
|
|
108
|
-
label: tag,
|
|
116
|
+
label: (_a = tagObject === null || tagObject === void 0 ? void 0 : tagObject["x-displayName"]) !== null && _a !== void 0 ? _a : tag,
|
|
109
117
|
link: linkConfig,
|
|
110
118
|
collapsible: sidebarCollapsible,
|
|
111
119
|
collapsed: sidebarCollapsed,
|
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-421",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=14"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "5ca3bcb461f9dad4a78d51fb7c3c59657528e24e"
|
|
71
71
|
}
|
|
@@ -227,8 +227,12 @@ function createItems(schema: SchemaObject) {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
if (schema.items?.allOf !== undefined) {
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
// TODO: figure out if and how we should pass merged required array
|
|
231
|
+
const {
|
|
232
|
+
mergedSchemas,
|
|
233
|
+
}: { mergedSchemas: SchemaObject; required: string[] } = mergeAllOf(
|
|
234
|
+
schema.items?.allOf
|
|
235
|
+
);
|
|
232
236
|
|
|
233
237
|
// Handles combo anyOf/oneOf + properties
|
|
234
238
|
if (
|
|
@@ -387,7 +391,7 @@ function createDetailsNode(
|
|
|
387
391
|
name: string,
|
|
388
392
|
schemaName: string,
|
|
389
393
|
schema: SchemaObject,
|
|
390
|
-
required:
|
|
394
|
+
required: string[] | boolean
|
|
391
395
|
): any {
|
|
392
396
|
return create("SchemaItem", {
|
|
393
397
|
collapsible: true,
|
|
@@ -402,7 +406,7 @@ function createDetailsNode(
|
|
|
402
406
|
style: { opacity: "0.6" },
|
|
403
407
|
children: ` ${schemaName}`,
|
|
404
408
|
}),
|
|
405
|
-
guard(required, () => [
|
|
409
|
+
guard(schema.required && schema.required === true, () => [
|
|
406
410
|
create("strong", {
|
|
407
411
|
style: {
|
|
408
412
|
fontSize: "var(--ifm-code-font-size)",
|
|
@@ -446,7 +450,7 @@ function createPropertyDiscriminator(
|
|
|
446
450
|
schemaName: string,
|
|
447
451
|
schema: SchemaObject,
|
|
448
452
|
discriminator: any,
|
|
449
|
-
required:
|
|
453
|
+
required: string[] | boolean
|
|
450
454
|
): any {
|
|
451
455
|
if (schema === undefined) {
|
|
452
456
|
return undefined;
|
|
@@ -515,7 +519,7 @@ function createPropertyDiscriminator(
|
|
|
515
519
|
interface EdgeProps {
|
|
516
520
|
name: string;
|
|
517
521
|
schema: SchemaObject;
|
|
518
|
-
required: boolean;
|
|
522
|
+
required: string[] | boolean;
|
|
519
523
|
discriminator?: any | unknown;
|
|
520
524
|
}
|
|
521
525
|
|
|
@@ -530,6 +534,8 @@ function createEdges({
|
|
|
530
534
|
}: EdgeProps): any {
|
|
531
535
|
const schemaName = getSchemaName(schema);
|
|
532
536
|
|
|
537
|
+
// if (name === "id") console.log(name, schema, required);
|
|
538
|
+
|
|
533
539
|
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
534
540
|
return createPropertyDiscriminator(
|
|
535
541
|
name,
|
|
@@ -548,9 +554,8 @@ function createEdges({
|
|
|
548
554
|
const {
|
|
549
555
|
mergedSchemas,
|
|
550
556
|
required,
|
|
551
|
-
}: { mergedSchemas: SchemaObject; required:
|
|
552
|
-
schema.allOf
|
|
553
|
-
);
|
|
557
|
+
}: { mergedSchemas: SchemaObject; required: string[] | boolean } =
|
|
558
|
+
mergeAllOf(schema.allOf);
|
|
554
559
|
const mergedSchemaName = getSchemaName(mergedSchemas);
|
|
555
560
|
|
|
556
561
|
if (
|
|
@@ -576,7 +581,7 @@ function createEdges({
|
|
|
576
581
|
return create("SchemaItem", {
|
|
577
582
|
collapsible: false,
|
|
578
583
|
name,
|
|
579
|
-
required,
|
|
584
|
+
required: Array.isArray(required) ? required.includes(name) : required,
|
|
580
585
|
schemaDescription: mergedSchemas.description,
|
|
581
586
|
schemaName: schemaName,
|
|
582
587
|
qualifierMessage: getQualifierMessage(schema),
|
|
@@ -601,7 +606,7 @@ function createEdges({
|
|
|
601
606
|
return create("SchemaItem", {
|
|
602
607
|
collapsible: false,
|
|
603
608
|
name,
|
|
604
|
-
required,
|
|
609
|
+
required: Array.isArray(required) ? required.includes(name) : required,
|
|
605
610
|
schemaDescription: schema.description,
|
|
606
611
|
schemaName: schemaName,
|
|
607
612
|
qualifierMessage: getQualifierMessage(schema),
|
|
@@ -685,7 +690,7 @@ interface Props {
|
|
|
685
690
|
[key: string]: MediaTypeObject;
|
|
686
691
|
};
|
|
687
692
|
description?: string;
|
|
688
|
-
required?: boolean;
|
|
693
|
+
required?: string[] | boolean;
|
|
689
694
|
};
|
|
690
695
|
}
|
|
691
696
|
|
|
@@ -734,7 +739,7 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
|
|
|
734
739
|
children: ` array`,
|
|
735
740
|
})
|
|
736
741
|
),
|
|
737
|
-
guard(body.required, () => [
|
|
742
|
+
guard(body.required && body.required === true, () => [
|
|
738
743
|
create("strong", {
|
|
739
744
|
style: {
|
|
740
745
|
fontSize: "var(--ifm-code-font-size)",
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -124,9 +124,7 @@ function createItems(
|
|
|
124
124
|
securitySchemes: openapiData.components?.securitySchemes,
|
|
125
125
|
info: {
|
|
126
126
|
...openapiData.info,
|
|
127
|
-
tags: openapiData.tags
|
|
128
|
-
getTagDisplayName(tagName.name!, openapiData.tags ?? [])
|
|
129
|
-
),
|
|
127
|
+
tags: openapiData.tags,
|
|
130
128
|
title: openapiData.info.title ?? "Introduction",
|
|
131
129
|
logo: openapiData.info["x-logo"]! as any,
|
|
132
130
|
darkLogo: openapiData.info["x-dark-logo"]! as any,
|
|
@@ -200,9 +198,7 @@ function createItems(
|
|
|
200
198
|
frontMatter: {},
|
|
201
199
|
api: {
|
|
202
200
|
...defaults,
|
|
203
|
-
tags: operationObject.tags
|
|
204
|
-
getTagDisplayName(tagName, openapiData.tags ?? [])
|
|
205
|
-
),
|
|
201
|
+
tags: operationObject.tags,
|
|
206
202
|
method,
|
|
207
203
|
path,
|
|
208
204
|
servers,
|
|
@@ -338,7 +334,7 @@ export async function processOpenapiFiles(
|
|
|
338
334
|
// Remove undefined tags due to transient parsing errors
|
|
339
335
|
return x !== undefined;
|
|
340
336
|
});
|
|
341
|
-
return [items as ApiMetadata[], tags as TagObject[]];
|
|
337
|
+
return [items as ApiMetadata[], tags[0] as TagObject[]];
|
|
342
338
|
}
|
|
343
339
|
|
|
344
340
|
export async function processOpenapiFile(
|
package/src/openapi/types.ts
CHANGED
package/src/sidebars/index.ts
CHANGED
|
@@ -60,12 +60,20 @@ function groupByTags(
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
// TODO: make sure we only take the first tag
|
|
63
|
-
const
|
|
63
|
+
const operationTags = uniq(
|
|
64
64
|
apiItems
|
|
65
65
|
.flatMap((item) => item.api.tags)
|
|
66
66
|
.filter((item): item is string => !!item)
|
|
67
67
|
);
|
|
68
68
|
|
|
69
|
+
// Only include operation tags that are globally defined
|
|
70
|
+
const apiTags: string[] = [];
|
|
71
|
+
tags.forEach((tag) => {
|
|
72
|
+
if (operationTags.includes(tag.name!)) {
|
|
73
|
+
apiTags.push(tag.name!);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
69
77
|
const basePath = docPath
|
|
70
78
|
? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
|
|
71
79
|
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
@@ -107,7 +115,7 @@ function groupByTags(
|
|
|
107
115
|
);
|
|
108
116
|
const tagObject = tags.flat().find(
|
|
109
117
|
(t) =>
|
|
110
|
-
|
|
118
|
+
tag === t.name ?? {
|
|
111
119
|
name: tag,
|
|
112
120
|
description: `${tag} Index`,
|
|
113
121
|
}
|
|
@@ -148,7 +156,7 @@ function groupByTags(
|
|
|
148
156
|
|
|
149
157
|
return {
|
|
150
158
|
type: "category" as const,
|
|
151
|
-
label: tag,
|
|
159
|
+
label: tagObject?.["x-displayName"] ?? tag,
|
|
152
160
|
link: linkConfig,
|
|
153
161
|
collapsible: sidebarCollapsible,
|
|
154
162
|
collapsed: sidebarCollapsed,
|