docusaurus-plugin-openapi-docs 3.0.0-beta.1 → 3.0.0-beta.10

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.
Files changed (74) hide show
  1. package/README.md +2 -0
  2. package/lib/index.js +75 -19
  3. package/lib/markdown/createAuthentication.js +4 -3
  4. package/lib/markdown/createCallbacks.d.ts +6 -0
  5. package/lib/markdown/createCallbacks.js +78 -0
  6. package/lib/markdown/createDeprecationNotice.js +6 -3
  7. package/lib/markdown/createDescription.js +1 -9
  8. package/lib/markdown/createHeading.js +4 -5
  9. package/lib/markdown/createRequestBodyDetails.d.ts +1 -1
  10. package/lib/markdown/createRequestHeader.d.ts +1 -1
  11. package/lib/markdown/createRequestHeader.js +10 -1
  12. package/lib/markdown/createRequestSchema.js +2 -2
  13. package/lib/markdown/createResponseSchema.js +1 -1
  14. package/lib/markdown/createSchema.d.ts +2 -2
  15. package/lib/markdown/createSchema.js +52 -19
  16. package/lib/markdown/createSchema.test.js +2 -2
  17. package/lib/markdown/createStatusCodes.d.ts +3 -1
  18. package/lib/markdown/createStatusCodes.js +8 -6
  19. package/lib/markdown/createVersionBadge.js +1 -1
  20. package/lib/markdown/index.d.ts +3 -2
  21. package/lib/markdown/index.js +31 -6
  22. package/lib/markdown/schema.js +3 -0
  23. package/lib/markdown/utils.d.ts +9 -3
  24. package/lib/markdown/utils.js +29 -4
  25. package/lib/openapi/openapi.d.ts +3 -3
  26. package/lib/openapi/openapi.js +61 -8
  27. package/lib/openapi/openapi.test.js +2 -0
  28. package/lib/openapi/types.d.ts +18 -13
  29. package/lib/openapi/utils/services/OpenAPIParser.d.ts +1 -1
  30. package/lib/openapi/utils/services/OpenAPIParser.js +2 -1
  31. package/lib/openapi/utils/services/RedocNormalizedOptions.js +49 -49
  32. package/lib/openapi/utils/types/index.d.ts +1 -1
  33. package/lib/openapi/utils/types/open-api.d.ts +4 -4
  34. package/lib/openapi/utils/types.d.ts +5 -5
  35. package/lib/openapi/utils/utils/openapi.js +1 -1
  36. package/lib/options.js +2 -1
  37. package/lib/sidebars/index.d.ts +2 -2
  38. package/lib/sidebars/index.js +49 -9
  39. package/lib/types.d.ts +16 -3
  40. package/package.json +11 -9
  41. package/src/index.ts +134 -21
  42. package/src/markdown/__snapshots__/createSchema.test.ts.snap +4 -28
  43. package/src/markdown/createAuthentication.ts +11 -6
  44. package/src/markdown/createCallbacks.ts +101 -0
  45. package/src/markdown/createContactInfo.ts +1 -1
  46. package/src/markdown/createDeprecationNotice.ts +2 -2
  47. package/src/markdown/createDescription.ts +2 -10
  48. package/src/markdown/createHeading.ts +10 -7
  49. package/src/markdown/createLicense.ts +1 -1
  50. package/src/markdown/createLogo.ts +1 -1
  51. package/src/markdown/createParamsDetails.ts +1 -1
  52. package/src/markdown/createRequestBodyDetails.ts +2 -2
  53. package/src/markdown/createRequestHeader.ts +15 -1
  54. package/src/markdown/createRequestSchema.ts +3 -3
  55. package/src/markdown/createResponseSchema.ts +2 -2
  56. package/src/markdown/createSchema.test.ts +6 -4
  57. package/src/markdown/createSchema.ts +67 -29
  58. package/src/markdown/createStatusCodes.ts +11 -7
  59. package/src/markdown/createVersionBadge.ts +8 -4
  60. package/src/markdown/index.ts +45 -14
  61. package/src/markdown/schema.ts +4 -0
  62. package/src/markdown/utils.ts +37 -4
  63. package/src/openapi/__fixtures__/examples/openapi.yaml +29 -0
  64. package/src/openapi/createRequestExample.ts +1 -1
  65. package/src/openapi/createResponseExample.ts +1 -1
  66. package/src/openapi/openapi.test.ts +3 -0
  67. package/src/openapi/openapi.ts +78 -11
  68. package/src/openapi/types.ts +6 -0
  69. package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
  70. package/src/openapi/utils/services/OpenAPIParser.ts +3 -3
  71. package/src/openapi/utils/utils/openapi.ts +8 -8
  72. package/src/options.ts +2 -1
  73. package/src/sidebars/index.ts +70 -15
  74. package/src/types.ts +21 -1
