docusaurus-theme-openapi-docs 0.0.0-1084 → 0.0.0-1087

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.
@@ -12,8 +12,6 @@ import { translate } from "@docusaurus/Translate";
12
12
  import json2xml from "@theme/ApiExplorer/Body/json2xml";
13
13
  import FormFileUpload from "@theme/ApiExplorer/FormFileUpload";
14
14
  import FormItem from "@theme/ApiExplorer/FormItem";
15
- import FormSelect from "@theme/ApiExplorer/FormSelect";
16
- import FormTextInput from "@theme/ApiExplorer/FormTextInput";
17
15
  import LiveApp from "@theme/ApiExplorer/LiveEditor";
18
16
  import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
19
17
  import Markdown from "@theme/Markdown";
@@ -23,13 +21,8 @@ import { OPENAPI_BODY, OPENAPI_REQUEST } from "@theme/translationIds";
23
21
  import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
24
22
  import format from "xml-formatter";
25
23
 
26
- import {
27
- clearFormBodyKey,
28
- clearRawBody,
29
- setFileFormBody,
30
- setFileRawBody,
31
- setStringFormBody,
32
- } from "./slice";
24
+ import { clearRawBody, setFileRawBody, setStringRawBody } from "./slice";
25
+ import FormBodyItem from "./FormBodyItem";
33
26
 
34
27
  export interface Props {
35
28
  jsonRequestBodyExample: string;
@@ -130,96 +123,23 @@ function Body({
130
123
  ) {
131
124
  return (
132
125
  <FormItem className="openapi-explorer__form-item-body-container">
133
- <div>
134
- {Object.entries(schema.properties ?? {}).map(([key, val]: any) => {
135
- if (val.format === "binary") {
136
- return (
137
- <FormItem
138
- key={key}
139
- label={key}
140
- required={
141
- Array.isArray(schema.required) &&
142
- schema.required.includes(key)
143
- }
144
- >
145
- <FormFileUpload
146
- placeholder={val.description || key}
147
- onChange={(file: any) => {
148
- if (file === undefined) {
149
- dispatch(clearFormBodyKey(key));
150
- return;
151
- }
152
- dispatch(
153
- setFileFormBody({
154
- key: key,
155
- value: {
156
- src: `/path/to/${file.name}`,
157
- content: file,
158
- },
159
- })
160
- );
161
- }}
162
- />
163
- </FormItem>
164
- );
165
- }
166
-
167
- if (val.enum) {
168
- return (
169
- <FormItem
170
- key={key}
171
- label={key}
172
- required={
173
- Array.isArray(schema.required) &&
174
- schema.required.includes(key)
175
- }
176
- >
177
- <FormSelect
178
- options={["---", ...val.enum]}
179
- onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
180
- const val = e.target.value;
181
- if (val === "---") {
182
- dispatch(clearFormBodyKey(key));
183
- } else {
184
- dispatch(
185
- setStringFormBody({
186
- key: key,
187
- value: val,
188
- })
189
- );
190
- }
191
- }}
192
- />
193
- </FormItem>
194
- );
195
- }
196
- // TODO: support all the other types.
197
- return (
198
- <FormItem
199
- key={key}
200
- label={key}
201
- required={
202
- Array.isArray(schema.required) &&
203
- schema.required.includes(key)
204
- }
205
- >
206
- <FormTextInput
207
- paramName={key}
208
- isRequired={
209
- Array.isArray(schema.required) &&
210
- schema.required.includes(key)
211
- }
212
- placeholder={val.description || key}
213
- onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
214
- dispatch(
215
- setStringFormBody({ key: key, value: e.target.value })
216
- );
217
- }}
218
- />
219
- </FormItem>
220
- );
221
- })}
222
- </div>
126
+ {Object.entries(schema.properties ?? {}).map(([key, val]: any) => {
127
+ return (
128
+ <FormItem
129
+ key={key}
130
+ label={key}
131
+ required={
132
+ Array.isArray(schema.required) && schema.required.includes(key)
133
+ }
134
+ >
135
+ <FormBodyItem
136
+ schemaObject={val}
137
+ id={key}
138
+ schema={schema}
139
+ ></FormBodyItem>
140
+ </FormItem>
141
+ );
142
+ })}
223
143
  </FormItem>
