docusaurus-theme-openapi-docs 4.5.1 → 4.7.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.
Files changed (133) hide show
  1. package/lib/markdown/schema.js +14 -1
  2. package/lib/theme/ApiExplorer/Accept/slice.d.ts +5 -2
  3. package/lib/theme/ApiExplorer/Authorization/index.js +50 -9
  4. package/lib/theme/ApiExplorer/Authorization/slice.d.ts +145 -3
  5. package/lib/theme/ApiExplorer/Authorization/slice.js +3 -1
  6. package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.d.ts +7 -0
  7. package/lib/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.js +126 -0
  8. package/lib/theme/ApiExplorer/Body/FormBodyItem/index.d.ts +9 -0
  9. package/lib/theme/ApiExplorer/Body/FormBodyItem/index.js +110 -0
  10. package/lib/theme/ApiExplorer/Body/index.js +322 -193
  11. package/lib/theme/ApiExplorer/Body/resolveSchemaWithSelections.d.ts +13 -0
  12. package/lib/theme/ApiExplorer/Body/resolveSchemaWithSelections.js +133 -0
  13. package/lib/theme/ApiExplorer/Body/slice.d.ts +1056 -11
  14. package/lib/theme/ApiExplorer/Body/slice.js +22 -2
  15. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +2 -1
  16. package/lib/theme/ApiExplorer/CodeSnippets/index.js +37 -26
  17. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +5 -1
  18. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +3 -3
  19. package/lib/theme/ApiExplorer/CodeTabs/index.js +2 -2
  20. package/lib/theme/ApiExplorer/ContentType/slice.d.ts +5 -2
  21. package/lib/theme/ApiExplorer/FormFileUpload/index.js +6 -1
  22. package/lib/theme/ApiExplorer/FormItem/index.js +6 -1
  23. package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +2 -0
  24. package/lib/theme/ApiExplorer/FormTextInput/index.js +8 -1
  25. package/lib/theme/ApiExplorer/LiveEditor/index.js +11 -4
  26. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.js +15 -5
  27. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +11 -3
  28. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +12 -4
  29. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.js +11 -2
  30. package/lib/theme/ApiExplorer/ParamOptions/index.js +11 -1
  31. package/lib/theme/ApiExplorer/ParamOptions/slice.d.ts +0 -4
  32. package/lib/theme/ApiExplorer/ParamOptions/slice.js +4 -4
  33. package/lib/theme/ApiExplorer/Request/index.js +110 -17
  34. package/lib/theme/ApiExplorer/Request/makeRequest.d.ts +7 -1
  35. package/lib/theme/ApiExplorer/Request/makeRequest.js +94 -24
  36. package/lib/theme/ApiExplorer/Response/index.js +34 -14
  37. package/lib/theme/ApiExplorer/Response/slice.d.ts +31 -7
  38. package/lib/theme/ApiExplorer/SchemaSelection/index.d.ts +2 -0
  39. package/lib/theme/ApiExplorer/SchemaSelection/index.js +36 -0
  40. package/lib/theme/ApiExplorer/SchemaSelection/slice.d.ts +37 -0
  41. package/lib/theme/ApiExplorer/SchemaSelection/slice.js +39 -0
  42. package/lib/theme/ApiExplorer/SecuritySchemes/index.js +208 -69
  43. package/lib/theme/ApiExplorer/Server/index.js +16 -2
  44. package/lib/theme/ApiExplorer/Server/slice.d.ts +49 -3
  45. package/lib/theme/ApiExplorer/buildPostmanRequest.js +46 -57
  46. package/lib/theme/ApiExplorer/index.js +4 -0
  47. package/lib/theme/ApiExplorer/persistenceMiddleware.d.ts +21 -0
  48. package/lib/theme/ApiExplorer/{persistanceMiddleware.js → persistenceMiddleware.js} +16 -9
  49. package/lib/theme/ApiExplorer/storage-utils.d.ts +2 -2
  50. package/lib/theme/ApiExplorer/storage-utils.js +3 -3
  51. package/lib/theme/ApiItem/Layout/index.d.ts +1 -1
  52. package/lib/theme/ApiItem/hooks.d.ts +10 -9
  53. package/lib/theme/ApiItem/index.js +13 -8
  54. package/lib/theme/ApiItem/store.d.ts +61 -43
  55. package/lib/theme/ApiItem/store.js +6 -2
  56. package/lib/theme/ApiTabs/index.js +6 -1
  57. package/lib/theme/Example/_Example.scss +11 -0
  58. package/lib/theme/Example/index.d.ts +24 -0
  59. package/lib/theme/Example/index.js +170 -0
  60. package/lib/theme/ParamsDetails/index.js +9 -1
  61. package/lib/theme/ParamsItem/index.d.ts +1 -1
  62. package/lib/theme/ParamsItem/index.js +43 -74
  63. package/lib/theme/RequestSchema/index.js +68 -48
  64. package/lib/theme/ResponseExamples/index.js +23 -3
  65. package/lib/theme/ResponseSchema/index.js +97 -82
  66. package/lib/theme/Schema/index.d.ts +6 -0
  67. package/lib/theme/Schema/index.js +240 -31
  68. package/lib/theme/SchemaItem/index.js +64 -36
  69. package/lib/theme/SchemaTabs/index.d.ts +8 -1
  70. package/lib/theme/SchemaTabs/index.js +14 -2
  71. package/lib/theme/StatusCodes/index.d.ts +1 -1
  72. package/lib/theme/StatusCodes/index.js +11 -2
  73. package/lib/theme/styles.scss +15 -0
  74. package/lib/theme/translationIds.d.ts +90 -0
  75. package/lib/theme/translationIds.js +114 -0
  76. package/package.json +28 -28
  77. package/src/markdown/schema.ts +17 -1
  78. package/src/theme/ApiExplorer/Authorization/index.tsx +51 -10
  79. package/src/theme/ApiExplorer/Authorization/slice.ts +1 -1
  80. package/src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx +77 -0
  81. package/src/theme/ApiExplorer/Body/FormBodyItem/index.tsx +120 -0
  82. package/src/theme/ApiExplorer/Body/index.tsx +262 -198
  83. package/{lib/types.js → src/theme/ApiExplorer/Body/json2xml.d.ts} +2 -2
  84. package/src/theme/ApiExplorer/Body/resolveSchemaWithSelections.ts +155 -0
  85. package/src/theme/ApiExplorer/Body/slice.ts +40 -1
  86. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +43 -29
  87. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +5 -1
  88. package/src/theme/ApiExplorer/CodeTabs/index.tsx +6 -5
  89. package/src/theme/ApiExplorer/ContentType/index.tsx +1 -1
  90. package/src/theme/ApiExplorer/FormFileUpload/index.tsx +6 -1
  91. package/src/theme/ApiExplorer/FormItem/index.tsx +8 -1
  92. package/src/theme/ApiExplorer/FormTextInput/index.tsx +10 -1
  93. package/src/theme/ApiExplorer/LiveEditor/index.tsx +11 -4
  94. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +16 -6
  95. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +12 -4
  96. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +12 -4
  97. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +12 -3
  98. package/src/theme/ApiExplorer/ParamOptions/index.tsx +10 -2
  99. package/src/theme/ApiExplorer/ParamOptions/slice.ts +1 -1
  100. package/src/theme/ApiExplorer/Request/index.tsx +108 -17
  101. package/src/theme/ApiExplorer/Request/makeRequest.ts +106 -25
  102. package/src/theme/ApiExplorer/Response/index.tsx +30 -8
  103. package/src/theme/ApiExplorer/SchemaSelection/index.ts +13 -0
  104. package/src/theme/ApiExplorer/SchemaSelection/slice.ts +46 -0
  105. package/src/theme/ApiExplorer/SecuritySchemes/index.tsx +157 -69
  106. package/src/theme/ApiExplorer/Server/index.tsx +12 -4
  107. package/src/theme/ApiExplorer/buildPostmanRequest.ts +47 -63
  108. package/src/theme/ApiExplorer/index.tsx +5 -0
  109. package/src/theme/ApiExplorer/{persistanceMiddleware.ts → persistenceMiddleware.ts} +23 -13
  110. package/src/theme/ApiExplorer/storage-utils.ts +4 -4
  111. package/src/theme/ApiItem/Layout/index.tsx +1 -1
  112. package/src/theme/ApiItem/index.tsx +13 -7
  113. package/src/theme/ApiItem/store.ts +2 -0
  114. package/src/theme/ApiTabs/index.tsx +6 -1
  115. package/src/theme/Example/_Example.scss +11 -0
  116. package/src/theme/Example/index.tsx +168 -0
  117. package/src/theme/Markdown/index.d.ts +8 -0
  118. package/src/theme/ParamsDetails/index.tsx +10 -1
  119. package/src/theme/ParamsItem/index.tsx +38 -54
  120. package/src/theme/RequestSchema/index.tsx +60 -35
  121. package/src/theme/ResponseExamples/index.tsx +23 -3
  122. package/src/theme/ResponseSchema/index.tsx +73 -61
  123. package/src/theme/Schema/index.tsx +307 -55
  124. package/src/theme/SchemaItem/index.tsx +51 -33
  125. package/src/theme/SchemaTabs/index.tsx +19 -5
  126. package/src/theme/StatusCodes/index.tsx +13 -3
  127. package/src/theme/styles.scss +15 -0
  128. package/src/theme/translationIds.ts +111 -0
  129. package/src/theme-openapi.d.ts +7 -275
  130. package/src/{types.ts → types.d.ts} +9 -1
  131. package/tsconfig.tsbuildinfo +1 -1
  132. package/lib/theme/ApiExplorer/persistanceMiddleware.d.ts +0 -3
  133. package/lib/types.d.ts +0 -46