package/README.md CHANGED
@@ -31,6 +31,7 @@ Key Features:
31
31
 
32
32
  | Docusaurus OpenAPI Docs | Docusaurus |
33
33
  | ----------------------- | --------------- |
34
+ | 3.0.0-beta.x (beta) | `3.0.1 - 3.1.1` |
34
35
  | 2.0.x (current) | `2.4.1 - 2.4.3` |
35
36
  | 1.7.3 (legacy) | `2.0.1 - 2.2.0` |
36
37
 
@@ -159,6 +160,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
159
160
  | `baseUrl` | `string` | `null` | _Optional:_ Version base URL used when generating version selector dropdown menu. |
160
161
  | `versions` | `object` | `null` | _Optional:_ Set of options for versioning configuration. See below for a list of supported options. |
161
162
  | `markdownGenerators` | `object` | `null` | _Optional:_ Customize MDX content with a set of options for specifying markdown generator functions. See below for a list of supported options. |
163
+ | `showSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates schema pages and adds them to the sidebar. |
162
164
 
163
165
  `sidebarOptions` can be configured with the following options:
164
166
 
package/lib/index.js CHANGED
@@ -15,6 +15,7 @@ const path_1 = __importDefault(require("path"));
15
15
  const zlib_1 = __importDefault(require("zlib"));
16
16
  const utils_1 = require("@docusaurus/utils");
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
+ const json5_1 = __importDefault(require("json5"));
18
19
  const mustache_1 = require("mustache");
19
20
  const markdown_1 = require("./markdown");
20
21
  const openapi_1 = require("./openapi");
@@ -77,7 +78,7 @@ function pluginOpenAPIDocs(context, options) {
77
78
  let docRouteBasePath = docData ? docData.routeBasePath : undefined;
78
79
  let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
79
80
  async function generateApiDocs(options, pluginId) {
80
- var _a, _b, _c;
81
+ var _a, _b, _c, _d;
81
82
  let { specPath, outputDir, template, markdownGenerators, downloadUrl, sidebarOptions, } = options;
82
83
  // Remove trailing slash before proceeding
83
84
  outputDir = outputDir.replace(/\/$/, "");
@@ -92,7 +93,7 @@ function pluginOpenAPIDocs(context, options) {
92
93
  : path_1.default.resolve(siteDir, specPath);
93
94
  try {
94
95
  const openapiFiles = await (0, openapi_1.readOpenapiFiles)(contentPath);
95
- const [loadedApi, tags] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, options, sidebarOptions);
96
+ const [loadedApi, tags, tagGroups] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, options, sidebarOptions);
96
97
  if (!fs_1.default.existsSync(outputDir)) {
97
98
  try {
98
99
  fs_1.default.mkdirSync(outputDir, { recursive: true });
@@ -104,18 +105,20 @@ function pluginOpenAPIDocs(context, options) {
104
105
  }
105
106
  // TODO: figure out better way to set default
106
107
  if (Object.keys(sidebarOptions !== null && sidebarOptions !== void 0 ? sidebarOptions : {}).length > 0) {
107
- const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath);
108
- const sidebarSliceTemplate = `module.exports = {{{slice}}};`;
108
+ const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath, tagGroups);
109
+ let sidebarSliceTemplate = `import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";\n\n`;
110
+ sidebarSliceTemplate += `const sidebar: SidebarsConfig = {{{slice}}};\n\n`;
111
+ sidebarSliceTemplate += `export default sidebar.apisidebar;\n`;
109
112
  const view = (0, mustache_1.render)(sidebarSliceTemplate, {
110
- slice: JSON.stringify(sidebarSlice),
113
+ slice: json5_1.default.stringify({ apisidebar: sidebarSlice }, { space: 2, quote: '"' }),
111
114
  });
