docusaurus-plugin-openapi-docs 1.2.1 → 1.3.0
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/LICENSE +21 -0
- package/lib/markdown/createRequestSchema.js +1 -1
- package/lib/markdown/createResponseSchema.js +1 -1
- package/lib/markdown/createStatusCodes.js +20 -0
- package/lib/openapi/openapi.js +11 -0
- package/package.json +3 -2
- package/src/markdown/createRequestSchema.ts +1 -1
- package/src/markdown/createResponseSchema.ts +1 -1
- package/src/markdown/createStatusCodes.ts +20 -0
- package/src/openapi/openapi.ts +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Palo Alto Networks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -566,7 +566,7 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
566
566
|
const mimeTypes = Object.keys(body.content);
|
|
567
567
|
if (mimeTypes && mimeTypes.length > 1) {
|
|
568
568
|
return (0, utils_1.create)("MimeTabs", {
|
|
569
|
-
|
|
569
|
+
schemaType: "request",
|
|
570
570
|
children: mimeTypes.map((mimeType) => {
|
|
571
571
|
const firstBody = body.content[mimeType].schema;
|
|
572
572
|
if (firstBody === undefined) {
|
|
@@ -566,7 +566,7 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
566
566
|
const mimeTypes = Object.keys(body.content);
|
|
567
567
|
if (mimeTypes && mimeTypes.length) {
|
|
568
568
|
return (0, utils_1.create)("MimeTabs", {
|
|
569
|
-
|
|
569
|
+
schemaType: "response",
|
|
570
570
|
children: mimeTypes.map((mimeType) => {
|
|
571
571
|
const responseExamples = body.content[mimeType].examples;
|
|
572
572
|
const responseExample = body.content[mimeType].example;
|
|
@@ -117,6 +117,11 @@ function createResponseExamples(responseExamples, mimeType) {
|
|
|
117
117
|
label: `${finalFormattedName}`,
|
|
118
118
|
value: `${finalFormattedName}`,
|
|
119
119
|
children: [
|
|
120
|
+
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
121
|
+
(0, utils_1.create)("p", {
|
|
122
|
+
children: ` ${summary}`,
|
|
123
|
+
}),
|
|
124
|
+
]),
|
|
120
125
|
(0, utils_1.create)("ResponseSamples", {
|
|
121
126
|
responseExample: JSON.stringify(exampleValue.value, null, 2),
|
|
122
127
|
language: language,
|
|
@@ -128,6 +133,11 @@ function createResponseExamples(responseExamples, mimeType) {
|
|
|
128
133
|
label: `${finalFormattedName}`,
|
|
129
134
|
value: `${finalFormattedName}`,
|
|
130
135
|
children: [
|
|
136
|
+
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
137
|
+
(0, utils_1.create)("p", {
|
|
138
|
+
children: ` ${summary}`,
|
|
139
|
+
}),
|
|
140
|
+
]),
|
|
131
141
|
(0, utils_1.create)("ResponseSamples", {
|
|
132
142
|
responseExample: exampleValue.value,
|
|
133
143
|
language: language,
|
|
@@ -150,6 +160,11 @@ function createResponseExample(responseExample, mimeType) {
|
|
|
150
160
|
label: `Example`,
|
|
151
161
|
value: `Example`,
|
|
152
162
|
children: [
|
|
163
|
+
(0, utils_2.guard)(responseExample.summary, (summary) => [
|
|
164
|
+
(0, utils_1.create)("p", {
|
|
165
|
+
children: ` ${summary}`,
|
|
166
|
+
}),
|
|
167
|
+
]),
|
|
153
168
|
(0, utils_1.create)("ResponseSamples", {
|
|
154
169
|
responseExample: JSON.stringify(responseExample, null, 2),
|
|
155
170
|
language: language,
|
|
@@ -161,6 +176,11 @@ function createResponseExample(responseExample, mimeType) {
|
|
|
161
176
|
label: `Example`,
|
|
162
177
|
value: `Example`,
|
|
163
178
|
children: [
|
|
179
|
+
(0, utils_2.guard)(responseExample.summary, (summary) => [
|
|
180
|
+
(0, utils_1.create)("p", {
|
|
181
|
+
children: ` ${summary}`,
|
|
182
|
+
}),
|
|
183
|
+
]),
|
|
164
184
|
(0, utils_1.create)("ResponseSamples", {
|
|
165
185
|
responseExample: responseExample,
|
|
166
186
|
language: language,
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -18,6 +18,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
18
18
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
19
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
20
20
|
const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
|
|
21
|
+
const unionBy_1 = __importDefault(require("lodash/unionBy"));
|
|
21
22
|
const index_1 = require("../index");
|
|
22
23
|
const createRequestExample_1 = require("./createRequestExample");
|
|
23
24
|
const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
|
|
@@ -151,6 +152,16 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
151
152
|
}
|
|
152
153
|
// TODO: Don't include summary temporarilly
|
|
153
154
|
const { summary, ...defaults } = operationObject;
|
|
155
|
+
// Merge common parameters with operation parameters
|
|
156
|
+
// Operation params take precendence over common params
|
|
157
|
+
if (parameters !== undefined) {
|
|
158
|
+
if (operationObject.parameters !== undefined) {
|
|
159
|
+
defaults.parameters = (0, unionBy_1.default)(operationObject.parameters, parameters, "name");
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
defaults.parameters = parameters;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
154
165
|
const apiPage = {
|
|
155
166
|
type: "api",
|
|
156
167
|
id: baseId,
|
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": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -67,5 +67,6 @@
|
|
|
67
67
|
},
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=14"
|
|
70
|
-
}
|
|
70
|
+
},
|
|
71
|
+
"gitHead": "b599d062a8e4f1cff86b01ac9b82dc564defbf5f"
|
|
71
72
|
}
|
|
@@ -721,7 +721,7 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
721
721
|
|
|
722
722
|
if (mimeTypes && mimeTypes.length > 1) {
|
|
723
723
|
return create("MimeTabs", {
|
|
724
|
-
|
|
724
|
+
schemaType: "request",
|
|
725
725
|
children: mimeTypes.map((mimeType) => {
|
|
726
726
|
const firstBody = body.content![mimeType].schema;
|
|
727
727
|
if (firstBody === undefined) {
|
|
@@ -721,7 +721,7 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
|
|
|
721
721
|
|
|
722
722
|
if (mimeTypes && mimeTypes.length) {
|
|
723
723
|
return create("MimeTabs", {
|
|
724
|
-
|
|
724
|
+
schemaType: "response",
|
|
725
725
|
children: mimeTypes.map((mimeType: any) => {
|
|
726
726
|
const responseExamples = body.content![mimeType].examples;
|
|
727
727
|
const responseExample = body.content![mimeType].example;
|
|
@@ -129,6 +129,11 @@ export function createResponseExamples(
|
|
|
129
129
|
label: `${finalFormattedName}`,
|
|
130
130
|
value: `${finalFormattedName}`,
|
|
131
131
|
children: [
|
|
132
|
+
guard(exampleValue.summary, (summary) => [
|
|
133
|
+
create("p", {
|
|
134
|
+
children: ` ${summary}`,
|
|
135
|
+
}),
|
|
136
|
+
]),
|
|
132
137
|
create("ResponseSamples", {
|
|
133
138
|
responseExample: JSON.stringify(exampleValue.value, null, 2),
|
|
134
139
|
language: language,
|
|
@@ -140,6 +145,11 @@ export function createResponseExamples(
|
|
|
140
145
|
label: `${finalFormattedName}`,
|
|
141
146
|
value: `${finalFormattedName}`,
|
|
142
147
|
children: [
|
|
148
|
+
guard(exampleValue.summary, (summary) => [
|
|
149
|
+
create("p", {
|
|
150
|
+
children: ` ${summary}`,
|
|
151
|
+
}),
|
|
152
|
+
]),
|
|
143
153
|
create("ResponseSamples", {
|
|
144
154
|
responseExample: exampleValue.value,
|
|
145
155
|
language: language,
|
|
@@ -163,6 +173,11 @@ export function createResponseExample(responseExample: any, mimeType: string) {
|
|
|
163
173
|
label: `Example`,
|
|
164
174
|
value: `Example`,
|
|
165
175
|
children: [
|
|
176
|
+
guard(responseExample.summary, (summary) => [
|
|
177
|
+
create("p", {
|
|
178
|
+
children: ` ${summary}`,
|
|
179
|
+
}),
|
|
180
|
+
]),
|
|
166
181
|
create("ResponseSamples", {
|
|
167
182
|
responseExample: JSON.stringify(responseExample, null, 2),
|
|
168
183
|
language: language,
|
|
@@ -174,6 +189,11 @@ export function createResponseExample(responseExample: any, mimeType: string) {
|
|
|
174
189
|
label: `Example`,
|
|
175
190
|
value: `Example`,
|
|
176
191
|
children: [
|
|
192
|
+
guard(responseExample.summary, (summary) => [
|
|
193
|
+
create("p", {
|
|
194
|
+
children: ` ${summary}`,
|
|
195
|
+
}),
|
|
196
|
+
]),
|
|
177
197
|
create("ResponseSamples", {
|
|
178
198
|
responseExample: responseExample,
|
|
179
199
|
language: language,
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -15,6 +15,7 @@ import chalk from "chalk";
|
|
|
15
15
|
import fs from "fs-extra";
|
|
16
16
|
import cloneDeep from "lodash/cloneDeep";
|
|
17
17
|
import kebabCase from "lodash/kebabCase";
|
|
18
|
+
import unionBy from "lodash/unionBy";
|
|
18
19
|
|
|
19
20
|
import { isURL } from "../index";
|
|
20
21
|
import {
|
|
@@ -193,6 +194,20 @@ function createItems(
|
|
|
193
194
|
// TODO: Don't include summary temporarilly
|
|
194
195
|
const { summary, ...defaults } = operationObject;
|
|
195
196
|
|
|
197
|
+
// Merge common parameters with operation parameters
|
|
198
|
+
// Operation params take precendence over common params
|
|
199
|
+
if (parameters !== undefined) {
|
|
200
|
+
if (operationObject.parameters !== undefined) {
|
|
201
|
+
defaults.parameters = unionBy(
|
|
202
|
+
operationObject.parameters,
|
|
203
|
+
parameters,
|
|
204
|
+
"name"
|
|
205
|
+
);
|
|
206
|
+
} else {
|
|
207
|
+
defaults.parameters = parameters;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
196
211
|
const apiPage: PartialPage<ApiPageMetadata> = {
|
|
197
212
|
type: "api",
|
|
198
213
|
id: baseId,
|