docusaurus-theme-openapi-docs 4.4.0 → 4.5.1

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 (45) hide show
  1. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +3 -3
  2. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.d.ts +5 -1
  3. package/lib/theme/ApiExplorer/Authorization/slice.js +2 -2
  4. package/lib/theme/ApiExplorer/Body/slice.js +2 -2
  5. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +3 -3
  6. package/lib/theme/ApiExplorer/Request/index.js +2 -2
  7. package/lib/theme/ApiExplorer/Request/makeRequest.d.ts +1 -1
  8. package/lib/theme/ApiExplorer/Request/makeRequest.js +3 -2
  9. package/lib/theme/ApiExplorer/Response/slice.js +2 -2
  10. package/lib/theme/ApiExplorer/Server/slice.js +2 -2
  11. package/lib/theme/ApiExplorer/buildPostmanRequest.d.ts +1 -1
  12. package/lib/theme/ApiExplorer/buildPostmanRequest.js +119 -46
  13. package/lib/theme/ApiExplorer/index.js +64 -2
  14. package/lib/theme/CodeSamples/_CodeSamples.scss +3 -0
  15. package/lib/theme/CodeSamples/index.d.ts +8 -0
  16. package/lib/theme/{ResponseSamples → CodeSamples}/index.js +4 -4
  17. package/lib/theme/ParamsItem/index.d.ts +1 -4
  18. package/lib/theme/ResponseExamples/index.js +9 -9
  19. package/lib/theme/Schema/index.js +39 -97
  20. package/lib/theme/SchemaItem/index.js +34 -0
  21. package/lib/theme/styles.scss +1 -1
  22. package/lib/types.d.ts +5 -116
  23. package/package.json +5 -3
  24. package/src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx +3 -3
  25. package/src/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.tsx +5 -1
  26. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +3 -3
  27. package/src/theme/ApiExplorer/Request/index.tsx +2 -2
  28. package/src/theme/ApiExplorer/Request/makeRequest.ts +4 -3
  29. package/src/theme/ApiExplorer/buildPostmanRequest.ts +48 -18
  30. package/src/theme/ApiExplorer/index.tsx +8 -2
  31. package/src/theme/CodeSamples/_CodeSamples.scss +3 -0
  32. package/src/theme/{ResponseSamples → CodeSamples}/index.tsx +5 -10
  33. package/src/theme/ParamsItem/index.tsx +1 -5
  34. package/src/theme/ResponseExamples/index.tsx +6 -9
  35. package/src/theme/Schema/index.tsx +47 -78
  36. package/src/theme/SchemaItem/index.tsx +27 -0
  37. package/src/theme/styles.scss +1 -1
  38. package/src/types.ts +5 -115
  39. package/tsconfig.tsbuildinfo +1 -1
  40. package/lib/theme/ResponseSamples/_ResponseSamples.scss +0 -3
  41. package/lib/theme/ResponseSamples/index.d.ts +0 -8
  42. package/src/theme/ApiExplorer/postman-collection.d.ts +0 -10
  43. package/src/theme/ApiExplorer/react-modal.d.ts +0 -8
  44. package/src/theme/ResponseSamples/_ResponseSamples.scss +0 -3
  45. package/src/theme-translations.d.ts +0 -9