112
- if (!fs_1.default.existsSync(`${outputDir}/sidebar.js`)) {
115
+ if (!fs_1.default.existsSync(`${outputDir}/sidebar.ts`)) {
113
116
  try {
114
- fs_1.default.writeFileSync(`${outputDir}/sidebar.js`, view, "utf8");
115
- console.log(chalk_1.default.green(`Successfully created "${outputDir}/sidebar.js"`));
117
+ fs_1.default.writeFileSync(`${outputDir}/sidebar.ts`, view, "utf8");
118
+ console.log(chalk_1.default.green(`Successfully created "${outputDir}/sidebar.ts"`));
116
119
  }
117
120
  catch (err) {
118
- console.error(chalk_1.default.red(`Failed to write "${outputDir}/sidebar.js"`), chalk_1.default.yellow(err));
121
+ console.error(chalk_1.default.red(`Failed to write "${outputDir}/sidebar.ts"`), chalk_1.default.yellow(err));
119
122
  }
120
123
  }
121
124
  }
@@ -195,20 +198,35 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
195
198
  <DocCardList items={useCurrentSidebarCategory().items}/>
196
199
  \`\`\`
197
200
  `;
201
+ const schemaMdTemplate = `---
202
+ id: {{{id}}}
203
+ title: "{{{title}}}"
204
+ description: "{{{frontMatter.description}}}"
205
+ sidebar_label: "{{{title}}}"
206
+ hide_title: true
207
+ schema: true
208
+ custom_edit_url: null
209
+ ---
210
+
211
+ {{{markdown}}}
212
+ `;
198
213
  const apiPageGenerator = (_a = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createApiPageMD) !== null && _a !== void 0 ? _a : markdown_1.createApiPageMD;
199
214
  const infoPageGenerator = (_b = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createInfoPageMD) !== null && _b !== void 0 ? _b : markdown_1.createInfoPageMD;
200
215
  const tagPageGenerator = (_c = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createTagPageMD) !== null && _c !== void 0 ? _c : markdown_1.createTagPageMD;
216
+ const schemaPageGenerator = (_d = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createSchemaPageMD) !== null && _d !== void 0 ? _d : markdown_1.createSchemaPageMD;
217
+ const pageGeneratorByType = {
218
+ api: apiPageGenerator,
219
+ info: infoPageGenerator,
220
+ tag: tagPageGenerator,
221
+ schema: schemaPageGenerator,
222
+ };
201
223
  loadedApi.map(async (item) => {
202
224
  if (item.type === "info") {
203
225
  if (downloadUrl && isURL(downloadUrl)) {
204
226
  item.downloadUrl = downloadUrl;
205
227
  }
206
228
  }
207
- const markdown = item.type === "api"
208
- ? apiPageGenerator(item)
209
- : item.type === "info"
210
- ? infoPageGenerator(item)
211
- : tagPageGenerator(item);
229
+ const markdown = pageGeneratorByType[item.type](item);
212
230
  item.markdown = markdown;
213
231
  if (item.type === "api") {
214
232
  // opportunity to compress JSON
@@ -274,6 +292,32 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
274
292
  }
275
293
  }
276
294
  }
295
+ if (item.type === "schema") {
296
+ if (!fs_1.default.existsSync(`${outputDir}/schemas/${item.id}.schema.mdx`)) {
297
+ if (!fs_1.default.existsSync(`${outputDir}/schemas`)) {
298
+ try {
299
+ fs_1.default.mkdirSync(`${outputDir}/schemas`, { recursive: true });
300
+ console.log(chalk_1.default.green(`Successfully created "${outputDir}/schemas"`));
301
+ }
302
+ catch (err) {
303
+ console.error(chalk_1.default.red(`Failed to create "${outputDir}/schemas"`), chalk_1.default.yellow(err));
304
+ }
305
+ }
306
+ try {
307
+ // kebabCase(arg) returns 0-length string when arg is undefined
308
+ if (item.id.length === 0) {
309
+ throw Error("Schema must have title defined");
310
+ }
311
+ // eslint-disable-next-line testing-library/render-result-naming-convention
312
+ const schemaView = (0, mustache_1.render)(schemaMdTemplate, item);
313
+ fs_1.default.writeFileSync(`${outputDir}/schemas/${item.id}.schema.mdx`, schemaView, "utf8");
314
+ console.log(chalk_1.default.green(`Successfully created "${outputDir}/${item.id}.schema.mdx"`));
315
+ }
316
+ catch (err) {
317
+ console.error(chalk_1.default.red(`Failed to write "${outputDir}/${item.id}.schema.mdx"`), chalk_1.default.yellow(err));
318
+ }
319
+ }
320
+ }
277
321
  return;
