docusaurus-theme-openapi-docs 4.3.7 → 4.4.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.
@@ -13,7 +13,8 @@
13
13
 
14
14
  &:hover {
15
15
  border: 2px dashed var(--ifm-color-primary);
16
- background: linear-gradient(
16
+ background:
17
+ linear-gradient(
17
18
  var(--openapi-dropzone-hover-shim),
18
19
  var(--openapi-dropzone-hover-shim)
19
20
  ),
@@ -38,7 +39,8 @@
38
39
  font-size: var(--ifm-code-font-size);
39
40
  border: 2px dashed var(--ifm-color-primary);
40
41
 
41
- background: linear-gradient(
42
+ background:
43
+ linear-gradient(
42
44
  var(--openapi-dropzone-hover-shim),
43
45
  var(--openapi-dropzone-hover-shim)
44
46
  ),
@@ -45,8 +45,8 @@
45
45
  line-height: 1.5;
46
46
 
47
47
  transition-property: color, background, border-color, box-shadow;
48
- transition-duration: 100ms, 100ms, 100ms,
49
- var(--ifm-button-transition-duration);
48
+ transition-duration:
49
+ 100ms, 100ms, 100ms, var(--ifm-button-transition-duration);
50
50
  transition-timing-function: cubic-bezier(0.08, 0.52, 0.52, 1);
51
51
 
52
52
  -webkit-user-select: none;
@@ -85,8 +85,8 @@
85
85
  padding: 0.5rem 1rem;
86
86
  font-size: 12px;
87
87
  transition-property: color, background, border-color, box-shadow;
88
- transition-duration: 100ms, 100ms, 100ms,
89
- var(--ifm-button-transition-duration);
88
+ transition-duration:
89
+ 100ms, 100ms, 100ms, var(--ifm-button-transition-duration);
90
90
  transition-timing-function: cubic-bezier(0.08, 0.52, 0.52, 1);
91
91
  user-select: none;
92
92
  white-space: nowrap;
@@ -158,15 +158,36 @@ function Request({ item }) {
158
158
  paramsArray.push(param);
159
159
  });
160
160
  const methods = (0, react_hook_form_1.useForm)({ shouldFocusError: false });
161
+ const handleEventStream = async (res) => {
162
+ res.headers &&
163
+ dispatch((0, slice_1.setHeaders)(Object.fromEntries(res.headers)));
164
+ dispatch((0, slice_1.setCode)(res.status));
165
+ const reader = res.body.getReader();
166
+ const decoder = new TextDecoder();
167
+ let result = "";
168
+ while (true) {
169
+ const { done, value } = await reader.read();
170
+ if (done) break;
171
+ result += decoder.decode(value, { stream: true });
172
+ dispatch((0, slice_1.setResponse)(result));
173
+ }
174
+ };
175
+ const handleResponse = async (res) => {
176
+ dispatch((0, slice_1.setResponse)(await res.text()));
177
+ dispatch((0, slice_1.setCode)(res.status));
178
+ res.headers &&
179
+ dispatch((0, slice_1.setHeaders)(Object.fromEntries(res.headers)));
180
+ };
161
181
  const onSubmit = async (data) => {
162
182
  dispatch((0, slice_1.setResponse)("Fetching..."));
163
183
  try {
164
184
  await delay(1200);
165
185
  const res = await (0, makeRequest_1.default)(postmanRequest, proxy, body);
166
- dispatch((0, slice_1.setResponse)(await res.text()));
167
- dispatch((0, slice_1.setCode)(res.status));
168
- res.headers &&
169
- dispatch((0, slice_1.setHeaders)(Object.fromEntries(res.headers)));
186
+ if (res.headers.get("content-type")?.includes("text/event-stream")) {
187
+ await handleEventStream(res);
188
+ } else {
189
+ await handleResponse(res);
190
+ }
170
191
  } catch (e) {
171
192
  console.log(e);
172
193
  dispatch((0, slice_1.setResponse)("Connection failed"));
@@ -44,9 +44,12 @@ function ParamsItem({ param, ...rest }) {
44
44
  } = param;
45
45
  let schema = param.schema;
46
46
  let defaultValue;
47
- if (!schema || !schema?.type) {
47
+ if (!schema) {
48
48
  schema = { type: "any" };
49
49
  }
50
+ if (!schema.type) {
51
+ schema.type = "any";
52
+ }
50
53
  if (schema) {
51
54
  if (schema.items) {
52
55
  defaultValue = schema.items.default;
@@ -344,7 +344,8 @@ const DiscriminatorNode = ({ discriminator, schema, schemaType }) => {
344
344
  mergedSubSchema = mergeAllOf(subSchema);
345
345
  }
346
346
  const subProperties = subSchema.properties || mergedSubSchema.properties;
347
- if (subProperties[discriminator.propertyName]) {
347
+ // Add a safeguard check to avoid referencing subProperties if it's undefined
348
+ if (subProperties && subProperties[discriminator.propertyName]) {
348
349
  if (schema.properties) {
349
350
  schema.properties[discriminator.propertyName] = {
350
351
  ...schema.properties[discriminator.propertyName],
@@ -777,6 +778,37 @@ const SchemaEdge = ({ name, schema, required, discriminator, schemaType }) => {
777
778
  children: null,
778
779
  });
779
780
  };
781
+ function renderChildren(schema, schemaType) {
782
+ return react_1.default.createElement(
783
+ react_1.default.Fragment,
784
+ null,
785
+ schema.oneOf &&
786
+ react_1.default.createElement(AnyOneOf, {
787
+ schema: schema,
788
+ schemaType: schemaType,
789
+ }),
790
+ schema.anyOf &&
791
+ react_1.default.createElement(AnyOneOf, {
792
+ schema: schema,
793
+ schemaType: schemaType,
794
+ }),
795
+ schema.properties &&
796
+ react_1.default.createElement(Properties, {
797
+ schema: schema,
798
+ schemaType: schemaType,
799
+ }),
800
+ schema.additionalProperties &&
801
+ react_1.default.createElement(AdditionalProperties, {
802
+ schema: schema,
803
+ schemaType: schemaType,
804
+ }),
805
+ schema.items &&
806
+ react_1.default.createElement(Items, {
807
+ schema: schema,
808
+ schemaType: schemaType,
809
+ })
810
+ );
811
+ }
780
812
  const SchemaNode = ({ schema, schemaType }) => {
781
813
  if (
782
814
  (schemaType === "request" && schema.readOnly) ||
@@ -826,12 +858,6 @@ const SchemaNode = ({ schema, schemaType }) => {
826
858
  })
827
859
  );
828
860
  }
829
- if (schema.oneOf || schema.anyOf) {
830
- return react_1.default.createElement(AnyOneOf, {
831
- schema: schema,
832
- schemaType: schemaType,
833
- });
834
- }
835
861
  // Handle primitives
836
862
  if (
837
863
  schema.type &&
@@ -854,34 +880,6 @@ const SchemaNode = ({ schema, schemaType }) => {
854
880
  children: null,
855
881
  });
856
882
  }
857
- return react_1.default.createElement(
858
- "div",
859
- null,
860
- schema.oneOf &&
861
- react_1.default.createElement(AnyOneOf, {
862
- schema: schema,
863
- schemaType: schemaType,
864
- }),
865
- schema.anyOf &&
866
- react_1.default.createElement(AnyOneOf, {
867
- schema: schema,
868
- schemaType: schemaType,
869
- }),
870
- schema.properties &&
871
- react_1.default.createElement(Properties, {
872
- schema: schema,
873
- schemaType: schemaType,
874
- }),
875
- schema.additionalProperties &&
876
- react_1.default.createElement(AdditionalProperties, {
877
- schema: schema,
878
- schemaType: schemaType,
879
- }),
880
- schema.items &&
881
- react_1.default.createElement(Items, {
882
- schema: schema,
883
- schemaType: schemaType,
884
- })
885
- );
883
+ return renderChildren(schema, schemaType);
886
884
  };
887
885
  exports.default = SchemaNode;
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.3.7",
4
+ "version": "4.4.0",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -36,7 +36,7 @@
36
36
  "@types/lodash": "^4.14.176",
37
37
  "@types/pako": "^2.0.3",
38
38
  "concurrently": "^5.2.0",
39
- "docusaurus-plugin-openapi-docs": "^4.3.7",
39
+ "docusaurus-plugin-openapi-docs": "^4.4.0",
40
40
  "docusaurus-plugin-sass": "^0.2.3",
41
41
  "eslint-plugin-prettier": "^5.0.1"
42
42
  },
@@ -79,5 +79,5 @@
79
79
  "engines": {
80
80
  "node": ">=14"
81
81
  },
82
- "gitHead": "e4d3ec4ebfb8415e97951076ce2f0901e8d88168"
82
+ "gitHead": "808e4a252af8e24201e38a6ecbddb05b844891a2"
83
83
  }
@@ -237,8 +237,7 @@ function Body({
237
237
  try {
238
238
  // If the value is already valid JSON we shouldn't double encode the value
239
239
  JSON.parse(example.value);
240
- }
241
- catch (e) {
240
+ } catch (e) {
242
241
  body = JSON.stringify(example.value, null, 2);
243
242
  }
244
243
 
@@ -13,7 +13,8 @@
13
13
 
14
14
  &:hover {
15
15
  border: 2px dashed var(--ifm-color-primary);
16
- background: linear-gradient(
16
+ background:
17
+ linear-gradient(
17
18
  var(--openapi-dropzone-hover-shim),
18
19
  var(--openapi-dropzone-hover-shim)
19
20
  ),
@@ -38,7 +39,8 @@
38
39
  font-size: var(--ifm-code-font-size);
39
40
  border: 2px dashed var(--ifm-color-primary);
40
41
 
41
- background: linear-gradient(
42
+ background:
43
+ linear-gradient(
42
44
  var(--openapi-dropzone-hover-shim),
43
45
  var(--openapi-dropzone-hover-shim)
44
46
  ),
@@ -45,8 +45,8 @@
45
45
  line-height: 1.5;
46
46
 
47
47
  transition-property: color, background, border-color, box-shadow;
48
- transition-duration: 100ms, 100ms, 100ms,
49
- var(--ifm-button-transition-duration);
48
+ transition-duration:
49
+ 100ms, 100ms, 100ms, var(--ifm-button-transition-duration);
50
50
  transition-timing-function: cubic-bezier(0.08, 0.52, 0.52, 1);
51
51
 
52
52
  -webkit-user-select: none;
@@ -85,8 +85,8 @@
85
85
  padding: 0.5rem 1rem;
86
86
  font-size: 12px;
87
87
  transition-property: color, background, border-color, box-shadow;
88
- transition-duration: 100ms, 100ms, 100ms,
89
- var(--ifm-button-transition-duration);
88
+ transition-duration:
89
+ 100ms, 100ms, 100ms, var(--ifm-button-transition-duration);
90
90
  transition-timing-function: cubic-bezier(0.08, 0.52, 0.52, 1);
91
91
  user-select: none;
92
92
  white-space: nowrap;
@@ -95,14 +95,37 @@ function Request({ item }: { item: ApiItem }) {
95
95
 
96
96
  const methods = useForm({ shouldFocusError: false });
97
97
 
98
+ const handleEventStream = async (res) => {
99
+ res.headers && dispatch(setHeaders(Object.fromEntries(res.headers)));
100
+ dispatch(setCode(res.status));
101
+
102
+ const reader = res.body.getReader();
103
+ const decoder = new TextDecoder();
104
+ let result = "";
105
+ while (true) {
106
+ const { done, value } = await reader.read();
107
+ if (done) break;
108
+ result += decoder.decode(value, { stream: true });
109
+ dispatch(setResponse(result));
110
+ }
111
+ };
112
+
113
+ const handleResponse = async (res) => {
114
+ dispatch(setResponse(await res.text()));
115
+ dispatch(setCode(res.status));
116
+ res.headers && dispatch(setHeaders(Object.fromEntries(res.headers)));
117
+ };
118
+
98
119
  const onSubmit = async (data) => {
99
120
  dispatch(setResponse("Fetching..."));
100
121
  try {
101
122
  await delay(1200);
102
123
  const res = await makeRequest(postmanRequest, proxy, body);
103
- dispatch(setResponse(await res.text()));
104
- dispatch(setCode(res.status));
105
- res.headers && dispatch(setHeaders(Object.fromEntries(res.headers)));
124
+ if (res.headers.get("content-type")?.includes("text/event-stream")) {
125
+ await handleEventStream(res);
126
+ } else {
127
+ await handleResponse(res);
128
+ }
106
129
  } catch (e: any) {
107
130
  console.log(e);
108
131
  dispatch(setResponse("Connection failed"));
@@ -70,9 +70,14 @@ function ParamsItem({ param, ...rest }: Props) {
70
70
  let schema = param.schema;
71
71
  let defaultValue: string | undefined;
72
72
 
73
- if (!schema || !schema?.type) {
73
+ if (!schema) {
74
74
  schema = { type: "any" };
75
75
  }
76
+
77
+ if (!schema.type) {
78
+ schema.type = "any";
79
+ }
80
+
76
81
  if (schema) {
77
82
  if (schema.items) {
78
83
  defaultValue = schema.items.default;
@@ -352,7 +352,8 @@ const DiscriminatorNode: React.FC<DiscriminatorNodeProps> = ({
352
352
  }
353
353
 
354
354
  const subProperties = subSchema.properties || mergedSubSchema.properties;
355
- if (subProperties[discriminator.propertyName]) {
355
+ // Add a safeguard check to avoid referencing subProperties if it's undefined
356
+ if (subProperties && subProperties[discriminator.propertyName]) {
356
357
  if (schema.properties) {
357
358
  schema.properties![discriminator.propertyName] = {
358
359
  ...schema.properties![discriminator.propertyName],
@@ -840,6 +841,25 @@ const SchemaEdge: React.FC<SchemaEdgeProps> = ({
840
841
  );
841
842
  };
842
843
 
844
+ function renderChildren(
845
+ schema: SchemaObject,
846
+ schemaType: "request" | "response"
847
+ ) {
848
+ return (
849
+ <>
850
+ {schema.oneOf && <AnyOneOf schema={schema} schemaType={schemaType} />}
851
+ {schema.anyOf && <AnyOneOf schema={schema} schemaType={schemaType} />}
852
+ {schema.properties && (
853
+ <Properties schema={schema} schemaType={schemaType} />
854
+ )}
855
+ {schema.additionalProperties && (
856
+ <AdditionalProperties schema={schema} schemaType={schemaType} />
857
+ )}
858
+ {schema.items && <Items schema={schema} schemaType={schemaType} />}
859
+ </>
860
+ );
861
+ }
862
+
843
863
  const SchemaNode: React.FC<SchemaProps> = ({ schema, schemaType }) => {
844
864
  if (
845
865
  (schemaType === "request" && schema.readOnly) ||
@@ -888,10 +908,6 @@ const SchemaNode: React.FC<SchemaProps> = ({ schema, schemaType }) => {
888
908
  );
889
909
  }
890
910
 
891
- if (schema.oneOf || schema.anyOf) {
892
- return <AnyOneOf schema={schema} schemaType={schemaType} />;
893
- }
894
-
895
911
  // Handle primitives
896
912
  if (
897
913
  schema.type &&
@@ -917,19 +933,7 @@ const SchemaNode: React.FC<SchemaProps> = ({ schema, schemaType }) => {
917
933
  );
918
934
  }
919
935
 
920
- return (
921
- <div>
922
- {schema.oneOf && <AnyOneOf schema={schema} schemaType={schemaType} />}
923
- {schema.anyOf && <AnyOneOf schema={schema} schemaType={schemaType} />}
924
- {schema.properties && (
925
- <Properties schema={schema} schemaType={schemaType} />
926
- )}
927
- {schema.additionalProperties && (
928
- <AdditionalProperties schema={schema} schemaType={schemaType} />
929
- )}
930
- {schema.items && <Items schema={schema} schemaType={schemaType} />}
931
- </div>
932
- );
936
+ return renderChildren(schema, schemaType);
933
937
  };
934
938
 
935
939
  export default SchemaNode;