@@ -108,15 +108,13 @@ const AnyOneOf = ({ schema, schemaType }) => {
108
108
  SchemaTabs_1.default,
109
109
  null,
110
110
  schema[type]?.map((anyOneSchema, index) => {
111
- const label = anyOneSchema.title || `MOD${index + 1}`;
111
+ const label = anyOneSchema.title || anyOneSchema.type;
112
112
  return (
113
113
  // @ts-ignore
114
114
  react_1.default.createElement(
115
115
  TabItem_1.default,
116
116
  { key: index, label: label, value: `${index}-item-properties` },
117
- ["string", "number", "integer", "boolean"].includes(
118
- anyOneSchema.type
119
- ) &&
117
+ (isPrimitive(anyOneSchema) || anyOneSchema.const) &&
120
118
  react_1.default.createElement(SchemaItem_1.default, {
121
119
  collapsible: false,
122
120
  name: undefined,
@@ -483,111 +481,45 @@ const SchemaNodeDetails = ({
483
481
  );
484
482
  };
485
483
  const Items = ({ schema, schemaType }) => {
486
- // Handles case when schema.items has properties
487
- if (schema.items?.properties) {
488
- return react_1.default.createElement(
489
- react_1.default.Fragment,
490
- null,
491
- react_1.default.createElement(ArrayBrackets_1.OpeningArrayBracket, null),
492
- react_1.default.createElement(Properties, {
493
- schema: schema.items,
494
- schemaType: schemaType,
495
- }),
496
- react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
497
- );
498
- }
499
- // Handles case when schema.items has additionalProperties
500
- if (schema.items?.additionalProperties) {
501
- return react_1.default.createElement(
502
- react_1.default.Fragment,
503
- null,
504
- react_1.default.createElement(ArrayBrackets_1.OpeningArrayBracket, null),
505
- react_1.default.createElement(AdditionalProperties, {
506
- schema: schema.items,
507
- schemaType: schemaType,
508
- }),
509
- react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
510
- );
484
+ // Process schema.items to handle allOf merging
485
+ let itemsSchema = schema.items;
486
+ if (schema.items?.allOf) {
487
+ itemsSchema = mergeAllOf(schema.items);
511
488
  }
512
- // Handles case when schema.items has oneOf or anyOf
513
- if (schema.items?.oneOf || schema.items?.anyOf) {
489
+ // Handle complex schemas with multiple schema types
490
+ const hasOneOfAnyOf = itemsSchema?.oneOf || itemsSchema?.anyOf;
491
+ const hasProperties = itemsSchema?.properties;
492
+ const hasAdditionalProperties = itemsSchema?.additionalProperties;
493
+ if (hasOneOfAnyOf || hasProperties || hasAdditionalProperties) {
514
494
  return react_1.default.createElement(
515
495
  react_1.default.Fragment,
516
496
  null,
517
497
  react_1.default.createElement(ArrayBrackets_1.OpeningArrayBracket, null),
518
- react_1.default.createElement(AnyOneOf, {
519
- schema: schema.items,
520
- schemaType: schemaType,
521
- }),
522
- react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
523
- );
524
- }
525
- // Handles case when schema.items has allOf
526
- if (schema.items?.allOf) {
527
- const mergedSchemas = mergeAllOf(schema.items);
528
- // Handles combo anyOf/oneOf + properties
529
- if (
530
- (mergedSchemas.oneOf || mergedSchemas.anyOf) &&
531
- mergedSchemas.properties
532
- ) {
533
- return react_1.default.createElement(
534
- react_1.default.Fragment,
535
- null,
536
- react_1.default.createElement(
537
- ArrayBrackets_1.OpeningArrayBracket,
538
- null
539
- ),
498
+ hasOneOfAnyOf &&
540
499
  react_1.default.createElement(AnyOneOf, {
541
- schema: mergedSchemas,
500
+ schema: itemsSchema,
542
501
  schemaType: schemaType,
543
502
  }),
503
+ hasProperties &&
544
504
  react_1.default.createElement(Properties, {
545
- schema: mergedSchemas,
505
+ schema: itemsSchema,
546
506
  schemaType: schemaType,
547
507
  }),
548
- react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
549
- );
550
- }
551
- // Handles only anyOf/oneOf
552
- if (mergedSchemas.oneOf || mergedSchemas.anyOf) {
553
- return react_1.default.createElement(
554
- react_1.default.Fragment,
555
- null,
556
- react_1.default.createElement(
557
- ArrayBrackets_1.OpeningArrayBracket,
558
- null
559
- ),
560
- react_1.default.createElement(AnyOneOf, {
561
- schema: mergedSchemas,
508
+ hasAdditionalProperties &&
509
+ react_1.default.createElement(AdditionalProperties, {
510
+ schema: itemsSchema,
562
511
  schemaType: schemaType,
563
512
  }),
564
- react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
565
- );
566
- }
567
- // Handles properties
568
- if (mergedSchemas.properties) {
569
- return react_1.default.createElement(
570
- react_1.default.Fragment,
571
- null,
572
- react_1.default.createElement(
573
- ArrayBrackets_1.OpeningArrayBracket,
574
- null
575
- ),
576
- react_1.default.createElement(Properties, {
577
- schema: mergedSchemas,
578
- schemaType: schemaType,
579
- }),
580
- react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
581
- );
582
- }
513
+ react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
514
+ );
583
515
  }
584
516
  // Handles basic types (string, number, integer, boolean, object)
585
517
  if (
586
- schema.items?.type === "string" ||
587
- schema.items?.type === "number" ||
588
- schema.items?.type === "integer" ||
589
- schema.items?.type === "boolean" ||
590
- schema.items?.type === "object"
518
+ itemsSchema?.type === "string" ||
519
+ itemsSchema?.type === "number" ||
520
+ itemsSchema?.type === "integer" ||
521
+ itemsSchema?.type === "boolean" ||
522
+ itemsSchema?.type === "object"
591
523
  ) {
592
524
  return react_1.default.createElement(
593
525
  "div",
@@ -596,9 +528,9 @@ const Items = ({ schema, schemaType }) => {
596
528
  react_1.default.createElement(SchemaItem_1.default, {
597
529
  collapsible: false,
598
530
  name: "", // No name for array items
599
- schemaName: (0, schema_1.getSchemaName)(schema.items),
600
- qualifierMessage: (0, schema_1.getQualifierMessage)(schema.items),
601
- schema: schema.items,
531
+ schemaName: (0, schema_1.getSchemaName)(itemsSchema),
532
+ qualifierMessage: (0, schema_1.getQualifierMessage)(itemsSchema),
533
+ schema: itemsSchema,
602
534
  discriminator: false,
603
535
  children: null,
604
536
  }),
@@ -610,7 +542,7 @@ const Items = ({ schema, schemaType }) => {
610
542
  react_1.default.Fragment,
611
543
  null,
612
544
  react_1.default.createElement(ArrayBrackets_1.OpeningArrayBracket, null),
613
- Object.entries(schema.items || {}).map(([key, val]) =>
545
+ Object.entries(itemsSchema || {}).map(([key, val]) =>
614
546
  react_1.default.createElement(SchemaEdge, {
615
547
  key: key,
616
548
  name: key,
@@ -883,3 +815,13 @@ const SchemaNode = ({ schema, schemaType }) => {
883
815
  return renderChildren(schema, schemaType);
884
816
  };
885
817
  exports.default = SchemaNode;
818
+ const PRIMITIVE_TYPES = {
819
+ string: true,
820
+ number: true,
821
+ integer: true,
822
+ boolean: true,
823
+ null: true,
824
+ };
825
+ const isPrimitive = (schema) => {
826
+ return PRIMITIVE_TYPES[schema.type];
827
+ };
@@ -51,6 +51,7 @@ function SchemaItem(props) {
51
51
  let example;
52
52
  let nullable;
53
53
  let enumDescriptions = [];
54
+ let constValue;
54
55
  if (schema) {
55
56
  deprecated = schema.deprecated;
56
57
  schemaDescription = schema.description;
@@ -60,6 +61,7 @@ function SchemaItem(props) {
60
61
  nullable =
61
62
  schema.nullable ||
62
63
  (Array.isArray(schema.type) && schema.type.includes("null")); // support JSON Schema nullable
64
+ constValue = schema.const;
63
65
  }
64
66
  const renderRequired = (0, utils_1.guard)(
65
67
  Array.isArray(required) ? required.includes(name) : required,
@@ -170,6 +172,37 @@ function SchemaItem(props) {
170
172
  }
171
173
  return undefined;
172
174
  }
175
+ function renderConstValue() {
176
+ if (constValue !== undefined) {
177
+ if (typeof constValue === "string") {
178
+ return react_1.default.createElement(
179
+ "div",
180
+ null,
181
+ react_1.default.createElement("strong", null, "Constant value: "),
182
+ react_1.default.createElement(
183
+ "span",
184
+ null,
185
+ react_1.default.createElement("code", null, constValue)
186
+ )
187
+ );
188
+ }
189
+ return react_1.default.createElement(
190
+ "div",
191
+ null,
192
+ react_1.default.createElement("strong", null, "Constant value: "),
193
+ react_1.default.createElement(
194
+ "span",
195
+ null,
196
+ react_1.default.createElement(
197
+ "code",
198
+ null,
199
+ JSON.stringify(constValue)
200
+ )
201
+ )
202
+ );
203
+ }
204
+ return undefined;
205
+ }
173
206
  const schemaContent = react_1.default.createElement(
174
207
  "div",
175
208
  null,
@@ -201,6 +234,7 @@ function SchemaItem(props) {
201
234
  renderSchemaDescription,
202
235
  renderEnumDescriptions,
203
236
  renderQualifierMessage,
237
+ renderConstValue(),
204
238
  renderDefaultValue(),
205
239
  renderExample(),
206
240
  collapsibleSchemaContent ?? collapsibleSchemaContent
@@ -38,7 +38,7 @@
38
38
  @use "./SchemaTabs/SchemaTabs";
39
39
  @use "./OperationTabs/OperationTabs";
40
40
  /* Code Samples */
41
- @use "./ResponseSamples/ResponseSamples";
41
+ @use "./CodeSamples/CodeSamples";
42
42
  /* Markdown Styling */
43
43
  @use "./Markdown/Details/Details";
44
44
 
package/lib/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { FrontMatterTag } from "@docusaurus/utils";
1
+ import type { DocFrontMatter as DocusaurusDocFrontMatter } from "@docusaurus/plugin-content-docs";
2
2
  import type { JSONSchema4, JSONSchema6, JSONSchema7 } from "json-schema";
3
3
  export interface ThemeConfig {
4
4
  api?: {
@@ -6,9 +6,6 @@ export interface ThemeConfig {
6
6
  authPersistance?: false | "localStorage" | "sessionStorage";
7
7
  };
8
8
  }
9
- interface Map<T> {
10
- [key: string]: T;
11
- }
12
9
  export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
13
10
  export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
14
11
  type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
@@ -17,7 +14,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
17
14
  anyOf?: SchemaObject[];
18
15
  not?: SchemaObject;
19
16
  items?: SchemaObject;
20
- properties?: Map<SchemaObject>;
17
+ properties?: Record<string, SchemaObject>;
21
18
  additionalProperties?: boolean | SchemaObject;
22
19
  nullable?: boolean;
23
20
  discriminator?: DiscriminatorObject;
@@ -30,7 +27,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
30
27
  };
31
28
  export interface DiscriminatorObject {
32
29
  propertyName: string;
33
- mapping?: Map<string>;
30
+ mapping?: Record<string, string>;
34
31
  }
35
32
  export interface XMLObject {
36
33
  name?: string;
@@ -43,115 +40,7 @@ export interface ExternalDocumentationObject {
43
40
  description?: string;
44
41
  url: string;
45
42
  }
46
- export type FileChange = {
47
- author?: string;
48
- /** Date can be any
49
- * [parsable date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).
50
- */
51
- date?: Date | string;
52
- };
53
- export type DocFrontMatter = {
54
- /**
55
- * The last part of the doc ID (will be refactored in the future to be the
56
- * full ID instead)
57
- * @see {@link DocMetadata.id}
58
- */
59
- id?: string;
60
- /**
61
- * Will override the default title collected from h1 heading.
62
- * @see {@link DocMetadata.title}
63
- */
64
- title?: string;
65
- /**
66
- * Front matter tags, unnormalized.
67
- * @see {@link DocMetadata.tags}
68
- */
69
- tags?: FrontMatterTag[];
70
- /**
71
- * If there isn't a Markdown h1 heading (which, if there is, we don't
72
- * remove), this front matter will cause the front matter title to not be
73
- * displayed in the doc page.
74
- */
75
- hide_title?: boolean;
76
- /** Hide the TOC on the right. */
77
- hide_table_of_contents?: boolean;
78
- /** Used in the head meta. */
79
- keywords?: string[];
80
- /** Used in the head meta. Should use `assets.image` in priority. */
81
- image?: string;
82
- /**
83
- * Will override the default excerpt.
84
- * @see {@link DocMetadata.description}
85
- */
86
- description?: string;
87
- /**
88
- * Custom slug appended after /<baseUrl>/<routeBasePath>/<versionPath>
89
- * @see {@link DocMetadata.slug}
90
- */
91
- slug?: string;
92
- /** Customizes the sidebar label for this doc. Will default to its title. */
93
- sidebar_label?: string;
94
- /**
95
- * Controls the position of a doc inside the generated sidebar slice when
96
- * using autogenerated sidebar items.
97
- *
98
- * @see https://docusaurus.io/docs/sidebar#autogenerated-sidebar-metadata
99
- */
100
- sidebar_position?: number;
101
- /**
102
- * Gives the corresponding sidebar label a special class name when using
103
- * autogenerated sidebars.
104
- */
105
- sidebar_class_name?: string;
106
- /**
107
- * Will be propagated to the final sidebars data structure. Useful if you
108
- * have swizzled sidebar-related code or simply querying doc data through
109
- * sidebars.
110
- */
111
- sidebar_custom_props?: {
112
- [key: string]: unknown;
113
- };
114
- /**
115
- * Changes the sidebar association of the current doc. Use `null` to make
116
- * the current doc not associated to any sidebar.
117
- */
118
- displayed_sidebar?: string | null;
119
- /**
120
- * Customizes the pagination label for this doc. Will default to the sidebar
121
- * label.
122
- */
123
- pagination_label?: string;
124
- /** Overrides the default URL computed for this doc. */
125
- custom_edit_url?: string | null;
126
- /**
127
- * Whether number prefix parsing is disabled on this doc.
128
- * @see https://docusaurus.io/docs/sidebar#using-number-prefixes
129
- */
130
- parse_number_prefixes?: boolean;
131
- /**
132
- * Minimum TOC heading level. Must be between 2 and 6 and lower or equal to
133
- * the max value.
134
- */
135
- toc_min_heading_level?: number;
136
- /** Maximum TOC heading level. Must be between 2 and 6. */
137
- toc_max_heading_level?: number;
138
- /**
139
- * The ID of the documentation you want the "Next" pagination to link to.
140
- * Use `null` to disable showing "Next" for this page.
141
- * @see {@link DocMetadata.next}
142
- */
143
- pagination_next?: string | null;
144
- /**
145
- * The ID of the documentation you want the "Previous" pagination to link
146
- * to. Use `null` to disable showing "Previous" for this page.
147
- * @see {@link DocMetadata.prev}
148
- */
149
- pagination_prev?: string | null;
150
- /** Should this doc be excluded from production builds? */
151
- draft?: boolean;
152
- /** Allows overriding the last updated author and/or date. */
153
- last_update?: FileChange;
43
+ export interface DocFrontMatter extends DocusaurusDocFrontMatter {
154
44
  /** Provides OpenAPI Docs with a reference path to their respective Info Doc */
155
45
  info_path?: string;
156
- };
157
- export {};
46
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-theme-openapi-docs",
3
3
  "description": "OpenAPI theme for Docusaurus.",
4
- "version": "4.4.0",
4
+ "version": "4.5.1",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -35,8 +35,10 @@
35
35
  "@types/file-saver": "^2.0.5",
36
36
  "@types/lodash": "^4.14.176",
37
37
  "@types/pako": "^2.0.3",
38
+ "@types/postman-collection": "^3.5.11",
39
+ "@types/react-modal": "^3.16.3",
38
40
  "concurrently": "^5.2.0",
39
- "docusaurus-plugin-openapi-docs": "^4.4.0",
41
+ "docusaurus-plugin-openapi-docs": "^4.5.1",
40
42
  "docusaurus-plugin-sass": "^0.2.3",
41
43
  "eslint-plugin-prettier": "^5.0.1"
42
44
  },
@@ -79,5 +81,5 @@
79
81
  "engines": {
80
82
  "node": ">=14"
81
83
  },
82
- "gitHead": "808e4a252af8e24201e38a6ecbddb05b844891a2"
84
+ "gitHead": "dab3823034dd9ea74a713ee9d729bd45455d3e5c"
83
85
  }
@@ -96,7 +96,7 @@ export default function CodeBlockString({
96
96
  getLineProps={getLineProps}
97
97
  getTokenProps={getTokenProps}
98
98
  classNames={lineClassNames[i]}
99
- showLineNumbers={showLineNumbers}
99
+ showLineNumbers={!!showLineNumbers}
100
100
  />
101
101
  ))}
102
102
  </code>
@@ -122,9 +122,9 @@ export default function CodeBlockString({
122
122
  )}
123
123
  code={code}
124
124
  language={(language ?? "text") as Language}
125
- showLineNumbers={showLineNumbers}
125
+ showLineNumbers={!!showLineNumbers}
126
126
  blockClassName={blockClassName}
127
- title={title}
127
+ title={typeof title === "string" ? title : undefined}
128
128
  lineClassNames={lineClassNames}
129
129
  />
130
130
  </div>
@@ -7,11 +7,15 @@
7
7
 
8
8
  import React, { useCallback, useState, useRef, useEffect } from "react";
9
9
 
10
- import { CopyButtonProps } from "@docusaurus/theme-common/internal";
11
10
  import { translate } from "@docusaurus/Translate";
12
11
  import clsx from "clsx";
13
12
  import copy from "copy-text-to-clipboard";
14
13
 
14
+ interface CopyButtonProps {
15
+ code: string;
16
+ className?: string;
17
+ }
18
+
15
19
  export default function CopyButton({
16
20
  code,
17
21
  className,
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import React, { useState, useEffect, type JSX } from "react";
8
+ import React, { useState, useEffect } from "react";
9
9
 
10
10
  import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
11
11
  import ApiCodeBlock from "@theme/ApiExplorer/ApiCodeBlock";
@@ -14,7 +14,7 @@ import CodeTabs from "@theme/ApiExplorer/CodeTabs";
14
14
  import { useTypedSelector } from "@theme/ApiItem/hooks";
15
15
  import cloneDeep from "lodash/cloneDeep";
16
16
  import codegen from "postman-code-generators";
17
- import sdk from "postman-collection";
17
+ import * as sdk from "postman-collection";
18
18
 
19
19
  import { CodeSample, Language } from "./code-snippets-types";
20
20
  import {
@@ -31,7 +31,7 @@ export interface Props {
31
31
  codeSamples: CodeSample[];
32
32
  }
33
33
 
34
- function CodeTab({ children, hidden, className }: any): JSX.Element {
34
+ function CodeTab({ children, hidden, className }: any): React.JSX.Element {
35
35
  return (
36
36
  <div role="tabpanel" className={className} {...{ hidden }}>
37
37
  {children}
@@ -26,7 +26,7 @@ import Server from "@theme/ApiExplorer/Server";
26
26
  import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
27
27
  import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
28
28
  import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
29
- import sdk from "postman-collection";
29
+ import * as sdk from "postman-collection";
30
30
  import { FormProvider, useForm } from "react-hook-form";
31
31
 
32
32
  import makeRequest from "./makeRequest";
@@ -126,7 +126,7 @@ function Request({ item }: { item: ApiItem }) {
126
126
  } else {
127
127
  await handleResponse(res);
128
128
  }
129
- } catch (e: any) {
129
+ } catch (e) {
130
130
  console.log(e);
131
131
  dispatch(setResponse("Connection failed"));
132
132
  dispatch(clearCode());
@@ -6,7 +6,7 @@
6
6
  * ========================================================================== */
7
7
 
8
8
  import { Body } from "@theme/ApiExplorer/Body/slice";
9
- import sdk from "postman-collection";
9
+ import * as sdk from "postman-collection";
10
10
 
11
11
  function fetchWithtimeout(
12
12
  url: string,
@@ -156,8 +156,9 @@ async function makeRequest(
156
156
  myHeaders.delete("Content-Type");
157
157
 
158
158
  myBody = new FormData();
159
- if (Array.isArray(request.body.formdata.members)) {
160
- for (const data of request.body.formdata.members) {
159
+ const members = (request.body as any)?.formdata?.members;
160
+ if (Array.isArray(members)) {
161
+ for (const data of members) {
161
162
  if (data.key && data.value.content) {
162
163
  myBody.append(data.key, data.value.content);
163
164
  }
@@ -12,7 +12,7 @@ import {
12
12
  ServerObject,
13
13
  } from "docusaurus-plugin-openapi-docs/src/openapi/types";
14
14
  import cloneDeep from "lodash/cloneDeep";
15
- import sdk from "postman-collection";
15
+ import * as sdk from "postman-collection";
16
16
 
17
17
  type Param = {
18
18
  value?: string | string[];
@@ -73,7 +73,7 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
73
73
  ([key, val]) =>
74
74
  new sdk.QueryParam({
75
75
  key: `${param.name}[${key}]`,
76
- value: val,
76
+ value: String(val),
77
77
  })
78
78
  );
79
79
  } else if (param.explode) {
@@ -81,7 +81,7 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
81
81
  ([key, val]) =>
82
82
  new sdk.QueryParam({
83
83
  key: key,
84
- value: val,
84
+ value: String(val),
85
85
  })
86
86
  );
87
87
  } else {
@@ -181,7 +181,10 @@ function setPathParams(postman: sdk.Request, pathParams: Param[]) {
181
181
  });
182
182
  });
183
183
 
184
- postman.url.variables.assimilate(source, false);
184
+ postman.url.variables.assimilate(
185
+ source.filter((v): v is sdk.Variable => v !== undefined),
186
+ false
187
+ );
185
188
  }
186
189
 
187
190
  function buildCookie(cookieParams: Param[]) {
@@ -207,7 +210,9 @@ function buildCookie(cookieParams: Param[]) {
207
210
  ([key, val]) =>
208
211
  new sdk.Cookie({
209
212
  key: key,
210
- value: val,
213
+ value: String(val),
214
+ domain: "",
215
+ path: "",
211
216
  })
212
217
  );
213
218
  } else {
@@ -217,6 +222,8 @@ function buildCookie(cookieParams: Param[]) {
217
222
  value: Object.entries(jsonResult)
218
223
  .map(([key, val]) => `${key},${val}`)
219
224
  .join(","),
225
+ domain: "",
226
+ path: "",
220
227
  });
221
228
  }
222
229
  }
@@ -224,7 +231,9 @@ function buildCookie(cookieParams: Param[]) {
224
231
  // Handle scalar values
225
232
  return new sdk.Cookie({
226
233
  key: param.name,
227
- value: param.value,
234
+ value: String(param.value),
235
+ domain: "",
236
+ path: "",
228
237
  });
229
238
  }
230
239
  }
@@ -430,10 +439,9 @@ function buildPostmanRequest(
430
439
  clonedPostman.url.host = [url];
431
440
  }
432
441
 
433
- setQueryParams(clonedPostman, queryParams);
434
- setPathParams(clonedPostman, pathParams);
442
+ const enhancedQueryParams = [...queryParams];
443
+ const enhancedCookieParams = [...cookieParams];
435
444
 
436
- const cookie = buildCookie(cookieParams);
437
445
  let otherHeaders = [];
438
446
 
439
447
  let selectedAuth: Scheme[] = [];
@@ -491,24 +499,46 @@ function buildPostmanRequest(
491
499
  continue;
492
500
  }
493
501
 
494
- // API Key
502
+ // API Key in header
495
503
  if (a.type === "apiKey" && a.in === "header") {
496
504
  const { apiKey } = auth.data[a.key];
497
- if (apiKey === undefined) {
498
- otherHeaders.push({
499
- key: a.name,
500
- value: `<${a.name ?? a.type}>`,
501
- });
502
- continue;
503
- }
504
505
  otherHeaders.push({
505
506
  key: a.name,
506
- value: apiKey,
507
+ value: apiKey || `<${a.name ?? a.type}>`,
508
+ });
509
+ continue;
510
+ }
511
+
512
+ // API Key in query
513
+ if (a.type === "apiKey" && a.in === "query") {
514
+ const { apiKey } = auth.data[a.key];
515
+ enhancedQueryParams.push({
516
+ name: a.name,
517
+ in: "query",
518
+ value: apiKey || `<${a.name ?? a.type}>`,
519
+ });
520
+ continue;
521
+ }
522
+
523
+ // API Key in cookie
524
+ if (a.type === "apiKey" && a.in === "cookie") {
525
+ const { apiKey } = auth.data[a.key];
526
+ enhancedCookieParams.push({
527
+ name: a.name,
528
+ in: "cookie",
529
+ value: apiKey || `<${a.name ?? a.type}>`,
507
530
  });
508
531
  continue;
509
532
  }
510
533
  }
511
534
 
535
+ // Use the enhanced params that might include API keys
536
+ setQueryParams(clonedPostman, enhancedQueryParams);
537
+ setPathParams(clonedPostman, pathParams);
538
+
539
+ // Use enhanced cookie params that might include API keys
540
+ const cookie = buildCookie(enhancedCookieParams);
541
+
512
542
  setHeaders(
513
543
  clonedPostman,
514
544
  contentType,