278
322
  });
279
323
  return;
@@ -290,6 +334,10 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
290
334
  cwd: path_1.default.resolve(apiDir),
291
335
  deep: 1,
292
336
  });
337
+ const schemaMdxFiles = await (0, utils_1.Globby)(["*.schema.mdx"], {
338
+ cwd: path_1.default.resolve(apiDir, "schemas"),
339
+ deep: 1,
340
+ });
293
341
  const sidebarFile = await (0, utils_1.Globby)(["sidebar.js"], {
294
342
  cwd: path_1.default.resolve(apiDir),
295
343
  deep: 1,
@@ -302,6 +350,14 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
302
350
  console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/${mdx}"`));
303
351
  }
304
352
  }));
353
+ schemaMdxFiles.map((mdx) => fs_1.default.unlink(`${apiDir}/schemas/${mdx}`, (err) => {
354
+ if (err) {
355
+ console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/schemas/${mdx}"`), chalk_1.default.yellow(err));
356
+ }
357
+ else {
358
+ console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/schemas/${mdx}"`));
359
+ }
360
+ }));
305
361
  sidebarFile.map((sidebar) => fs_1.default.unlink(`${apiDir}/${sidebar}`, (err) => {
306
362
  if (err) {
307
363
  console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/${sidebar}"`), chalk_1.default.yellow(err));
@@ -322,7 +378,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
322
378
  }
323
379
  const versionsJson = JSON.stringify(versionsArray, null, 2);
324
380
  try {
325
- fs_1.default.writeFileSync(`${outputDir}/versions.json`, versionsJson, "utf8");
381
+ fs_1.default.writeFileSync(`${outputDir}/versions.json`, versionsJson + "\n", "utf8");
326
382
  console.log(chalk_1.default.green(`Successfully created "${outputDir}/versions.json"`));
327
383
  }
328
384
  catch (err) {
@@ -346,7 +402,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
346
402
  extendCli(cli) {
347
403
  cli
348
404
  .command(`gen-api-docs`)
349
- .description(`Generates OpenAPI docs in MDX file format and sidebar.js (if enabled).`)
405
+ .description(`Generates OpenAPI docs in MDX file format and sidebar.ts (if enabled).`)
350
406
  .usage("<id>")
351
407
  .arguments("<id>")
352
408
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
@@ -394,7 +450,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
394
450
  });
395
451
  cli
396
452
  .command(`gen-api-docs:version`)
397
- .description(`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.js (if enabled).`)
453
+ .description(`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.ts (if enabled).`)
398
454
  .usage("<id:version>")
399
455
  .arguments("<id:version>")
400
456
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
@@ -469,7 +525,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
469
525
  });
470
526
  cli
471
527
  .command(`clean-api-docs`)
472
- .description(`Clears the generated OpenAPI docs MDX files and sidebar.js (if enabled).`)
528
+ .description(`Clears the generated OpenAPI docs MDX files and sidebar.ts (if enabled).`)
473
529
  .usage("<id>")
474
530
  .arguments("<id>")
475
531
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
@@ -512,7 +568,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
512
568
  });
513
569
  cli
514
570
  .command(`clean-api-docs:version`)
515
- .description(`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.js (if enabled).`)
571
+ .description(`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.ts (if enabled).`)
516
572
  .usage("<id:version>")
517
573
  .arguments("<id:version>")
518
574
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
@@ -148,11 +148,12 @@ function createAuthentication(securitySchemes) {
148
148
  };
