docusaurus-plugin-openapi-docs 1.5.2 → 1.6.1
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/README.md +20 -19
- package/lib/index.js +5 -0
- package/lib/markdown/createAuthentication.js +45 -13
- package/lib/markdown/createRequestSchema.js +35 -20
- package/lib/markdown/createResponseSchema.js +39 -22
- package/lib/markdown/createStatusCodes.js +3 -1
- package/lib/markdown/index.js +1 -1
- package/lib/markdown/utils.js +2 -2
- package/lib/openapi/createRequestExample.js +1 -1
- package/lib/openapi/createResponseExample.js +1 -1
- package/lib/openapi/openapi.js +7 -1
- package/lib/openapi/utils/loadAndResolveSpec.js +13 -0
- package/lib/options.js +3 -1
- package/lib/sidebars/index.js +3 -1
- package/lib/types.d.ts +1 -0
- package/package.json +8 -8
- package/src/index.ts +6 -0
- package/src/markdown/createAuthentication.ts +53 -17
- package/src/markdown/createRequestSchema.ts +104 -23
- package/src/markdown/createResponseSchema.ts +119 -34
- package/src/markdown/createStatusCodes.ts +38 -39
- package/src/markdown/index.ts +1 -1
- package/src/markdown/utils.ts +2 -2
- package/src/openapi/createRequestExample.ts +1 -1
- package/src/openapi/createResponseExample.ts +1 -1
- package/src/openapi/openapi.ts +7 -1
- package/src/openapi/utils/loadAndResolveSpec.ts +15 -0
- package/src/options.ts +3 -1
- package/src/sidebars/index.ts +6 -1
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -117,28 +117,29 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
|
|
|
117
117
|
|
|
118
118
|
`config` can be configured with the following options:
|
|
119
119
|
|
|
120
|
-
| Name | Type
|
|
121
|
-
| ---------------- |
|
|
122
|
-
| `specPath` | `string`
|
|
123
|
-
| `ouputDir` | `string`
|
|
124
|
-
| `proxy` | `string`
|
|
125
|
-
| `template` | `string`
|
|
126
|
-
| `downloadUrl` | `string`
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
131
|
-
| `
|
|
120
|
+
| Name | Type | Default | Description |
|
|
121
|
+
| ---------------- | --------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
122
|
+
| `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
|
|
123
|
+
| `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
|
|
124
|
+
| `proxy` | `string` | `null` | _Optional:_ Proxy URL to prepend to base URL when performing API requests from browser. |
|
|
125
|
+
| `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
|
|
126
|
+
| `downloadUrl` | `string` | `null` | _Optional:_ Designated URL for downloading OpenAPI specification. (requires `info` section/doc) |
|
|
127
|
+
| `hideSendButton` | `boolean` | `null` | _Optional:_ If set to `true`, hides the "Send API Request" button in API demo panel |
|
|
128
|
+
| `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
|
|
129
|
+
| `version` | `string` | `null` | _Optional:_ Version assigned to single or micro-spec API specified in `specPath`. |
|
|
130
|
+
| `label` | `string` | `null` | _Optional:_ Version label used when generating version selector dropdown menu. |
|
|
131
|
+
| `baseUrl` | `string` | `null` | _Optional:_ Version base URL used when generating version selector dropdown menu. |
|
|
132
|
+
| `versions` | `object` | `null` | _Optional:_ Set of options for versioning configuration. See below for a list of supported options. |
|
|
132
133
|
|
|
133
134
|
`sidebarOptions` can be configured with the following options:
|
|
134
135
|
|
|
135
|
-
| Name | Type | Default | Description
|
|
136
|
-
| -------------------- | --------- | ------- |
|
|
137
|
-
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by `tag`.
|
|
138
|
-
| `categoryLinkSource` | `string` | `null` | Defines what source to use for rendering category link pages when grouping paths by tag. <br/><br/>The supported options are as follows: <br/><br/> `tag`: Sets the category link config type to `generated-index` and uses the tag description as the link config description. <br/><br/>`info`: Sets the category link config type to `doc` and renders the `info` section as the category link (recommended only for multi/micro-spec scenarios). |
|
|
139
|
-
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default.
|
|
140
|
-
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default.
|
|
141
|
-
| `customProps` | `object` | `null` | Additional props for customizing a sidebar item.
|
|
136
|
+
| Name | Type | Default | Description |
|
|
137
|
+
| -------------------- | --------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
138
|
+
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by `tag`. |
|
|
139
|
+
| `categoryLinkSource` | `string` | `null` | Defines what source to use for rendering category link pages when grouping paths by tag. <br/><br/>The supported options are as follows: <br/><br/> `tag`: Sets the category link config type to `generated-index` and uses the tag description as the link config description. <br/><br/>`info`: Sets the category link config type to `doc` and renders the `info` section as the category link (recommended only for multi/micro-spec scenarios). <br/><br/>`none`: Does not create pages for categories, only groups that can be expanded/collapsed. |
|
|
140
|
+
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
|
|
141
|
+
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
|
|
142
|
+
| `customProps` | `object` | `null` | Additional props for customizing a sidebar item. |
|
|
142
143
|
|
|
143
144
|
> You may optionally configure a `sidebarOptions`. In doing so, an individual `sidebar.js` slice with the configured options will be generated within the respective `outputDir`.
|
|
144
145
|
|
package/lib/index.js
CHANGED
|
@@ -77,6 +77,8 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
77
77
|
let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
78
78
|
async function generateApiDocs(options, pluginId) {
|
|
79
79
|
let { specPath, outputDir, template, downloadUrl, sidebarOptions } = options;
|
|
80
|
+
// Remove trailing slash before proceeding
|
|
81
|
+
outputDir = outputDir.replace(/\/$/, "");
|
|
80
82
|
// Override docPath if pluginId provided
|
|
81
83
|
if (pluginId) {
|
|
82
84
|
docData = getDocsPluginConfig(presetsPlugins, pluginId);
|
|
@@ -147,6 +149,9 @@ custom_edit_url: null
|
|
|
147
149
|
{{#frontMatter.proxy}}
|
|
148
150
|
proxy: {{{frontMatter.proxy}}}
|
|
149
151
|
{{/frontMatter.proxy}}
|
|
152
|
+
{{#frontMatter.hide_send_button}}
|
|
153
|
+
hide_send_button: true
|
|
154
|
+
{{/frontMatter.hide_send_button}}
|
|
150
155
|
---
|
|
151
156
|
|
|
152
157
|
{{{markdown}}}
|
|
@@ -13,7 +13,7 @@ function createAuthentication(securitySchemes) {
|
|
|
13
13
|
if (!securitySchemes || !Object.keys(securitySchemes).length)
|
|
14
14
|
return "";
|
|
15
15
|
const createAuthenticationTable = (securityScheme) => {
|
|
16
|
-
const { bearerFormat, flows, name, scheme, type } = securityScheme;
|
|
16
|
+
const { bearerFormat, flows, name, scheme, type, openIdConnectUrl } = securityScheme;
|
|
17
17
|
const createSecuritySchemeTypeRow = () => (0, utils_1.create)("tr", {
|
|
18
18
|
children: [
|
|
19
19
|
(0, utils_1.create)("th", { children: "Security Scheme Type:" }),
|
|
@@ -25,7 +25,7 @@ function createAuthentication(securitySchemes) {
|
|
|
25
25
|
const { authorizationUrl, tokenUrl, refreshUrl, scopes } = flowObj;
|
|
26
26
|
return (0, utils_1.create)("tr", {
|
|
27
27
|
children: [
|
|
28
|
-
(0, utils_1.create)("th", { children:
|
|
28
|
+
(0, utils_1.create)("th", { children: `OAuth Flow (${flowType}):` }),
|
|
29
29
|
(0, utils_1.create)("td", {
|
|
30
30
|
children: [
|
|
31
31
|
(0, utils_1.guard)(tokenUrl, () => (0, utils_1.create)("p", { children: `Token URL: ${tokenUrl}` })),
|
|
@@ -76,12 +76,12 @@ function createAuthentication(securitySchemes) {
|
|
|
76
76
|
(0, utils_1.create)("td", { children: scheme }),
|
|
77
77
|
],
|
|
78
78
|
}),
|
|
79
|
-
(0, utils_1.create)("tr", {
|
|
79
|
+
(0, utils_1.guard)(bearerFormat, () => (0, utils_1.create)("tr", {
|
|
80
80
|
children: [
|
|
81
81
|
(0, utils_1.create)("th", { children: "Bearer format:" }),
|
|
82
82
|
(0, utils_1.create)("td", { children: bearerFormat }),
|
|
83
83
|
],
|
|
84
|
-
}),
|
|
84
|
+
})),
|
|
85
85
|
],
|
|
86
86
|
}),
|
|
87
87
|
}),
|
|
@@ -100,20 +100,51 @@ function createAuthentication(securitySchemes) {
|
|
|
100
100
|
}),
|
|
101
101
|
],
|
|
102
102
|
});
|
|
103
|
+
case "openIdConnect":
|
|
104
|
+
return (0, utils_1.create)("div", {
|
|
105
|
+
children: [
|
|
106
|
+
(0, utils_1.create)("table", {
|
|
107
|
+
children: (0, utils_1.create)("tbody", {
|
|
108
|
+
children: [
|
|
109
|
+
createSecuritySchemeTypeRow(),
|
|
110
|
+
(0, utils_1.guard)(openIdConnectUrl, () => (0, utils_1.create)("tr", {
|
|
111
|
+
children: [
|
|
112
|
+
(0, utils_1.create)("th", { children: "OpenID Connect URL:" }),
|
|
113
|
+
(0, utils_1.create)("td", { children: openIdConnectUrl }),
|
|
114
|
+
],
|
|
115
|
+
})),
|
|
116
|
+
],
|
|
117
|
+
}),
|
|
118
|
+
}),
|
|
119
|
+
],
|
|
120
|
+
});
|
|
103
121
|
default:
|
|
104
122
|
return "";
|
|
105
123
|
}
|
|
106
124
|
};
|
|
107
|
-
const formatTabLabel = (
|
|
108
|
-
const formattedLabel =
|
|
125
|
+
const formatTabLabel = (key, type, scheme) => {
|
|
126
|
+
const formattedLabel = key
|
|
109
127
|
.replace(/(_|-)/g, " ")
|
|
110
128
|
.trim()
|
|
111
129
|
.replace(/\w\S*/g, (str) => str.charAt(0).toUpperCase() + str.substr(1))
|
|
112
130
|
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
113
131
|
.replace(/([A-Z])([A-Z][a-z])/g, "$1 $2");
|
|
114
|
-
const isOAuth =
|
|
115
|
-
const isApiKey =
|
|
116
|
-
|
|
132
|
+
const isOAuth = type === "oauth2";
|
|
133
|
+
const isApiKey = type === "apiKey";
|
|
134
|
+
const isHttpBasic = type === "http" && scheme === "basic";
|
|
135
|
+
const isHttpBearer = type === "http" && scheme === "bearer";
|
|
136
|
+
const isOpenId = type === "openIdConnect";
|
|
137
|
+
if (isOAuth)
|
|
138
|
+
return `OAuth 2.0: ${key}`;
|
|
139
|
+
if (isApiKey)
|
|
140
|
+
return `API Key: ${key}`;
|
|
141
|
+
if (isHttpBasic)
|
|
142
|
+
return "HTTP: Basic Auth";
|
|
143
|
+
if (isHttpBearer)
|
|
144
|
+
return "HTTP: Bearer Auth";
|
|
145
|
+
if (isOpenId)
|
|
146
|
+
return `OpenID Connect: ${key}`;
|
|
147
|
+
return formattedLabel;
|
|
117
148
|
};
|
|
118
149
|
return (0, utils_1.create)("div", {
|
|
119
150
|
children: [
|
|
@@ -122,10 +153,11 @@ function createAuthentication(securitySchemes) {
|
|
|
122
153
|
id: "authentication",
|
|
123
154
|
style: { marginBottom: "1rem" },
|
|
124
155
|
}),
|
|
125
|
-
(0, utils_1.create)("
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
156
|
+
(0, utils_1.create)("SchemaTabs", {
|
|
157
|
+
className: "openapi-tabs__security-schemes",
|
|
158
|
+
children: Object.entries(securitySchemes).map(([schemeKey, schemeObj]) => (0, utils_1.create)("TabItem", {
|
|
159
|
+
label: formatTabLabel(schemeKey, schemeObj.type, schemeObj.scheme),
|
|
160
|
+
value: `${schemeKey}`,
|
|
129
161
|
children: [
|
|
130
162
|
(0, createDescription_1.createDescription)(schemeObj.description),
|
|
131
163
|
createAuthenticationTable(schemeObj),
|
|
@@ -30,7 +30,7 @@ function mergeAllOf(allOf) {
|
|
|
30
30
|
return true;
|
|
31
31
|
},
|
|
32
32
|
},
|
|
33
|
-
ignoreAdditionalProperties:
|
|
33
|
+
ignoreAdditionalProperties: false,
|
|
34
34
|
});
|
|
35
35
|
const required = allOf.reduce((acc, cur) => {
|
|
36
36
|
if (Array.isArray(cur.required)) {
|
|
@@ -142,12 +142,25 @@ function createAdditionalProperties(schema) {
|
|
|
142
142
|
// },
|
|
143
143
|
// type: 'array'
|
|
144
144
|
// }
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
((
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
const additionalProperties = schema.additionalProperties;
|
|
146
|
+
const type = additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.type;
|
|
147
|
+
if ((type === "object" || type === "array") &&
|
|
148
|
+
((additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.properties) ||
|
|
149
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.items) ||
|
|
150
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.allOf) ||
|
|
151
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.additionalProperties) ||
|
|
152
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.oneOf) ||
|
|
153
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.anyOf))) {
|
|
154
|
+
const title = additionalProperties.title;
|
|
155
|
+
const schemaName = title ? `object (${title})` : "object";
|
|
156
|
+
const required = (_a = schema.required) !== null && _a !== void 0 ? _a : false;
|
|
157
|
+
return createDetailsNode("property name*", schemaName, additionalProperties, required, schema.nullable);
|
|
158
|
+
}
|
|
159
|
+
if (((_b = schema.additionalProperties) === null || _b === void 0 ? void 0 : _b.type) === "string" ||
|
|
160
|
+
((_c = schema.additionalProperties) === null || _c === void 0 ? void 0 : _c.type) === "object" ||
|
|
161
|
+
((_d = schema.additionalProperties) === null || _d === void 0 ? void 0 : _d.type) === "boolean" ||
|
|
162
|
+
((_e = schema.additionalProperties) === null || _e === void 0 ? void 0 : _e.type) === "integer" ||
|
|
163
|
+
((_f = schema.additionalProperties) === null || _f === void 0 ? void 0 : _f.type) === "number") {
|
|
151
164
|
const additionalProperties = (_g = schema.additionalProperties) === null || _g === void 0 ? void 0 : _g.additionalProperties;
|
|
152
165
|
if (additionalProperties !== undefined) {
|
|
153
166
|
const type = (_j = (_h = schema.additionalProperties) === null || _h === void 0 ? void 0 : _h.additionalProperties) === null || _j === void 0 ? void 0 : _j.type;
|
|
@@ -373,7 +386,7 @@ function createItems(schema) {
|
|
|
373
386
|
// }),
|
|
374
387
|
// });
|
|
375
388
|
// }
|
|
376
|
-
function createDetailsNode(name, schemaName, schema, required) {
|
|
389
|
+
function createDetailsNode(name, schemaName, schema, required, nullable) {
|
|
377
390
|
return (0, utils_1.create)("SchemaItem", {
|
|
378
391
|
collapsible: true,
|
|
379
392
|
className: "schemaItem",
|
|
@@ -387,7 +400,8 @@ function createDetailsNode(name, schemaName, schema, required) {
|
|
|
387
400
|
style: { opacity: "0.6" },
|
|
388
401
|
children: ` ${schemaName}`,
|
|
389
402
|
}),
|
|
390
|
-
(0, utils_1.guard)(schema.nullable && schema.nullable === true
|
|
403
|
+
(0, utils_1.guard)((schema.nullable && schema.nullable === true) ||
|
|
404
|
+
(nullable && nullable === true), () => [
|
|
391
405
|
(0, utils_1.create)("strong", {
|
|
392
406
|
style: {
|
|
393
407
|
fontSize: "var(--ifm-code-font-size)",
|
|
@@ -498,24 +512,24 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
498
512
|
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
499
513
|
}
|
|
500
514
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
501
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
515
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
502
516
|
}
|
|
503
517
|
if (schema.allOf !== undefined) {
|
|
504
518
|
const { mergedSchemas, required, } = mergeAllOf(schema.allOf);
|
|
505
519
|
const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
|
|
506
520
|
if (mergedSchemas.oneOf !== undefined ||
|
|
507
521
|
mergedSchemas.anyOf !== undefined) {
|
|
508
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
522
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
509
523
|
}
|
|
510
524
|
if (mergedSchemas.properties !== undefined) {
|
|
511
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
525
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
512
526
|
}
|
|
513
527
|
if (mergedSchemas.additionalProperties !== undefined) {
|
|
514
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
528
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
515
529
|
}
|
|
516
530
|
// array of objects
|
|
517
531
|
if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
518
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
532
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
519
533
|
}
|
|
520
534
|
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
521
535
|
return undefined;
|
|
@@ -530,17 +544,17 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
530
544
|
});
|
|
531
545
|
}
|
|
532
546
|
if (schema.properties !== undefined) {
|
|
533
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
547
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
534
548
|
}
|
|
535
549
|
if (schema.additionalProperties !== undefined) {
|
|
536
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
550
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
537
551
|
}
|
|
538
552
|
// array of objects
|
|
539
553
|
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.properties) !== undefined) {
|
|
540
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
554
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
541
555
|
}
|
|
542
556
|
if (((_c = schema.items) === null || _c === void 0 ? void 0 : _c.anyOf) !== undefined || ((_d = schema.items) === null || _d === void 0 ? void 0 : _d.oneOf) !== undefined) {
|
|
543
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
557
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
544
558
|
}
|
|
545
559
|
if (schema.readOnly && schema.readOnly === true) {
|
|
546
560
|
return undefined;
|
|
@@ -610,9 +624,10 @@ function createNodes(schema) {
|
|
|
610
624
|
}
|
|
611
625
|
// Unknown node/schema type should return undefined
|
|
612
626
|
// So far, haven't seen this hit in testing
|
|
613
|
-
return
|
|
627
|
+
return "any";
|
|
614
628
|
}
|
|
615
629
|
function createRequestSchema({ title, body, ...rest }) {
|
|
630
|
+
var _a;
|
|
616
631
|
if (body === undefined ||
|
|
617
632
|
body.content === undefined ||
|
|
618
633
|
Object.keys(body).length === 0 ||
|
|
@@ -681,7 +696,7 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
681
696
|
});
|
|
682
697
|
}
|
|
683
698
|
const randomFirstKey = Object.keys(body.content)[0];
|
|
684
|
-
const firstBody = body.content[randomFirstKey].schema;
|
|
699
|
+
const firstBody = (_a = body.content[randomFirstKey].schema) !== null && _a !== void 0 ? _a : body.content[randomFirstKey];
|
|
685
700
|
if (firstBody === undefined) {
|
|
686
701
|
return undefined;
|
|
687
702
|
}
|
|
@@ -143,12 +143,25 @@ function createAdditionalProperties(schema) {
|
|
|
143
143
|
// },
|
|
144
144
|
// type: 'array'
|
|
145
145
|
// }
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
((
|
|
150
|
-
|
|
151
|
-
|
|
146
|
+
const additionalProperties = schema.additionalProperties;
|
|
147
|
+
const type = additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.type;
|
|
148
|
+
if ((type === "object" || type === "array") &&
|
|
149
|
+
((additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.properties) ||
|
|
150
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.items) ||
|
|
151
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.allOf) ||
|
|
152
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.additionalProperties) ||
|
|
153
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.oneOf) ||
|
|
154
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.anyOf))) {
|
|
155
|
+
const title = additionalProperties.title;
|
|
156
|
+
const schemaName = title ? `object (${title})` : "object";
|
|
157
|
+
const required = (_a = schema.required) !== null && _a !== void 0 ? _a : false;
|
|
158
|
+
return createDetailsNode("property name*", schemaName, additionalProperties, required, schema.nullable);
|
|
159
|
+
}
|
|
160
|
+
if (((_b = schema.additionalProperties) === null || _b === void 0 ? void 0 : _b.type) === "string" ||
|
|
161
|
+
((_c = schema.additionalProperties) === null || _c === void 0 ? void 0 : _c.type) === "object" ||
|
|
162
|
+
((_d = schema.additionalProperties) === null || _d === void 0 ? void 0 : _d.type) === "boolean" ||
|
|
163
|
+
((_e = schema.additionalProperties) === null || _e === void 0 ? void 0 : _e.type) === "integer" ||
|
|
164
|
+
((_f = schema.additionalProperties) === null || _f === void 0 ? void 0 : _f.type) === "number") {
|
|
152
165
|
const additionalProperties = (_g = schema.additionalProperties) === null || _g === void 0 ? void 0 : _g.additionalProperties;
|
|
153
166
|
if (additionalProperties !== undefined) {
|
|
154
167
|
const type = (_j = (_h = schema.additionalProperties) === null || _h === void 0 ? void 0 : _h.additionalProperties) === null || _j === void 0 ? void 0 : _j.type;
|
|
@@ -374,7 +387,7 @@ function createItems(schema) {
|
|
|
374
387
|
// }),
|
|
375
388
|
// });
|
|
376
389
|
// }
|
|
377
|
-
function createDetailsNode(name, schemaName, schema, required) {
|
|
390
|
+
function createDetailsNode(name, schemaName, schema, required, nullable) {
|
|
378
391
|
return (0, utils_1.create)("SchemaItem", {
|
|
379
392
|
collapsible: true,
|
|
380
393
|
className: "schemaItem",
|
|
@@ -388,7 +401,8 @@ function createDetailsNode(name, schemaName, schema, required) {
|
|
|
388
401
|
style: { opacity: "0.6" },
|
|
389
402
|
children: ` ${schemaName}`,
|
|
390
403
|
}),
|
|
391
|
-
(0, utils_1.guard)(schema.nullable && schema.nullable === true
|
|
404
|
+
(0, utils_1.guard)((schema.nullable && schema.nullable === true) ||
|
|
405
|
+
(nullable && nullable === true), () => [
|
|
392
406
|
(0, utils_1.create)("strong", {
|
|
393
407
|
style: {
|
|
394
408
|
fontSize: "var(--ifm-code-font-size)",
|
|
@@ -397,7 +411,9 @@ function createDetailsNode(name, schemaName, schema, required) {
|
|
|
397
411
|
children: " nullable",
|
|
398
412
|
}),
|
|
399
413
|
]),
|
|
400
|
-
(0, utils_1.guard)(
|
|
414
|
+
(0, utils_1.guard)(Array.isArray(required)
|
|
415
|
+
? required.includes(name)
|
|
416
|
+
: required === true, () => [
|
|
401
417
|
(0, utils_1.create)("strong", {
|
|
402
418
|
style: {
|
|
403
419
|
fontSize: "var(--ifm-code-font-size)",
|
|
@@ -497,24 +513,24 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
497
513
|
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
498
514
|
}
|
|
499
515
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
500
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
516
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
501
517
|
}
|
|
502
518
|
if (schema.allOf !== undefined) {
|
|
503
519
|
const { mergedSchemas, required, } = mergeAllOf(schema.allOf);
|
|
504
520
|
const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
|
|
505
521
|
if (mergedSchemas.oneOf !== undefined ||
|
|
506
522
|
mergedSchemas.anyOf !== undefined) {
|
|
507
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
523
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
508
524
|
}
|
|
509
525
|
if (mergedSchemas.properties !== undefined) {
|
|
510
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
526
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
511
527
|
}
|
|
512
528
|
if (mergedSchemas.additionalProperties !== undefined) {
|
|
513
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
529
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
514
530
|
}
|
|
515
531
|
// array of objects
|
|
516
532
|
if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
517
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
533
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
518
534
|
}
|
|
519
535
|
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
|
|
520
536
|
return undefined;
|
|
@@ -522,24 +538,24 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
522
538
|
return (0, utils_1.create)("SchemaItem", {
|
|
523
539
|
collapsible: false,
|
|
524
540
|
name,
|
|
525
|
-
required:
|
|
541
|
+
required: Array.isArray(required) ? required.includes(name) : required,
|
|
526
542
|
schemaName: schemaName,
|
|
527
543
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
528
544
|
schema: mergedSchemas,
|
|
529
545
|
});
|
|
530
546
|
}
|
|
531
547
|
if (schema.properties !== undefined) {
|
|
532
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
548
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
533
549
|
}
|
|
534
550
|
if (schema.additionalProperties !== undefined) {
|
|
535
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
551
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
536
552
|
}
|
|
537
553
|
// array of objects
|
|
538
554
|
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.properties) !== undefined) {
|
|
539
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
555
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
540
556
|
}
|
|
541
557
|
if (((_c = schema.items) === null || _c === void 0 ? void 0 : _c.anyOf) !== undefined || ((_d = schema.items) === null || _d === void 0 ? void 0 : _d.oneOf) !== undefined) {
|
|
542
|
-
return createDetailsNode(name, schemaName, schema, required);
|
|
558
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
543
559
|
}
|
|
544
560
|
if (schema.writeOnly && schema.writeOnly === true) {
|
|
545
561
|
return undefined;
|
|
@@ -548,7 +564,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
548
564
|
return (0, utils_1.create)("SchemaItem", {
|
|
549
565
|
collapsible: false,
|
|
550
566
|
name,
|
|
551
|
-
required:
|
|
567
|
+
required: Array.isArray(required) ? required.includes(name) : required,
|
|
552
568
|
schemaName: schemaName,
|
|
553
569
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
554
570
|
schema: schema,
|
|
@@ -611,7 +627,7 @@ function createNodes(schema) {
|
|
|
611
627
|
}
|
|
612
628
|
// Unknown node/schema type should return undefined
|
|
613
629
|
// So far, haven't seen this hit in testing
|
|
614
|
-
return
|
|
630
|
+
return "any";
|
|
615
631
|
}
|
|
616
632
|
function createResponseSchema({ title, body, ...rest }) {
|
|
617
633
|
if (body === undefined ||
|
|
@@ -626,9 +642,10 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
626
642
|
return (0, utils_1.create)("MimeTabs", {
|
|
627
643
|
schemaType: "response",
|
|
628
644
|
children: mimeTypes.map((mimeType) => {
|
|
645
|
+
var _a;
|
|
629
646
|
const responseExamples = body.content[mimeType].examples;
|
|
630
647
|
const responseExample = body.content[mimeType].example;
|
|
631
|
-
const firstBody = body.content[mimeType].schema;
|
|
648
|
+
const firstBody = (_a = body.content[mimeType].schema) !== null && _a !== void 0 ? _a : body.content[mimeType];
|
|
632
649
|
if (firstBody === undefined &&
|
|
633
650
|
responseExample === undefined &&
|
|
634
651
|
responseExamples === undefined) {
|
|
@@ -66,7 +66,9 @@ function createResponseHeaders(responseHeaders) {
|
|
|
66
66
|
style: { marginLeft: "1rem" },
|
|
67
67
|
children: [
|
|
68
68
|
Object.entries(responseHeaders).map(([headerName, headerObj]) => {
|
|
69
|
-
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const { description, example } = headerObj;
|
|
71
|
+
const type = (_b = (_a = headerObj.schema) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : "any";
|
|
70
72
|
return (0, utils_1.create)("li", {
|
|
71
73
|
className: "schemaItem",
|
|
72
74
|
children: [
|
package/lib/markdown/index.js
CHANGED
|
@@ -48,7 +48,7 @@ exports.createApiPageMD = createApiPageMD;
|
|
|
48
48
|
function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, downloadUrl, }) {
|
|
49
49
|
return (0, utils_1.render)([
|
|
50
50
|
`import ApiLogo from "@theme/ApiLogo";\n`,
|
|
51
|
-
`import
|
|
51
|
+
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
52
52
|
`import TabItem from "@theme/TabItem";\n`,
|
|
53
53
|
`import Export from "@theme/ApiDemoPanel/Export";\n\n`,
|
|
54
54
|
(0, createVersionBadge_1.createVersionBadge)(version),
|
package/lib/markdown/utils.js
CHANGED
|
@@ -17,7 +17,7 @@ function create(tag, props) {
|
|
|
17
17
|
}
|
|
18
18
|
exports.create = create;
|
|
19
19
|
function guard(value, cb) {
|
|
20
|
-
if (value) {
|
|
20
|
+
if (!!value) {
|
|
21
21
|
const children = cb(value);
|
|
22
22
|
return render(children);
|
|
23
23
|
}
|
|
@@ -36,5 +36,5 @@ function render(children) {
|
|
|
36
36
|
exports.render = render;
|
|
37
37
|
// Regex to selectively URL-encode '>' and '<' chars
|
|
38
38
|
exports.lessThan = /<(?!(=|button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/gu;
|
|
39
|
-
exports.greaterThan = /(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>/gu;
|
|
39
|
+
exports.greaterThan = /(?<!(button|code|details|summary|hr|br|span|strong|small|table|thead|tbody|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>/gu;
|
|
40
40
|
exports.codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
|
|
@@ -18,7 +18,7 @@ const primitives = {
|
|
|
18
18
|
default: () => "string",
|
|
19
19
|
email: () => "user@example.com",
|
|
20
20
|
date: () => new Date().toISOString().substring(0, 10),
|
|
21
|
-
"date-time": () => new Date().toISOString()
|
|
21
|
+
"date-time": () => new Date().toISOString(),
|
|
22
22
|
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
23
23
|
hostname: () => "example.com",
|
|
24
24
|
ipv4: () => "198.51.100.42",
|
|
@@ -18,7 +18,7 @@ const primitives = {
|
|
|
18
18
|
default: () => "string",
|
|
19
19
|
email: () => "user@example.com",
|
|
20
20
|
date: () => new Date().toISOString().substring(0, 10),
|
|
21
|
-
"date-time": () => new Date().toISOString()
|
|
21
|
+
"date-time": () => new Date().toISOString(),
|
|
22
22
|
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
23
23
|
hostname: () => "example.com",
|
|
24
24
|
ipv4: () => "198.51.100.42",
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -66,7 +66,7 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
66
66
|
let items = [];
|
|
67
67
|
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
68
68
|
const infoId = (0, kebabCase_1.default)(infoIdSpaces);
|
|
69
|
-
if (openapiData.info.description) {
|
|
69
|
+
if (openapiData.info.description || openapiData.info.title) {
|
|
70
70
|
// Only create an info page if we have a description.
|
|
71
71
|
const infoDescription = (_a = openapiData.info) === null || _a === void 0 ? void 0 : _a.description;
|
|
72
72
|
let splitDescription;
|
|
@@ -173,6 +173,9 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
173
173
|
.replace(/\s+$/, "")
|
|
174
174
|
: "",
|
|
175
175
|
...((options === null || options === void 0 ? void 0 : options.proxy) && { proxy: options.proxy }),
|
|
176
|
+
...((options === null || options === void 0 ? void 0 : options.hideSendButton) && {
|
|
177
|
+
hide_send_button: options.hideSendButton,
|
|
178
|
+
}),
|
|
176
179
|
},
|
|
177
180
|
api: {
|
|
178
181
|
...defaults,
|
|
@@ -264,6 +267,9 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
264
267
|
.replace(/\s+$/, "")
|
|
265
268
|
: "",
|
|
266
269
|
...((options === null || options === void 0 ? void 0 : options.proxy) && { proxy: options.proxy }),
|
|
270
|
+
...((options === null || options === void 0 ? void 0 : options.hideSendButton) && {
|
|
271
|
+
hide_send_button: options.hideSendButton,
|
|
272
|
+
}),
|
|
267
273
|
},
|
|
268
274
|
api: {
|
|
269
275
|
...defaults,
|
|
@@ -114,6 +114,19 @@ async function loadAndResolveSpec(specUrlOrObject) {
|
|
|
114
114
|
// Force dereference ?
|
|
115
115
|
// bundleOpts["dereference"] = true;
|
|
116
116
|
const { bundle: { parsed }, } = await (0, openapi_core_1.bundle)(bundleOpts);
|
|
117
|
+
//Pre-processing before resolving JSON refs
|
|
118
|
+
if (parsed.components) {
|
|
119
|
+
for (let [component, type] of Object.entries(parsed.components)) {
|
|
120
|
+
if (component === "schemas") {
|
|
121
|
+
for (let [schemaKey, schemaValue] of Object.entries(type)) {
|
|
122
|
+
const title = schemaValue["title"];
|
|
123
|
+
if (!title) {
|
|
124
|
+
schemaValue.title = schemaKey;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
117
130
|
const resolved = await resolveJsonRefs(parsed);
|
|
118
131
|
// Force serialization and replace circular $ref pointers
|
|
119
132
|
// @ts-ignore
|
package/lib/options.js
CHANGED
|
@@ -10,7 +10,8 @@ exports.OptionsSchema = void 0;
|
|
|
10
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
11
|
const sidebarOptions = utils_validation_1.Joi.object({
|
|
12
12
|
groupPathsBy: utils_validation_1.Joi.string().valid("tag"),
|
|
13
|
-
|
|
13
|
+
// TODO: Remove "none" in 2.0, make it the default if not specified
|
|
14
|
+
categoryLinkSource: utils_validation_1.Joi.string().valid("tag", "info", "none"),
|
|
14
15
|
customProps: utils_validation_1.Joi.object(),
|
|
15
16
|
sidebarCollapsible: utils_validation_1.Joi.boolean(),
|
|
16
17
|
sidebarCollapsed: utils_validation_1.Joi.boolean(),
|
|
@@ -25,6 +26,7 @@ exports.OptionsSchema = utils_validation_1.Joi.object({
|
|
|
25
26
|
outputDir: utils_validation_1.Joi.string().required(),
|
|
26
27
|
template: utils_validation_1.Joi.string(),
|
|
27
28
|
downloadUrl: utils_validation_1.Joi.string(),
|
|
29
|
+
hideSendButton: utils_validation_1.Joi.boolean(),
|
|
28
30
|
sidebarOptions: sidebarOptions,
|
|
29
31
|
version: utils_validation_1.Joi.string().when("versions", {
|
|
30
32
|
is: utils_validation_1.Joi.exist(),
|
package/lib/sidebars/index.js
CHANGED
|
@@ -21,7 +21,9 @@ function isInfoItem(item) {
|
|
|
21
21
|
return item.type === "info";
|
|
22
22
|
}
|
|
23
23
|
function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
24
|
-
|
|
24
|
+
let { outputDir, label } = options;
|
|
25
|
+
// Remove trailing slash before proceeding
|
|
26
|
+
outputDir = outputDir.replace(/\/$/, "");
|
|
25
27
|
const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
|
|
26
28
|
const apiItems = items.filter(isApiItem);
|
|
27
29
|
const infoItems = items.filter(isInfoItem);
|