224
144
  );
225
145
  }
@@ -348,7 +268,11 @@ function Body({
348
268
  value="Example (from schema)"
349
269
  default
350
270
  >
351
- <LiveApp action={dispatch} language={language} required={required}>
271
+ <LiveApp
272
+ action={(code: string) => dispatch(setStringRawBody(code))}
273
+ language={language}
274
+ required={required}
275
+ >
352
276
  {defaultBody}
353
277
  </LiveApp>
354
278
  </TabItem>
@@ -357,7 +281,7 @@ function Body({
357
281
  {example.summary && <Markdown>{example.summary}</Markdown>}
358
282
  {exampleBody && (
359
283
  <LiveApp
360
- action={dispatch}
284
+ action={(code: string) => dispatch(setStringRawBody(code))}
361
285
  language={language}
362
286
  required={required}
363
287
  >
@@ -383,7 +307,11 @@ function Body({
383
307
  value="Example (from schema)"
384
308
  default
385
309
  >
386
- <LiveApp action={dispatch} language={language} required={required}>
310
+ <LiveApp
311
+ action={(code: string) => dispatch(setStringRawBody(code))}
312
+ language={language}
313
+ required={required}
314
+ >
387
315
  {defaultBody}
388
316
  </LiveApp>
389
317
  </TabItem>
@@ -397,7 +325,10 @@ function Body({
397
325
  >
398
326
  {example.summary && <Markdown>{example.summary}</Markdown>}
399
327
  {example.body && (
400
- <LiveApp action={dispatch} language={language}>
328
+ <LiveApp
329
+ action={(code: string) => dispatch(setStringRawBody(code))}
330
+ language={language}
331
+ >
401
332
  {example.body}
402
333
  </LiveApp>
403
334
  )}
@@ -411,7 +342,11 @@ function Body({
411
342
 
412
343
  return (
413
344
  <FormItem>
414
- <LiveApp action={dispatch} language={language} required={required}>
345
+ <LiveApp
346
+ action={(code: string) => dispatch(setStringRawBody(code))}
347
+ language={language}
348
+ required={required}
349
+ >
415
350
  {defaultBody}
416
351
  </LiveApp>
417
352
  </FormItem>
@@ -15,12 +15,24 @@ export interface FileContent {
15
15
  };
16
16
  }
17
17
 
18
+ export interface FileArrayContent {
19
+ type: "file[]";
20
+ value: {
21
+ src: string;
22
+ content: Blob;
23
+ }[];
24
+ }
25
+
18
26
  export interface StringContent {
19
27
  type: "string";
20
28
  value?: string;
21
29
  }
22
30
 
23
- export type Content = FileContent | StringContent | undefined;
31
+ export type Content =
32
+ | FileContent
33
+ | FileArrayContent
34
+ | StringContent
35
+ | undefined;
24
36
 
25
37
  export interface FormBody {
26
38
  type: "form";
@@ -118,6 +130,32 @@ export const slice = createSlice({
118
130
  };
119
131
  return state;
120
132
  },
133
+ setFileArrayFormBody: (
134
+ state,
135
+ action: PayloadAction<{
136
+ key: string;
137
+ value: FileArrayContent["value"];
138
+ }>
139
+ ) => {
140
+ if (state?.type !== "form") {
141
+ return {
142
+ type: "form",
143
+ content: {
144
+ [action.payload.key]: {
145
+ type: "file[]",
146
+ value: action.payload.value,
147
+ },
148
+ },
149
+ };
150
+ }
151
+
152
+ state.content[action.payload.key] = {
153
+ type: "file[]",
154
+ value: action.payload.value,
155
+ };
156
+
157
+ return state;
158
+ },
121
159
  },
122
160
  });
123
161
 
@@ -128,6 +166,7 @@ export const {
128
166
  clearFormBodyKey,
129
167
  setStringFormBody,
130
168
  setFileFormBody,
169
+ setFileArrayFormBody,
131
170
  } = slice.actions;
132
171
 
133
172
  export default slice.reducer;
@@ -11,7 +11,6 @@ import { usePrismTheme } from "@docusaurus/theme-common";
11
11
  import { translate } from "@docusaurus/Translate";
12
12
  import useIsBrowser from "@docusaurus/useIsBrowser";
13
13
  import { ErrorMessage } from "@hookform/error-message";
14
- import { setStringRawBody } from "@theme/ApiExplorer/Body/slice";
15
14
  import { OPENAPI_FORM } from "@theme/translationIds";
16
15
  import clsx from "clsx";
17
16
  import { Controller, useFormContext } from "react-hook-form";
@@ -56,8 +55,8 @@ function App({
56
55
  const [code, setCode] = React.useState(children.replace(/\n$/, ""));
57
56
 
58
57
  useEffect(() => {
59
- action(setStringRawBody(code));
60
- }, [action, code]);
58
+ action(code);
59
+ }, [code]);
61
60
 
62
61
  const {
63
62
  control,
@@ -19,7 +19,7 @@ export interface State {
19
19
 
20
20
  const initialState: State = {} as any;
21
21
 
22
- export const slice = createSlice({
22
+ const slice = createSlice({
23
23
  name: "params",
24
24
  initialState,
25
25
  reducers: {
@@ -313,7 +313,11 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
313
313
  switch (clonedPostman.body.mode) {
314
314
  case "raw": {
315
315
  // check file even though it should already be set from above
316
- if (body.type !== "raw" || body.content?.type === "file") {
316
+ if (
317
+ body.type !== "raw" ||
318
+ body.content?.type === "file" ||
319
+ body.content?.type === "file[]"
320
+ ) {
317
321
  clonedPostman.body = undefined;
318
322
  return;
319
323
  }
@@ -328,15 +332,23 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
328
332
  clonedPostman.body.raw = `${body.content?.value}`;
329
333
  return;
330
334
  }
331
- const params = Object.entries(body.content)
335
+ const params: sdk.FormParam[] = [];
336
+ Object.entries(body.content)
332
337
  .filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
333
- .map(([key, content]) => {
338
+ .forEach(([key, content]) => {
334
339
  if (content.type === "file") {
335
- return new sdk.FormParam({ key: key, ...content });
340
+ params.push(new sdk.FormParam({ key: key, ...content }));
341
+ } else if (content.type === "file[]") {
342
+ content.value.forEach((file) =>
343
+ params.push(new sdk.FormParam({ key, value: file }))
344
+ );
345
+ } else {
346
+ params.push(new sdk.FormParam({ key: key, value: content.value }));
336
347
  }
337
- return new sdk.FormParam({ key: key, value: content.value });
338
348
  });
339
- clonedPostman.body.formdata?.assimilate(params, false);
349
+ params.forEach((param) => {
350
+ clonedPostman.body?.formdata?.add(param);
351
+ });
340
352
  return;
341
353
  }
342
354
  case "urlencoded": {
@@ -350,7 +362,11 @@ function setBody(clonedPostman: sdk.Request, body: Body) {
350
362
  const params = Object.entries(body.content)
351
363
  .filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
352
364
  .map(([key, content]) => {
353
- if (content.type !== "file" && content.value) {
365
+ if (
366
+ content.type !== "file" &&
367
+ content.type !== "file[]" &&
368
+ content.value
369
+ ) {
354
370
  return new sdk.QueryParam({ key: key, value: content.value });
355
371
  }
356
372
  return undefined;
@@ -1 +1 @@
1
- {"root":["./src/index.ts","./src/plugin-content-docs.d.ts","./src/postman-code-generators.d.ts","./src/react-magic-dropzone.d.ts","./src/theme-classic.d.ts","./src/theme-openapi.d.ts","./src/types.ts","./src/markdown/createDescription.ts","./src/markdown/schema.ts","./src/markdown/utils.test.ts","./src/markdown/utils.ts","./src/theme/translationIds.ts","./src/theme/ApiExplorer/buildPostmanRequest.ts","./src/theme/ApiExplorer/index.tsx","./src/theme/ApiExplorer/persistenceMiddleware.ts","./src/theme/ApiExplorer/storage-utils.ts","./src/theme/ApiExplorer/Accept/index.tsx","./src/theme/ApiExplorer/Accept/slice.ts","./src/theme/ApiExplorer/ApiCodeBlock/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/Element.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx","./src/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.tsx","./src/theme/ApiExplorer/Authorization/auth-types.ts","./src/theme/ApiExplorer/Authorization/index.tsx","./src/theme/ApiExplorer/Authorization/slice.ts","./src/theme/ApiExplorer/Body/index.tsx","./src/theme/ApiExplorer/Body/json2xml.d.ts","./src/theme/ApiExplorer/Body/slice.ts","./src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts","./src/theme/ApiExplorer/CodeSnippets/index.tsx","./src/theme/ApiExplorer/CodeSnippets/languages.ts","./src/theme/ApiExplorer/CodeTabs/index.tsx","./src/theme/ApiExplorer/ContentType/index.tsx","./src/theme/ApiExplorer/ContentType/slice.ts","./src/theme/ApiExplorer/Export/index.tsx","./src/theme/ApiExplorer/FloatingButton/index.tsx","./src/theme/ApiExplorer/FormFileUpload/index.tsx","./src/theme/ApiExplorer/FormItem/index.tsx","./src/theme/ApiExplorer/FormMultiSelect/index.tsx","./src/theme/ApiExplorer/FormSelect/index.tsx","./src/theme/ApiExplorer/FormTextInput/index.tsx","./src/theme/ApiExplorer/LiveEditor/index.tsx","./src/theme/ApiExplorer/MethodEndpoint/index.tsx","./src/theme/ApiExplorer/ParamOptions/index.tsx","./src/theme/ApiExplorer/ParamOptions/slice.ts","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx","./src/theme/ApiExplorer/Request/index.tsx","./src/theme/ApiExplorer/Request/makeRequest.ts","./src/theme/ApiExplorer/Response/index.tsx","./src/theme/ApiExplorer/Response/slice.ts","./src/theme/ApiExplorer/SecuritySchemes/index.tsx","./src/theme/ApiExplorer/Server/index.tsx","./src/theme/ApiExplorer/Server/slice.ts","./src/theme/ApiItem/hooks.ts","./src/theme/ApiItem/index.tsx","./src/theme/ApiItem/store.ts","./src/theme/ApiItem/Layout/index.tsx","./src/theme/ApiLogo/index.tsx","./src/theme/ApiTabs/index.tsx","./src/theme/ArrayBrackets/index.tsx","./src/theme/CodeSamples/index.tsx","./src/theme/DiscriminatorTabs/index.tsx","./src/theme/Example/index.tsx","./src/theme/Markdown/index.d.ts","./src/theme/MimeTabs/index.tsx","./src/theme/OperationTabs/index.tsx","./src/theme/ParamsDetails/index.tsx","./src/theme/ParamsItem/index.tsx","./src/theme/RequestSchema/index.tsx","./src/theme/ResponseExamples/index.tsx","./src/theme/ResponseHeaders/index.tsx","./src/theme/ResponseSchema/index.tsx","./src/theme/Schema/index.tsx","./src/theme/SchemaItem/index.tsx","./src/theme/SchemaTabs/index.tsx","./src/theme/SkeletonLoader/index.tsx","./src/theme/StatusCodes/index.tsx"],"version":"5.8.3"}
1
+ {"root":["./src/index.ts","./src/plugin-content-docs.d.ts","./src/postman-code-generators.d.ts","./src/react-magic-dropzone.d.ts","./src/theme-classic.d.ts","./src/theme-openapi.d.ts","./src/types.ts","./src/markdown/createDescription.ts","./src/markdown/schema.ts","./src/markdown/utils.test.ts","./src/markdown/utils.ts","./src/theme/translationIds.ts","./src/theme/ApiExplorer/buildPostmanRequest.ts","./src/theme/ApiExplorer/index.tsx","./src/theme/ApiExplorer/persistenceMiddleware.ts","./src/theme/ApiExplorer/storage-utils.ts","./src/theme/ApiExplorer/Accept/index.tsx","./src/theme/ApiExplorer/Accept/slice.ts","./src/theme/ApiExplorer/ApiCodeBlock/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/Element.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx","./src/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx","./src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.tsx","./src/theme/ApiExplorer/Authorization/auth-types.ts","./src/theme/ApiExplorer/Authorization/index.tsx","./src/theme/ApiExplorer/Authorization/slice.ts","./src/theme/ApiExplorer/Body/index.tsx","./src/theme/ApiExplorer/Body/json2xml.d.ts","./src/theme/ApiExplorer/Body/slice.ts","./src/theme/ApiExplorer/Body/FileArrayFormBodyItem/index.tsx","./src/theme/ApiExplorer/Body/FormBodyItem/index.tsx","./src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts","./src/theme/ApiExplorer/CodeSnippets/index.tsx","./src/theme/ApiExplorer/CodeSnippets/languages.ts","./src/theme/ApiExplorer/CodeTabs/index.tsx","./src/theme/ApiExplorer/ContentType/index.tsx","./src/theme/ApiExplorer/ContentType/slice.ts","./src/theme/ApiExplorer/Export/index.tsx","./src/theme/ApiExplorer/FloatingButton/index.tsx","./src/theme/ApiExplorer/FormFileUpload/index.tsx","./src/theme/ApiExplorer/FormItem/index.tsx","./src/theme/ApiExplorer/FormMultiSelect/index.tsx","./src/theme/ApiExplorer/FormSelect/index.tsx","./src/theme/ApiExplorer/FormTextInput/index.tsx","./src/theme/ApiExplorer/LiveEditor/index.tsx","./src/theme/ApiExplorer/MethodEndpoint/index.tsx","./src/theme/ApiExplorer/ParamOptions/index.tsx","./src/theme/ApiExplorer/ParamOptions/slice.ts","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx","./src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx","./src/theme/ApiExplorer/Request/index.tsx","./src/theme/ApiExplorer/Request/makeRequest.ts","./src/theme/ApiExplorer/Response/index.tsx","./src/theme/ApiExplorer/Response/slice.ts","./src/theme/ApiExplorer/SecuritySchemes/index.tsx","./src/theme/ApiExplorer/Server/index.tsx","./src/theme/ApiExplorer/Server/slice.ts","./src/theme/ApiItem/hooks.ts","./src/theme/ApiItem/index.tsx","./src/theme/ApiItem/store.ts","./src/theme/ApiItem/Layout/index.tsx","./src/theme/ApiLogo/index.tsx","./src/theme/ApiTabs/index.tsx","./src/theme/ArrayBrackets/index.tsx","./src/theme/CodeSamples/index.tsx","./src/theme/DiscriminatorTabs/index.tsx","./src/theme/Example/index.tsx","./src/theme/Markdown/index.d.ts","./src/theme/MimeTabs/index.tsx","./src/theme/OperationTabs/index.tsx","./src/theme/ParamsDetails/index.tsx","./src/theme/ParamsItem/index.tsx","./src/theme/RequestSchema/index.tsx","./src/theme/ResponseExamples/index.tsx","./src/theme/ResponseHeaders/index.tsx","./src/theme/ResponseSchema/index.tsx","./src/theme/Schema/index.tsx","./src/theme/SchemaItem/index.tsx","./src/theme/SchemaTabs/index.tsx","./src/theme/SkeletonLoader/index.tsx","./src/theme/StatusCodes/index.tsx"],"version":"5.9.3"}