149
149
  return (0, utils_1.create)("div", {
150
150
  children: [
151
- (0, utils_1.create)("h2", {
151
+ (0, utils_1.create)("Heading", {
152
152
  children: "Authentication",
153
153
  id: "authentication",
154
- style: { marginBottom: "1rem" },
155
- }),
154
+ as: "h2",
155
+ className: "openapi-tabs__heading",
156
+ }, { inline: true }),
156
157
  (0, utils_1.create)("SchemaTabs", {
157
158
  className: "openapi-tabs__security-schemes",
158
159
  children: Object.entries(securitySchemes).map(([schemeKey, schemeObj]) => (0, utils_1.create)("TabItem", {
@@ -0,0 +1,6 @@
1
+ import { ApiItem } from "../types";
2
+ interface Props {
3
+ callbacks: ApiItem["callbacks"];
4
+ }
5
+ export declare function createCallbacks({ callbacks }: Props): string | undefined;
6
+ export {};
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createCallbacks = void 0;
10
+ const createDescription_1 = require("./createDescription");
11
+ const createMethodEndpoint_1 = require("./createMethodEndpoint");
12
+ const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
13
+ const createStatusCodes_1 = require("./createStatusCodes");
14
+ const utils_1 = require("./utils");
15
+ function createCallbacks({ callbacks }) {
16
+ if (callbacks === undefined) {
17
+ return undefined;
18
+ }
19
+ const callbacksNames = Object.keys(callbacks);
20
+ if (callbacksNames.length === 0) {
21
+ return undefined;
22
+ }
23
+ return (0, utils_1.create)("div", {
24
+ children: [
25
+ (0, utils_1.create)("div", {
26
+ className: "openapi__divider",
27
+ }),
28
+ (0, utils_1.create)("Heading", {
29
+ children: "Callbacks",
30
+ id: "callbacks",
31
+ as: "h2",
32
+ className: "openapi-tabs__heading",
33
+ }, { inline: true }),
34
+ (0, utils_1.create)("OperationTabs", {
35
+ className: "openapi-tabs__operation",
36
+ children: callbacksNames.flatMap((name) => {
37
+ const path = Object.keys(callbacks[name])[0];
38
+ const methods = new Map([
39
+ ["delete", callbacks[name][path].delete],
40
+ ["get", callbacks[name][path].get],
41
+ ["head", callbacks[name][path].head],
42
+ ["options", callbacks[name][path].options],
43
+ ["patch", callbacks[name][path].patch],
44
+ ["post", callbacks[name][path].post],
45
+ ["put", callbacks[name][path].put],
46
+ ["trace", callbacks[name][path].trace],
47
+ ]);
48
+ return Array.from(methods).flatMap(([method, operationObject]) => {
49
+ if (!operationObject)
50
+ return [];
51
+ const { description, requestBody, responses } = operationObject;
52
+ return [
53
+ (0, utils_1.create)("TabItem", {
54
+ label: `${method.toUpperCase()} ${name}`,
55
+ value: `${method}-${name}`,
56
+ children: [
57
+ (0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
58
+ // TODO: add `deprecation notice` when markdown support is added
59
+ (0, createDescription_1.createDescription)(description),
60
+ (0, createRequestBodyDetails_1.createRequestBodyDetails)({
61
+ title: "Body",
62
+ body: requestBody,
63
+ }),
64
+ (0, createStatusCodes_1.createStatusCodes)({
65
+ id: "callbacks-responses",
66
+ label: "Callbacks Responses",
67
+ responses,
68
+ }),
69
+ ],
70
+ }),
71
+ ];
72
+ });
73
+ }),
74
+ }),
75
+ ],
76
+ });
77
+ }
78
+ exports.createCallbacks = createCallbacks;
@@ -12,8 +12,11 @@ function createAdmonition({ children }) {
12
12
  return `:::caution deprecated\n\n${(0, utils_1.render)(children)}\n\n:::`;
13
13
  }
14
14
  function createDeprecationNotice({ deprecated, description, }) {
15
- return (0, utils_1.guard)(deprecated, () => createAdmonition({
16
- children: description !== null && description !== void 0 ? description : "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
17
- }));
15
+ return (0, utils_1.guard)(deprecated, () => {
16
+ var _a;
17
+ return createAdmonition({
18
+ children: (_a = (0, utils_1.clean)(description)) !== null && _a !== void 0 ? _a : "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
19
+ });
20
+ });
18
21
  }
19
22
  exports.createDeprecationNotice = createDeprecationNotice;
@@ -9,14 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createDescription = void 0;
10
10
  const utils_1 = require("./utils");
11
11
  function createDescription(description) {
12
- if (!description) {
13
- return "";
14
- }
15
- return `\n\n${description
16
- .replace(utils_1.lessThan, "&lt;")
17
- .replace(utils_1.greaterThan, "&gt;")
18
- .replace(utils_1.codeFence, function (match) {
19
- return match.replace(/\\>/g, ">");
20
- })}\n\n`;
12
+ return `\n\n${(0, utils_1.clean)(description)}\n\n`;
21
13
  }
22
14
  exports.createDescription = createDescription;
@@ -10,12 +10,11 @@ exports.createHeading = void 0;
10
10
  const utils_1 = require("./utils");
11
11
  function createHeading(heading) {
12
12
  return [
13
- (0, utils_1.create)("h1", {
13
+ (0, utils_1.create)("Heading", {
14
+ children: (0, utils_1.clean)(heading),
15
+ as: "h1",
14
16
  className: "openapi__heading",
15
- children: `${heading
16
- .replace(utils_1.lessThan, "&lt;")
17
- .replace(utils_1.greaterThan, "&gt;")}`,
18
- }),
17
+ }, { inline: true }),
19
18
  `\n\n`,
20
19
  ];
21
20
  }
@@ -9,5 +9,5 @@ interface Props {
9
9
  required?: boolean;
10
10
  };
11
11
  }
12
- export declare function createRequestBodyDetails({ title, body }: Props): any;
12
+ export declare function createRequestBodyDetails({ title, body }: Props): string | undefined;
13
13
  export {};
@@ -1 +1 @@
1
- export declare function createRequestHeader(header: string): string;
1
+ export declare function createRequestHeader(header: string): string[];
@@ -7,7 +7,16 @@
7
7
  * ========================================================================== */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createRequestHeader = void 0;
10
+ const utils_1 = require("./utils");
10
11
  function createRequestHeader(header) {
11
- return `## ${header}\n\n`;
12
+ return [
13
+ (0, utils_1.create)("Heading", {
14
+ children: header,
15
+ id: header.replace(" ", "-").toLowerCase(),
16
+ as: "h2",
17
+ className: "openapi-tabs__heading",
18
+ }, { inline: true }),
19
+ `\n\n`,
20
+ ];
12
21
  }
13
22
  exports.createRequestHeader = createRequestHeader;
@@ -74,7 +74,7 @@ function createRequestSchema({ title, body, ...rest }) {
74
74
  }),
75
75
  (0, utils_1.create)("ul", {
76
76
  style: { marginLeft: "1rem" },
77
- children: (0, createSchema_1.createNodes)(firstBody),
77
+ children: (0, createSchema_1.createNodes)(firstBody, "request"),
78
78
  }),
79
79
  ],
80
80
  }),
@@ -139,7 +139,7 @@ function createRequestSchema({ title, body, ...rest }) {
139
139
  }),
140
140
  (0, utils_1.create)("ul", {
141
141
  style: { marginLeft: "1rem" },
142
- children: (0, createSchema_1.createNodes)(firstBody),
142
+ children: (0, createSchema_1.createNodes)(firstBody, "request"),
143
143
  }),
144
144
  ],
145
145
  }),
