docusaurus-plugin-openapi-docs 0.0.0-862 → 0.0.0-934

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.
@@ -5,19 +5,9 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  * ========================================================================== */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createStatusCodes = exports.createExampleFromSchema = exports.createResponseExample = exports.createResponseExamples = void 0;
13
- const xml_formatter_1 = __importDefault(require("xml-formatter"));
14
- const createDescription_1 = require("./createDescription");
15
- const createDetails_1 = require("./createDetails");
16
- const createDetailsSummary_1 = require("./createDetailsSummary");
17
- const createResponseSchema_1 = require("./createResponseSchema");
9
+ exports.createStatusCodes = void 0;
18
10
  const utils_1 = require("./utils");
19
- const utils_2 = require("./utils");
20
- const createResponseExample_1 = require("../openapi/createResponseExample");
21
11
  function json2xml(o, tab) {
22
12
  var toXml = function (v, name, ind) {
23
13
  var xml = "";
@@ -61,253 +51,14 @@ function json2xml(o, tab) {
61
51
  return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
62
52
  }
63
53
  exports.default = json2xml;
64
- function createResponseHeaders(responseHeaders) {
65
- return (0, utils_2.guard)(responseHeaders, () => (0, utils_1.create)("ul", {
66
- style: { marginLeft: "1rem" },
67
- children: [
68
- Object.entries(responseHeaders).map(([headerName, headerObj]) => {
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";
72
- return (0, utils_1.create)("li", {
73
- className: "schemaItem",
74
- children: [
75
- (0, createDetailsSummary_1.createDetailsSummary)({
76
- children: [
77
- (0, utils_1.create)("strong", { children: headerName }),
78
- (0, utils_2.guard)(type, () => [
79
- (0, utils_1.create)("span", {
80
- style: { opacity: "0.6" },
81
- children: ` ${type}`,
82
- }),
83
- ]),
84
- ],
85
- }),
86
- (0, utils_1.create)("div", {
87
- children: [
88
- (0, utils_2.guard)(description, (description) => (0, utils_1.create)("div", {
89
- style: {
90
- marginTop: ".5rem",
91
- marginBottom: ".5rem",
92
- },
93
- children: [
94
- (0, utils_2.guard)(example, () => `Example: ${example}`),
95
- (0, createDescription_1.createDescription)(description),
96
- ],
97
- })),
98
- ],
99
- }),
100
- ],
101
- });
102
- }),
103
- ],
104
- }));
105
- }
106
- function createResponseExamples(responseExamples, mimeType) {
107
- let language = "shell";
108
- if (mimeType.endsWith("json")) {
109
- language = "json";
110
- }
111
- if (mimeType.endsWith("xml")) {
112
- language = "xml";
113
- }
114
- return Object.entries(responseExamples).map(([exampleName, exampleValue]) => {
115
- if (typeof exampleValue.value === "object") {
116
- return (0, utils_1.create)("TabItem", {
117
- label: `${exampleName}`,
118
- value: `${exampleName}`,
119
- children: [
120
- (0, utils_2.guard)(exampleValue.summary, (summary) => [
121
- (0, utils_1.create)("div", {
122
- children: `${summary}`,
123
- className: "openapi-example__summary",
124
- }),
125
- ]),
126
- (0, utils_1.create)("ResponseSamples", {
127
- responseExample: JSON.stringify(exampleValue.value, null, 2),
128
- language: language,
129
- }),
130
- ],
131
- });
132
- }
133
- return (0, utils_1.create)("TabItem", {
134
- label: `${exampleName}`,
135
- value: `${exampleName}`,
136
- children: [
137
- (0, utils_2.guard)(exampleValue.summary, (summary) => [
138
- (0, utils_1.create)("div", {
139
- children: `${summary}`,
140
- className: "openapi-example__summary",
141
- }),
142
- ]),
143
- (0, utils_1.create)("ResponseSamples", {
144
- responseExample: exampleValue.value,
145
- language: language,
146
- }),
147
- ],
148
- });
149
- });
150
- }
151
- exports.createResponseExamples = createResponseExamples;
152
- function createResponseExample(responseExample, mimeType) {
153
- let language = "shell";
154
- if (mimeType.endsWith("json")) {
155
- language = "json";
156
- }
157
- if (mimeType.endsWith("xml")) {
158
- language = "xml";
159
- }
160
- if (typeof responseExample === "object") {
161
- return (0, utils_1.create)("TabItem", {
162
- label: `Example`,
163
- value: `Example`,
164
- children: [
165
- (0, utils_2.guard)(responseExample.summary, (summary) => [
166
- (0, utils_1.create)("div", {
167
- children: `${summary}`,
168
- className: "openapi-example__summary",
169
- }),
170
- ]),
171
- (0, utils_1.create)("ResponseSamples", {
172
- responseExample: JSON.stringify(responseExample, null, 2),
173
- language: language,
174
- }),
175
- ],
176
- });
177
- }
178
- return (0, utils_1.create)("TabItem", {
179
- label: `Example`,
180
- value: `Example`,
181
- children: [
182
- (0, utils_2.guard)(responseExample.summary, (summary) => [
183
- (0, utils_1.create)("div", {
184
- children: `${summary}`,
185
- className: "openapi-example__summary",
186
- }),
187
- ]),
188
- (0, utils_1.create)("ResponseSamples", {
189
- responseExample: responseExample,
190
- language: language,
191
- }),
192
- ],
193
- });
194
- }
195
- exports.createResponseExample = createResponseExample;
196
- function createExampleFromSchema(schema, mimeType) {
197
- const responseExample = (0, createResponseExample_1.sampleResponseFromSchema)(schema);
198
- if (mimeType.endsWith("xml")) {
199
- let responseExampleObject;
200
- try {
201
- responseExampleObject = JSON.parse(JSON.stringify(responseExample));
202
- }
203
- catch {
204
- return undefined;
205
- }
206
- if (typeof responseExampleObject === "object") {
207
- let xmlExample;
208
- try {
209
- xmlExample = (0, xml_formatter_1.default)(json2xml(responseExampleObject, ""), {
210
- indentation: " ",
211
- lineSeparator: "\n",
212
- collapseContent: true,
213
- });
214
- }
215
- catch {
216
- const xmlExampleWithRoot = { root: responseExampleObject };
217
- try {
218
- xmlExample = (0, xml_formatter_1.default)(json2xml(xmlExampleWithRoot, ""), {
219
- indentation: " ",
220
- lineSeparator: "\n",
221
- collapseContent: true,
222
- });
223
- }
224
- catch {
225
- xmlExample = json2xml(responseExampleObject, "");
226
- }
227
- }
228
- return (0, utils_1.create)("TabItem", {
229
- label: `Example (from schema)`,
230
- value: `Example (from schema)`,
231
- children: [
232
- (0, utils_1.create)("ResponseSamples", {
233
- responseExample: xmlExample,
234
- language: "xml",
235
- }),
236
- ],
237
- });
238
- }
239
- }
240
- if (typeof responseExample === "object") {
241
- return (0, utils_1.create)("TabItem", {
242
- label: `Example (from schema)`,
243
- value: `Example (from schema)`,
244
- children: [
245
- (0, utils_1.create)("ResponseSamples", {
246
- responseExample: JSON.stringify(responseExample, null, 2),
247
- language: "json",
248
- }),
249
- ],
250
- });
251
- }
252
- return undefined;
253
- }
254
- exports.createExampleFromSchema = createExampleFromSchema;
255
- function createStatusCodes({ label, id, responses }) {
256
- if (responses === undefined) {
257
- return undefined;
258
- }
259
- const codes = Object.keys(responses);
260
- if (codes.length === 0) {
261
- return undefined;
262
- }
263
- return (0, utils_1.create)("div", {
264
- children: [
265
- (0, utils_1.create)("div", {
266
- children: [
267
- (0, utils_1.create)("ApiTabs", {
268
- label,
269
- id,
270
- children: codes.map((code) => {
271
- const responseHeaders = responses[code].headers;
272
- return (0, utils_1.create)("TabItem", {
273
- label: code,
274
- value: code,
275
- children: [
276
- (0, utils_1.create)("div", {
277
- children: (0, createDescription_1.createDescription)(responses[code].description),
278
- }),
279
- responseHeaders &&
280
- (0, createDetails_1.createDetails)({
281
- className: "openapi-markdown__details",
282
- "data-collapsed": true,
283
- open: false,
284
- style: { textAlign: "left", marginBottom: "1rem" },
285
- children: [
286
- (0, createDetailsSummary_1.createDetailsSummary)({
287
- children: [
288
- (0, utils_1.create)("strong", {
289
- children: "Response Headers",
290
- }),
291
- ],
292
- }),
293
- createResponseHeaders(responseHeaders),
294
- ],
295
- }),
296
- (0, utils_1.create)("div", {
297
- children: (0, createResponseSchema_1.createResponseSchema)({
298
- title: "Schema",
299
- body: {
300
- content: responses[code].content,
301
- },
302
- }),
303
- }),
304
- ],
305
- });
306
- }),
307
- }),
308
- ],
309
- }),
310
- ],
311
- });
54
+ function createStatusCodes({ id, label, responses }) {
55
+ return [
56
+ (0, utils_1.create)("StatusCodes", {
57
+ id: id,
58
+ label: label,
59
+ responses: responses,
60
+ }),
61
+ "\n\n",
62
+ ];
312
63
  }
313
64
  exports.createStatusCodes = createStatusCodes;
@@ -29,18 +29,13 @@ const createVersionBadge_1 = require("./createVersionBadge");
29
29
  const utils_1 = require("./utils");
30
30
  function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, callbacks, }, infoPath, frontMatter, }) {
31
31
  return (0, utils_1.render)([
32
- `import ApiTabs from "@theme/ApiTabs";\n`,
33
- `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
34
32
  `import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";\n`,
35
- `import SecuritySchemes from "@theme/ApiExplorer/SecuritySchemes";\n`,
36
- `import MimeTabs from "@theme/MimeTabs";\n`,
37
- `import ParamsItem from "@theme/ParamsItem";\n`,
38
- `import ResponseSamples from "@theme/ResponseSamples";\n`,
39
- `import SchemaItem from "@theme/SchemaItem";\n`,
40
- `import SchemaTabs from "@theme/SchemaTabs";\n`,
41
- `import Heading from "@theme/Heading";\n`,
33
+ `import ParamsDetails from "@theme/ParamsDetails";\n`,
34
+ `import RequestSchema from "@theme/RequestSchema";\n`,
35
+ `import StatusCodes from "@theme/StatusCodes";\n`,
42
36
  `import OperationTabs from "@theme/OperationTabs";\n`,
43
- `import TabItem from "@theme/TabItem";\n\n`,
37
+ `import TabItem from "@theme/TabItem";\n`,
38
+ `import Heading from "@theme/Heading";\n\n`,
44
39
  (0, createHeading_1.createHeading)(title),
45
40
  (0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
46
41
  infoPath && (0, createAuthorization_1.createAuthorization)(infoPath),
@@ -50,10 +45,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
50
45
  (0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
51
46
  (0, createDescription_1.createDescription)(description),
52
47
  requestBody || parameters ? (0, createRequestHeader_1.createRequestHeader)("Request") : undefined,
53
- (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "path" }),
54
- (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "query" }),
55
- (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "header" }),
56
- (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "cookie" }),
48
+ (0, createParamsDetails_1.createParamsDetails)({ parameters }),
57
49
  (0, createRequestBodyDetails_1.createRequestBodyDetails)({
58
50
  title: "Body",
59
51
  body: requestBody,
@@ -51,7 +51,7 @@ function sampleRequestFromProp(name, prop, obj) {
51
51
  obj[name] = (0, exports.sampleRequestFromSchema)(prop.anyOf[0]);
52
52
  }
53
53
  else if (prop.allOf) {
54
- const { mergedSchemas } = (0, createSchema_1.mergeAllOf)(prop.allOf);
54
+ const mergedSchemas = (0, createSchema_1.mergeAllOf)(prop);
55
55
  sampleRequestFromProp(name, mergedSchemas, obj);
56
56
  }
57
57
  else {
@@ -86,7 +86,7 @@ const sampleRequestFromSchema = (schema = {}) => {
86
86
  return (0, exports.sampleRequestFromSchema)(anyOf[0]);
87
87
  }
88
88
  if (allOf) {
89
- const { mergedSchemas } = (0, createSchema_1.mergeAllOf)(allOf);
89
+ const mergedSchemas = (0, createSchema_1.mergeAllOf)(schemaCopy);
90
90
  if (mergedSchemas.properties) {
91
91
  for (const [key, value] of Object.entries(mergedSchemas.properties)) {
92
92
  if ((value.readOnly && value.readOnly === true) || value.deprecated) {
@@ -51,7 +51,7 @@ function sampleResponseFromProp(name, prop, obj) {
51
51
  obj[name] = (0, exports.sampleResponseFromSchema)(prop.anyOf[0]);
52
52
  }
53
53
  else if (prop.allOf) {
54
- const { mergedSchemas } = (0, createSchema_1.mergeAllOf)(prop.allOf);
54
+ const mergedSchemas = (0, createSchema_1.mergeAllOf)(prop);
55
55
  sampleResponseFromProp(name, mergedSchemas, obj);
56
56
  }
57
57
  else {
@@ -68,7 +68,7 @@ const sampleResponseFromSchema = (schema = {}) => {
68
68
  return example;
69
69
  }
70
70
  if (allOf) {
71
- const { mergedSchemas } = (0, createSchema_1.mergeAllOf)(allOf);
71
+ const mergedSchemas = (0, createSchema_1.mergeAllOf)(schemaCopy);
72
72
  if (mergedSchemas.properties) {
73
73
  for (const [key, value] of Object.entries(mergedSchemas.properties)) {
74
74
  if ((value.writeOnly && value.writeOnly === true) ||
@@ -21,8 +21,8 @@ const uniq_1 = __importDefault(require("lodash/uniq"));
21
21
  const openapi_to_postmanv2_1 = __importDefault(require("openapi-to-postmanv2"));
22
22
  const postman_collection_1 = __importDefault(require("postman-collection"));
23
23
  const createRequestExample_1 = require("./createRequestExample");
24
- const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
25
24
  const index_1 = require("../index");
25
+ const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
26
26
  /**
27
27
  * Convenience function for converting raw JSON to a Postman Collection object.
28
28
  */
@@ -196,6 +196,7 @@ export interface MediaTypeObject {
196
196
  example?: any;
197
197
  examples?: Map<ExampleObject>;
198
198
  encoding?: Map<EncodingObject>;
199
+ type?: any;
199
200
  }
200
201
  export interface MediaTypeObjectWithRef {
201
202
  schema?: SchemaObjectWithRef | ReferenceObject;
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-862",
4
+ "version": "0.0.0-934",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -42,11 +42,11 @@
42
42
  "@docusaurus/utils": "^3.5.0",
43
43
  "@docusaurus/utils-validation": "^3.5.0",
44
44
  "@redocly/openapi-core": "^1.10.5",
45
+ "allof-merge": "^0.6.6",
45
46
  "chalk": "^4.1.2",
46
47
  "clsx": "^1.1.1",
47
48
  "fs-extra": "^9.0.1",
48
49
  "json-pointer": "^0.6.2",
49
- "json-schema-merge-allof": "^0.8.1",
50
50
  "json5": "^2.2.3",
51
51
  "lodash": "^4.17.20",
52
52
  "mustache": "^4.2.0",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">=14"
64
64
  },
65
- "gitHead": "55568375fb676dfcd0260043c2b789932e309b89"
65
+ "gitHead": "23c20cde70c5311d6879b113665ceddc84d1febc"
66
66
  }
@@ -364,6 +364,24 @@ Array [
364
364
  qualifierMessage={undefined}
365
365
  schema={{ type: \\"string\\" }}
366
366
  ></SchemaItem>;
367
+ ",
368
+ "<SchemaItem
369
+ collapsible={false}
370
+ name={\\"parentProp1\\"}
371
+ required={false}
372
+ schemaName={\\"string\\"}
373
+ qualifierMessage={undefined}
374
+ schema={{ type: \\"string\\" }}
375
+ ></SchemaItem>;
376
+ ",
377
+ "<SchemaItem
378
+ collapsible={false}
379
+ name={\\"parentProp2\\"}
380
+ required={false}
381
+ schemaName={\\"string\\"}
382
+ qualifierMessage={undefined}
383
+ schema={{ type: \\"string\\" }}
384
+ ></SchemaItem>;
367
385
  ",
368
386
  ]
369
387
  `;
@@ -711,6 +729,15 @@ Array [
711
729
  qualifierMessage={undefined}
712
730
  schema={{ type: \\"string\\" }}
713
731
  ></SchemaItem>;
732
+ ",
733
+ "<SchemaItem
734
+ collapsible={false}
735
+ name={\\"type\\"}
736
+ required={false}
737
+ schemaName={\\"string\\"}
738
+ qualifierMessage={undefined}
739
+ schema={{ type: \\"string\\" }}
740
+ ></SchemaItem>;
714
741
  ",
715
742
  ]
716
743
  `;
@@ -797,6 +824,34 @@ Array [
797
824
  qualifierMessage={undefined}
798
825
  schema={{ type: \\"string\\" }}
799
826
  ></SchemaItem>;
827
+ ",
828
+ "<div className={\\"openapi-discriminator__item openapi-schema__list-item\\"}>
829
+ <div>
830
+ <span className={\\"openapi-schema__container\\"}>
831
+ <strong
832
+ className={\\"openapi-discriminator__name openapi-schema__property\\"}
833
+ >
834
+ type
835
+ </strong>
836
+ <span className={\\"openapi-schema__name\\"}>string</span>
837
+ </span>
838
+ <div style={{ paddingLeft: \\"1rem\\" }}>
839
+ **Possible values:** [\`typeA\`, \`typeB\`]
840
+ </div>
841
+ <DiscriminatorTabs className={\\"openapi-tabs__discriminator\\"}>
842
+ <TabItem label={\\"typeA\\"} value={\\"0-item-discriminator\\"}>
843
+ <div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
844
+ #/definitions/TypeA
845
+ </div>
846
+ </TabItem>
847
+ <TabItem label={\\"typeB\\"} value={\\"1-item-discriminator\\"}>
848
+ <div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
849
+ #/definitions/TypeB
850
+ </div>
851
+ </TabItem>
852
+ </DiscriminatorTabs>
853
+ </div>
854
+ </div>;
800
855
  ",
801
856
  ]
802
857
  `;
@@ -5,60 +5,18 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { createDetails } from "./createDetails";
9
- import { createDetailsSummary } from "./createDetailsSummary";
10
8
  import { create } from "./utils";
11
9
  import { ApiItem } from "../types";
12
10
 
13
11
  interface Props {
14
12
  parameters: ApiItem["parameters"];
15
- type: "path" | "query" | "header" | "cookie";
16
13
  }
17
14
 
18
- export function createParamsDetails({ parameters, type }: Props) {
19
- if (parameters === undefined) {
20
- return undefined;
21
- }
22
- const params = parameters.filter((param) => param?.in === type);
23
- if (params.length === 0) {
24
- return undefined;
25
- }
26
-
27
- return createDetails({
28
- className: "openapi-markdown__details",
29
- "data-collapsed": false,
30
- open: true,
31
- style: { marginBottom: "1rem" },
32
- children: [
33
- createDetailsSummary({
34
- children: [
35
- create("h3", {
36
- className: "openapi-markdown__details-summary-header-params",
37
- children: `${
38
- type.charAt(0).toUpperCase() + type.slice(1)
39
- } Parameters`,
40
- }),
41
- ],
42
- }),
43
- create("div", {
44
- children: [
45
- create("ul", {
46
- children: params.map((param) => {
47
- return create("ParamsItem", {
48
- className: "paramsItem",
49
- param: {
50
- ...param,
51
- enumDescriptions: Object.entries(
52
- param?.schema?.["x-enumDescriptions"] ??
53
- param?.schema?.items?.["x-enumDescriptions"] ??
54
- {}
55
- ),
56
- },
57
- });
58
- }),
59
- }),
60
- ],
61
- }),
62
- ],
63
- });
15
+ export function createParamsDetails({ parameters }: Props) {
16
+ return [
17
+ create("ParamsDetails", {
18
+ parameters: parameters,
19
+ }),
20
+ "\n\n",
21
+ ];
64
22
  }