docusaurus-plugin-openapi-docs 0.0.0-619 → 0.0.0-685

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 (44) hide show
  1. package/README.md +3 -3
  2. package/lib/markdown/createAuthorization.d.ts +1 -0
  3. package/lib/markdown/createAuthorization.js +16 -0
  4. package/lib/markdown/createDeprecationNotice.js +1 -1
  5. package/lib/markdown/createHeading.d.ts +1 -0
  6. package/lib/markdown/createHeading.js +20 -0
  7. package/lib/markdown/createMethodEndpoint.d.ts +1 -0
  8. package/lib/markdown/createMethodEndpoint.js +14 -0
  9. package/lib/markdown/createParamsDetails.js +3 -1
  10. package/lib/markdown/createRequestHeader.d.ts +1 -0
  11. package/lib/markdown/createRequestHeader.js +13 -0
  12. package/lib/markdown/createRequestSchema.js +21 -17
  13. package/lib/markdown/createResponseSchema.js +8 -8
  14. package/lib/markdown/createSchema.d.ts +1 -1
  15. package/lib/markdown/createSchema.js +125 -86
  16. package/lib/markdown/createSchema.test.d.ts +1 -0
  17. package/lib/markdown/createSchema.test.js +73 -0
  18. package/lib/markdown/createStatusCodes.js +38 -35
  19. package/lib/markdown/index.d.ts +1 -1
  20. package/lib/markdown/index.js +15 -6
  21. package/lib/openapi/openapi.js +29 -13
  22. package/lib/openapi/openapi.test.js +1 -0
  23. package/lib/options.js +1 -2
  24. package/lib/sidebars/index.js +2 -2
  25. package/lib/types.d.ts +3 -1
  26. package/package.json +8 -16
  27. package/src/markdown/__snapshots__/createSchema.test.ts.snap +98 -0
  28. package/src/markdown/createAuthorization.ts +13 -0
  29. package/src/markdown/createDeprecationNotice.ts +1 -1
  30. package/src/markdown/createHeading.ts +18 -0
  31. package/src/markdown/createMethodEndpoint.ts +12 -0
  32. package/src/markdown/createParamsDetails.ts +3 -1
  33. package/src/markdown/createRequestHeader.ts +10 -0
  34. package/src/markdown/createRequestSchema.ts +22 -17
  35. package/src/markdown/createResponseSchema.ts +9 -8
  36. package/src/markdown/createSchema.test.ts +56 -0
  37. package/src/markdown/createSchema.ts +140 -92
  38. package/src/markdown/createStatusCodes.ts +38 -35
  39. package/src/markdown/index.ts +17 -5
  40. package/src/openapi/openapi.test.ts +1 -0
  41. package/src/openapi/openapi.ts +25 -4
  42. package/src/options.ts +1 -2
  43. package/src/sidebars/index.ts +2 -2
  44. package/src/types.ts +3 -1
@@ -13,14 +13,18 @@ import {
13
13
  } from "../openapi/types";
14
14
  import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
15
15
  import { createAuthentication } from "./createAuthentication";
16
+ import { createAuthorization } from "./createAuthorization";
16
17
  import { createContactInfo } from "./createContactInfo";
17
18
  import { createDeprecationNotice } from "./createDeprecationNotice";
18
19
  import { createDescription } from "./createDescription";
19
20
  import { createDownload } from "./createDownload";
21
+ import { createHeading } from "./createHeading";
20
22
  import { createLicense } from "./createLicense";
21
23
  import { createLogo } from "./createLogo";
24
+ import { createMethodEndpoint } from "./createMethodEndpoint";
22
25
  import { createParamsDetails } from "./createParamsDetails";
23
26
  import { createRequestBodyDetails } from "./createRequestBodyDetails";
27
+ import { createRequestHeader } from "./createRequestHeader";
24
28
  import { createStatusCodes } from "./createStatusCodes";
25
29
  import { createTermsOfService } from "./createTermsOfService";
26
30
  import { createVendorExtensions } from "./createVendorExtensions";