@@ -89,7 +89,7 @@ function createResponseSchema({ title, body, ...rest }) {
89
89
  }),
90
90
  (0, utils_1.create)("ul", {
91
91
  style: { marginLeft: "1rem" },
92
- children: (0, createSchema_1.createNodes)(firstBody),
92
+ children: (0, createSchema_1.createNodes)(firstBody, "response"),
93
93
  }),
94
94
  ],
95
95
  }),
@@ -4,9 +4,9 @@ import { SchemaObject } from "../openapi/types";
4
4
  */
5
5
  export declare function mergeAllOf(allOf: SchemaObject[]): {
6
6
  mergedSchemas: any;
7
- required: any;
7
+ mergedRequired: any;
8
8
  };
9
9
  /**
10
10
  * Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
11
11
  */
12
- export declare function createNodes(schema: SchemaObject): any;
12
+ export declare function createNodes(schema: SchemaObject, schemaType: "request" | "response"): any;
@@ -18,6 +18,7 @@ const createDetailsSummary_1 = require("./createDetailsSummary");
18
18
  const schema_1 = require("./schema");
19
19
  const utils_1 = require("./utils");
20
20
  const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
21
+ let SCHEMA_TYPE;
21
22
  /**
22
23
  * Returns a merged representation of allOf array of schemas.
23
24
  */