@@ -7,10 +7,12 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
+ import { translate } from "@docusaurus/Translate";
10
11
  import FormItem from "@theme/ApiExplorer/FormItem";
11
12
  import FormSelect from "@theme/ApiExplorer/FormSelect";
12
13
  import FormTextInput from "@theme/ApiExplorer/FormTextInput";
13
14
  import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
15
+ import { OPENAPI_AUTH } from "@theme/translationIds";
14
16
 
15
17
  import { setAuthData, setSelectedAuth } from "./slice";
16
18
 
@@ -32,11 +34,16 @@ function Authorization() {
32
34
  return (
33
35
  <div>
34
36
  {optionKeys.length > 1 && (
35
- <FormItem label="Security Scheme">
37
+ <FormItem
38
+ label={translate({
39
+ id: OPENAPI_AUTH.SECURITY_SCHEME,
40
+ message: "Security Scheme",
41
+ })}
42
+ >
36
43
  <FormSelect
37
44
  options={optionKeys}
38
45
  value={selected}
39
- onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
46
+ onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
40
47
  dispatch(setSelectedAuth(e.target.value));
41
48
  }}
42
49
  />
@@ -45,9 +52,18 @@ function Authorization() {
45
52
  {selectedAuth.map((a: any) => {
46
53
  if (a.type === "http" && a.scheme === "bearer") {
47
54
  return (
48
- <FormItem label="Bearer Token" key={a.key + "-bearer"}>
55
+ <FormItem
56
+ label={translate({
57
+ id: OPENAPI_AUTH.BEARER_TOKEN,
58
+ message: "Bearer Token",
59
+ })}
60
+ key={a.key + "-bearer"}
61
+ >
49
62
  <FormTextInput
50
- placeholder="Bearer Token"
63
+ placeholder={translate({
64
+ id: OPENAPI_AUTH.BEARER_TOKEN,
65
+ message: "Bearer Token",
66
+ })}
51
67
  password
52
68
  value={data[a.key].token ?? ""}
53
69
  onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
@@ -67,9 +83,18 @@ function Authorization() {
67
83
 
68
84
  if (a.type === "oauth2") {
69
85
  return (
70
- <FormItem label="Bearer Token" key={a.key + "-oauth2"}>
86
+ <FormItem
87
+ label={translate({
88
+ id: OPENAPI_AUTH.BEARER_TOKEN,
89
+ message: "Bearer Token",
90
+ })}
91
+ key={a.key + "-oauth2"}
92
+ >
71
93
  <FormTextInput
72
- placeholder="Bearer Token"
94
+ placeholder={translate({
95
+ id: OPENAPI_AUTH.BEARER_TOKEN,
96
+ message: "Bearer Token",
97
+ })}
73
98
  password
74
99
  value={data[a.key].token ?? ""}
75
100
  onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
@@ -90,9 +115,17 @@ function Authorization() {
90
115
  if (a.type === "http" && a.scheme === "basic") {
91
116
  return (
92
117
  <React.Fragment key={a.key + "-basic"}>
93
- <FormItem label="Username">
118
+ <FormItem
119
+ label={translate({
120
+ id: OPENAPI_AUTH.USERNAME,
121
+ message: "Username",
122
+ })}
123
+ >
94
124
  <FormTextInput
95
- placeholder="Username"
125
+ placeholder={translate({
126
+ id: OPENAPI_AUTH.USERNAME,
127
+ message: "Username",
128
+ })}
96
129
  value={data[a.key].username ?? ""}
97
130
  onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
98
131
  const value = e.target.value;
@@ -106,9 +139,17 @@ function Authorization() {
106
139
  }}
107
140
  />
108
141
  </FormItem>
109
- <FormItem label="Password">
142
+ <FormItem
143
+ label={translate({
144
+ id: OPENAPI_AUTH.PASSWORD,
145
+ message: "Password",
146
+ })}
147
+ >
110
148
  <FormTextInput
111
- placeholder="Password"
149
+ placeholder={translate({
150
+ id: OPENAPI_AUTH.PASSWORD,
151
+ message: "Password",
152
+ })}
112
153
  password
113
154
  value={data[a.key].password ?? ""}
114
155
  onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
@@ -58,7 +58,7 @@ export function createAuth({
58
58
  };
59
59
  options?: ThemeConfig["api"];
60
60
  }): AuthState {
61
- const storage = createStorage("sessionStorage");
61
+ const storage = createStorage(opts?.authPersistence ?? "sessionStorage");
62
62
 
63
63
  let data: AuthState["data"] = {};
64
64
  let options: AuthState["options"] = {};
@@ -0,0 +1,77 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import React, { useState } from "react";
9
+ import FormFileUpload from "@theme/ApiExplorer/FormFileUpload";
10
+ import { useTypedDispatch } from "@theme/ApiItem/hooks";
11
+ import { FileContent, setFileArrayFormBody } from "../slice";
12
+
13
+ interface FileArrayFormItemProps {
14
+ id: string;
15
+ description: string | undefined;
16
+ }
17
+
18
+ export default function FileArrayFormBodyItem({
19
+ id,
20
+ description,
21
+ }: FileArrayFormItemProps): React.JSX.Element {
22
+ const dispatch = useTypedDispatch();
23
+ const [fileItems, setFileItems] = useState<
24
+ Map<number, FileContent["value"] | undefined>
25
+ >(new Map([[0, undefined]]));
26
+
27
+ const handleFileChange = (index: number, file: any) => {
28
+ const newItems = new Map(fileItems);
29
+
30
+ if (file === undefined) {
31
+ newItems.delete(index);
32
+
33
+ setFileItems(newItems);
34
+
35
+ dispatch(
36
+ setFileArrayFormBody({
37
+ key: id,
38
+ value: [...newItems.values()].filter((item) => item !== undefined),
39
+ })
40
+ );
41
+ return;
42
+ }
43
+
44
+ let maxIndex = 0;
45
+
46
+ newItems.keys().forEach((item) => {
47
+ maxIndex = item > maxIndex ? item : maxIndex;
48
+ });
49
+ newItems.set(index, {
50
+ src: `/path/to/${file.name}`,
51
+ content: file,
52
+ });
53
+ newItems.set(index + 1, undefined);
54
+
55
+ setFileItems(newItems);
56
+
57
+ dispatch(
58
+ setFileArrayFormBody({
59
+ key: id,
60
+ value: [...newItems.values()].filter((item) => item !== undefined),
61
+ })
62
+ );
63
+ };
64
+
65
+ return (
66
+ <div>
67
+ {[...fileItems.keys()].map((index) => (
68
+ <div key={index}>
69
+ <FormFileUpload
70
+ placeholder={description || id}
71
+ onChange={(file: any) => handleFileChange(index, file)}
72
+ />
73
+ </div>
74
+ ))}
75
+ </div>
76
+ );
77
+ }
@@ -0,0 +1,120 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import React from "react";
9
+ import FormFileUpload from "@theme/ApiExplorer/FormFileUpload";
10
+ import FormSelect from "@theme/ApiExplorer/FormSelect";
11
+ import FormTextInput from "@theme/ApiExplorer/FormTextInput";
12
+ import LiveApp from "@theme/ApiExplorer/LiveEditor";
13
+ import { useTypedDispatch } from "@theme/ApiItem/hooks";
14
+ import { SchemaObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
15
+ import { clearFormBodyKey, setFileFormBody, setStringFormBody } from "../slice";
16
+ import FileArrayFormBodyItem from "../FileArrayFormBodyItem";
17
+
18
+ interface FormBodyItemProps {
19
+ schemaObject: SchemaObject;
20
+ id: string;
21
+ schema: SchemaObject;
22
+ }
23
+
24
+ export default function FormBodyItem({
25
+ schemaObject,
26
+ id,
27
+ schema,
28
+ }: FormBodyItemProps): React.JSX.Element {
29
+ const dispatch = useTypedDispatch();
30
+
31
+ if (
32
+ schemaObject.type === "array" &&
33
+ schemaObject.items?.format === "binary"
34
+ ) {
35
+ return (
36
+ <FileArrayFormBodyItem id={id} description={schemaObject.description} />
37
+ );
38
+ }
39
+
40
+ if (schemaObject.format === "binary") {
41
+ return (
42
+ <FormFileUpload
43
+ placeholder={schemaObject.description || id}
44
+ onChange={(file: any) => {
45
+ if (file === undefined) {
46
+ dispatch(clearFormBodyKey(id));
47
+ return;
48
+ }
49
+ dispatch(
50
+ setFileFormBody({
51
+ key: id,
52
+ value: {
53
+ src: `/path/to/${file.name}`,
54
+ content: file,
55
+ },
56
+ })
57
+ );
58
+ }}
59
+ />
60
+ );
61
+ }
62
+
63
+ if (
64
+ schemaObject.type === "object" &&
65
+ (schemaObject.example || schemaObject.examples)
66
+ ) {
67
+ const objectExample = JSON.stringify(
68
+ schemaObject.example ?? schemaObject.examples[0],
69
+ null,
70
+ 2
71
+ );
72
+
73
+ return (
74
+ <LiveApp
75
+ action={(code: string) =>
76
+ dispatch(setStringFormBody({ key: id, value: code }))
77
+ }
78
+ >
79
+ {objectExample}
80
+ </LiveApp>
81
+ );
82
+ }
83
+
84
+ if (
85
+ schemaObject.enum &&
86
+ schemaObject.enum.every((value) => typeof value === "string")
87
+ ) {
88
+ return (
89
+ <FormSelect
90
+ options={["---", ...schemaObject.enum]}
91
+ onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
92
+ const val = e.target.value;
93
+ if (val === "---") {
94
+ dispatch(clearFormBodyKey(id));
95
+ } else {
96
+ dispatch(
97
+ setStringFormBody({
98
+ key: id,
99
+ value: val,
100
+ })
101
+ );
102
+ }
103
+ }}
104
+ />
105
+ );
106
+ }
107
+ // TODO: support all the other types.
108
+ return (
109
+ <FormTextInput
110
+ paramName={id}
111
+ isRequired={
112
+ Array.isArray(schema.required) && schema.required.includes(id)
113
+ }
114
+ placeholder={schemaObject.description || id}
115
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
116
+ dispatch(setStringFormBody({ key: id, value: e.target.value }));
117
+ }}
118
+ />
119
+ );
120
+ }