@@ -44,32 +48,40 @@ export function createApiPageMD({
44
48
  deprecated,
45
49
  "x-deprecated-description": deprecatedDescription,
46
50
  description,
51
+ method,
52
+ path,
47
53
  extensions,
48
54
  parameters,
49
55
  requestBody,
50
56
  responses,
51
57
  },
58
+ infoPath,
52
59
  frontMatter,
53
60
  }: ApiPageMetadata) {
54
61
  return render([
55
62
  `import ApiTabs from "@theme/ApiTabs";\n`,
63
+ `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
64
+ `import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";\n`,
65
+ `import SecuritySchemes from "@theme/ApiExplorer/SecuritySchemes";\n`,
56
66
  `import MimeTabs from "@theme/MimeTabs";\n`,
57
67
  `import ParamsItem from "@theme/ParamsItem";\n`,
58
68
  `import ResponseSamples from "@theme/ResponseSamples";\n`,
59
69
  `import SchemaItem from "@theme/SchemaItem";\n`,
60
70
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
61
- `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
62
71
  `import TabItem from "@theme/TabItem";\n\n`,
63
- `## ${title.replace(lessThan, "<").replace(greaterThan, ">")}\n\n`,
72
+ createHeading(title.replace(lessThan, "<").replace(greaterThan, ">")),
73
+ createMethodEndpoint(method, path),
74
+ infoPath && createAuthorization(infoPath),
64
75
  frontMatter.show_extensions && createVendorExtensions(extensions),
65
76
  createDeprecationNotice({ deprecated, description: deprecatedDescription }),
66
77
  createDescription(description),
78
+ createRequestHeader("Request"),
67
79
  createParamsDetails({ parameters, type: "path" }),
68
80
  createParamsDetails({ parameters, type: "query" }),
69
81
  createParamsDetails({ parameters, type: "header" }),
70
82
  createParamsDetails({ parameters, type: "cookie" }),
71
83
  createRequestBodyDetails({
72
- title: "Request Body",
84
+ title: "Body",
73
85
  body: requestBody,
74
86
  } as Props),
75
87
  createStatusCodes({ responses }),
@@ -94,11 +106,11 @@ export function createInfoPageMD({
94
106
  `import ApiLogo from "@theme/ApiLogo";\n`,
95
107
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
96
108
  `import TabItem from "@theme/TabItem";\n`,
97
- `import Export from "@theme/ApiDemoPanel/Export";\n\n`,
109
+ `import Export from "@theme/ApiExplorer/Export";\n\n`,
98
110
 
99
111
  createVersionBadge(version),
100
112
  createDownload(downloadUrl),
101
- `# ${title.replace(lessThan, "<").replace(greaterThan, ">")}\n\n`,
113
+ createHeading(title.replace(lessThan, "<").replace(greaterThan, ">")),
102
114
  createLogo(logo, darkLogo),
103
115
  createDescription(description),
104
116
  createAuthentication(securitySchemes as unknown as SecuritySchemeObject),
@@ -7,6 +7,7 @@
7
7
 
8
8
  import path from "path";
9
9
 
10
+ // eslint-disable-next-line import/no-extraneous-dependencies
10
11
  import { posixPath } from "@docusaurus/utils";
11
12
 
12
13
  import { readOpenapiFiles } from ".";
@@ -171,7 +171,18 @@ function createItems(
171
171
  }
172
172
 
173
173
  let jsonRequestBodyExample;
174
- const body = operationObject.requestBody?.content?.["application/json"];
174
+ const content = operationObject.requestBody?.content;
175
+ let body;
176
+ for (let key in content) {
177
+ if (
178
+ key.toLowerCase() === "application/json" ||
179
+ key.toLowerCase() === "application/json; charset=utf-8"
180
+ ) {
181
+ body = content[key];
182
+ break;
183
+ }
184
+ }
185
+
175
186
  if (body?.schema) {
176
187
  jsonRequestBodyExample = sampleRequestFromSchema(body.schema);
177
188
  }
@@ -304,7 +315,18 @@ function createItems(
304
315
  }
305
316
 
306
317
  let jsonRequestBodyExample;
307
- const body = operationObject.requestBody?.content?.["application/json"];
318
+ const content = operationObject.requestBody?.content;
319
+ let body;
320
+ for (let key in content) {
321
+ if (
322
+ key.toLowerCase() === "application/json" ||
323
+ key.toLowerCase() === "application/json; charset=utf-8"
324
+ ) {
325
+ body = content[key];
326
+ break;
327
+ }
328
+ }
329
+
308
330
  if (body?.schema) {
309
331
  jsonRequestBodyExample = sampleRequestFromSchema(body.schema);
310
332
  }
@@ -447,8 +469,7 @@ function bindCollectionToApiItems(
447
469
  const method = item.request.method.toLowerCase();
448
470
  const path = item.request.url
449
471
  .getPath({ unresolved: true }) // unresolved returns "/:variableName" instead of "/<type>"
450
- .replace(/:([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
451
-
472
+ .replace(/(?<![a-z0-9-_]+):([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
452
473
  const apiItem = items.find((item) => {
453
474
  if (item.type === "info" || item.type === "tag") {
454
475
  return false;
package/src/options.ts CHANGED
@@ -9,8 +9,7 @@ import { Joi } from "@docusaurus/utils-validation";
9
9
 
10
10
  const sidebarOptions = Joi.object({
11
11
  groupPathsBy: Joi.string().valid("tag"),
12
- // TODO: Remove "none" in 2.0, make it the default if not specified
13
- categoryLinkSource: Joi.string().valid("tag", "info", "none"),
12
+ categoryLinkSource: Joi.string().valid("tag", "info", "auto"),
14
13
  customProps: Joi.object(),
15
14
  sidebarCollapsible: Joi.boolean(),
16
15
  sidebarCollapsed: Joi.boolean(),
@@ -130,6 +130,7 @@ function groupByTags(
130
130
  );
131
131
 
132
132
  // TODO: perhaps move this into a getLinkConfig() function
133
+ // Default to no link config (spindowns only)
133
134
  let linkConfig = undefined;
134
135
  if (taggedInfoObject !== undefined && categoryLinkSource === "info") {
135
136
  linkConfig = {
@@ -151,8 +152,7 @@ function groupByTags(
151
152
  } as SidebarItemCategoryLinkConfig;
152
153
  }
153
154
 
154
- // Default behavior
155
- if (categoryLinkSource === undefined) {
155
+ if (categoryLinkSource === "auto") {
156
156
  linkConfig = {
157
157
  type: "generated-index" as "generated-index",
158
158
  title: tag,
package/src/types.ts CHANGED
@@ -54,7 +54,7 @@ export interface MarkdownGenerator {
54
54
 
55
55
  export interface SidebarOptions {
56
56
  groupPathsBy?: string;
57
- categoryLinkSource?: string;
57
+ categoryLinkSource?: "info" | "tag" | "auto";
58
58
  customProps?: { [key: string]: unknown };
59
59
  sidebarCollapsible?: boolean;
60
60
  sidebarCollapsed?: boolean;
@@ -92,6 +92,8 @@ export interface ApiMetadataBase {
92
92
  permalink: string;
93
93
  sidebarPosition?: number;
94
94
  frontMatter: Record<string, unknown>;
95
+ method?: string;
96
+ path?: string;
95
97
  }
96
98
 
97
99
  export interface ApiPageMetadata extends ApiMetadataBase {