@@ -27,6 +28,9 @@ function mergeAllOf(allOf) {
27
28
  readOnly: function () {
28
29
  return true;
29
30
  },
31
+ writeOnly: function () {
32
+ return true;
33
+ },
30
34
  example: function () {
31
35
  return true;
32
36
  },
@@ -36,14 +40,14 @@ function mergeAllOf(allOf) {
36
40
  },
37
41
  ignoreAdditionalProperties: true,
38
42
  });
39
- const required = allOf.reduce((acc, cur) => {
43
+ const mergedRequired = allOf.reduce((acc, cur) => {
40
44
  if (Array.isArray(cur.required)) {
41
45
  const next = [...acc, ...cur.required];
42
46
  return next;
43
47
  }
44
48
  return acc;
45
49
  }, []);
46
- return { mergedSchemas, required };
50
+ return { mergedSchemas, mergedRequired };
47
51
  }
48
52
  exports.mergeAllOf = mergeAllOf;
49
53
  /**
@@ -68,7 +72,7 @@ function createAnyOneOf(schema) {
68
72
  delete anyOneSchema.properties;
69
73
  }
70
74
  if (anyOneSchema.allOf !== undefined) {
71
- anyOneChildren.push(createNodes(anyOneSchema));
75
+ anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
72
76
  delete anyOneSchema.allOf;
73
77
  }
74
78
  if (anyOneSchema.items !== undefined) {
@@ -79,7 +83,7 @@ function createAnyOneOf(schema) {
79
83
  anyOneSchema.type === "number" ||
80
84
  anyOneSchema.type === "integer" ||
81
85
  anyOneSchema.type === "boolean") {
82
- anyOneChildren.push(createNodes(anyOneSchema));
86
+ anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
83
87
  }
84
88
  if (anyOneChildren.length) {
85
89
  if (schema.type === "array") {
@@ -257,7 +261,7 @@ function createItems(schema) {
257
261
  ((_l = schema.items) === null || _l === void 0 ? void 0 : _l.type) === "object") {
258
262
  return [
259
263
  (0, createArrayBracket_1.createOpeningArrayBracket)(),
260
- createNodes(schema.items),
264
+ createNodes(schema.items, SCHEMA_TYPE),
261
265
  (0, createArrayBracket_1.createClosingArrayBracket)(),
262
266
  ].flat();
263
267
  }
@@ -344,7 +348,7 @@ function createDetailsNode(name, schemaName, schema, required, nullable) {
344
348
  style: { marginTop: ".5rem", marginBottom: ".5rem" },
345
349
  children: (0, createDescription_1.createDescription)(description),
346
350
  })),
347
- createNodes(schema),
351
+ createNodes(schema, SCHEMA_TYPE),
348
352
  ],
349
353
  }),
350
354
  ],
@@ -466,7 +470,7 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
466
470
  // className: "openapi-tabs__discriminator-item",
467
471
  label: label,
468
472
  value: `${index}-item-discriminator`,
469
- children: [createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key])],
473
+ children: [createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key], SCHEMA_TYPE)],
470
474
  });
471
475
  }),
472
476
  }),
@@ -487,7 +491,7 @@ function createEdges({ name, schema, required, discriminator, }) {
487
491
  return createAnyOneOfProperty(name, schemaName, schema, required, schema.nullable);
488
492
  }
489
493
  if (schema.allOf !== undefined) {
490
- const { mergedSchemas, required, } = mergeAllOf(schema.allOf);
494
+ const { mergedSchemas } = mergeAllOf(schema.allOf);
491
495
  const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
492
496
  if (mergedSchemas.oneOf !== undefined ||
493
497
  mergedSchemas.anyOf !== undefined) {
@@ -503,15 +507,22 @@ function createEdges({ name, schema, required, discriminator, }) {
503
507
  if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
504
508
  return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
505
509
  }
506
- if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
507
- return undefined;
510
+ if (SCHEMA_TYPE === "request") {
511
+ if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
512
+ return undefined;
513
+ }
514
+ }
515
+ if (SCHEMA_TYPE === "response") {
516
+ if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
517
+ return undefined;
518
+ }
508
519
  }
509
520
  return (0, utils_1.create)("SchemaItem", {
510
521
  collapsible: false,
511
522
  name,
512
523
  required: Array.isArray(required) ? required.includes(name) : required,
513
- schemaName: schemaName,
514
- qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
524
+ schemaName: mergedSchemaName,
525
+ qualifierMessage: (0, schema_1.getQualifierMessage)(mergedSchemas),
515
526
  schema: mergedSchemas,
516
527
  });
517
528
  }
@@ -528,8 +539,15 @@ function createEdges({ name, schema, required, discriminator, }) {
528
539
  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) {
529
540
  return createDetailsNode(name, schemaName, schema, required, schema.nullable);
530
541
  }
531
- if (schema.readOnly && schema.readOnly === true) {
532
- return undefined;
542
+ if (SCHEMA_TYPE === "request") {
543
+ if (schema.readOnly && schema.readOnly === true) {
544
+ return undefined;
545
+ }
546
+ }
547
+ if (SCHEMA_TYPE === "response") {
548
+ if (schema.writeOnly && schema.writeOnly === true) {
549
+ return undefined;
550
+ }
533
551
  }
534
552
  // primitives and array of non-objects
535
553
  return (0, utils_1.create)("SchemaItem", {
@@ -544,7 +562,8 @@ function createEdges({ name, schema, required, discriminator, }) {
544
562
  /**
545
563
  * Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
546
564
  */
547
- function createNodes(schema) {
565
+ function createNodes(schema, schemaType) {
566
+ SCHEMA_TYPE = schemaType;
548
567
  const nodes = [];
549
568
  // if (schema.discriminator !== undefined) {
550
569
  // return createDiscriminator(schema);
@@ -591,9 +610,16 @@ function createNodes(schema) {
591
610
  style: {
592
611
  marginTop: ".5rem",
593
612
  marginBottom: ".5rem",
594
- marginLeft: "1rem",
595
613
  },
596
- children: (0, createDescription_1.createDescription)(schema.type),
614
+ children: [
615
+ (0, createDescription_1.createDescription)(schema.type),
616
+ (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
617
+ style: {
618
+ paddingTop: "1rem",
619
+ },
620
+ children: (0, createDescription_1.createDescription)(message),
621
+ })),
622
+ ],
597
623
  });
598
624
  }
599
625
  // handle circular references
@@ -602,9 +628,16 @@ function createNodes(schema) {
602
628
  style: {
603
629
  marginTop: ".5rem",
604
630
  marginBottom: ".5rem",
605
- marginLeft: "1rem",
606
631
  },
607
- children: [(0, createDescription_1.createDescription)(schema)],
632
+ children: [
633
+ (0, createDescription_1.createDescription)(schema),
634
+ (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
635
+ style: {
636
+ paddingTop: "1rem",
637
+ },
638
+ children: (0, createDescription_1.createDescription)(message),
639
+ })),
640
+ ],
608
641
  });
609
642
  }
610
643
  // Unknown node/schema type should return undefined
@@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  const prettier = __importStar(require("prettier"));
33
33
  const createSchema_1 = require("./createSchema");
34
34
  describe("createNodes", () => {
35
- it("should create readable MODs for oneOf primitive properties", () => {
35
+ it("should create readable MODs for oneOf primitive properties", async () => {
36
36
  const schema = {
37
37
  type: "object",
38
38
  properties: {
@@ -68,6 +68,6 @@ describe("createNodes", () => {
68
68
  },
69
69
  },
70
70
  };
71
- expect((0, createSchema_1.createNodes)(schema).map((md) => prettier.format(md, { parser: "babel" }))).toMatchSnapshot();
71
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
72
72
  });
73
73
  });
@@ -1,10 +1,12 @@
1
1
  import { ApiItem } from "../types";
2
2
  export default function json2xml(o: any, tab: any): string;
3
3
  interface Props {
4
+ id?: string;
5
+ label?: string;
4
6
  responses: ApiItem["responses"];
5
7
  }
6
8
  export declare function createResponseExamples(responseExamples: any, mimeType: string): string[];
7
9
  export declare function createResponseExample(responseExample: any, mimeType: string): string;
8
10
  export declare function createExampleFromSchema(schema: any, mimeType: string): string | undefined;
9
- export declare function createStatusCodes({ responses }: Props): string | undefined;
11
+ export declare function createStatusCodes({ label, id, responses }: Props): string | undefined;
10
12
  export {};