docusaurus-theme-openapi-docs 1.1.7 → 1.1.10

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 (34) hide show
  1. package/lib/theme/ApiDemoPanel/Body/index.js +11 -1
  2. package/lib/theme/ApiDemoPanel/CodeTabs/styles.module.css +7 -1
  3. package/lib/theme/ApiDemoPanel/Curl/index.js +80 -22
  4. package/lib/theme/ApiDemoPanel/Curl/languages.json +1386 -0
  5. package/lib/theme/ApiItem/Layout/styles.module.css +120 -20
  6. package/lib/theme/ResponseSamples/index.js +2 -2
  7. package/lib-next/theme/ApiDemoPanel/Body/index.js +10 -1
  8. package/lib-next/theme/ApiDemoPanel/CodeTabs/styles.module.css +7 -1
  9. package/lib-next/theme/ApiDemoPanel/Curl/index.js +85 -17
  10. package/lib-next/theme/ApiDemoPanel/Curl/languages.json +1386 -0
  11. package/lib-next/theme/ApiItem/Layout/styles.module.css +120 -20
  12. package/lib-next/theme/ResponseSamples/index.js +2 -2
  13. package/package.json +6 -5
  14. package/src/theme/ApiDemoPanel/Body/index.tsx +10 -1
  15. package/src/theme/ApiDemoPanel/CodeTabs/styles.module.css +7 -1
  16. package/src/theme/ApiDemoPanel/Curl/index.tsx +89 -22
  17. package/src/theme/ApiDemoPanel/Curl/languages.json +1386 -0
  18. package/src/theme/ApiItem/Layout/styles.module.css +120 -20
  19. package/src/theme/ResponseSamples/index.js +2 -2
  20. package/lib/theme/ApiItem/Layout/icons/bash-original.svg +0 -1
  21. package/lib/theme/ApiItem/Layout/icons/go-original-wordmark.svg +0 -1
  22. package/lib/theme/ApiItem/Layout/icons/javascript-original.svg +0 -1
  23. package/lib/theme/ApiItem/Layout/icons/linux-original.svg +0 -1
  24. package/lib/theme/ApiItem/Layout/icons/python-original.svg +0 -1
  25. package/lib-next/theme/ApiItem/Layout/icons/bash-original.svg +0 -1
  26. package/lib-next/theme/ApiItem/Layout/icons/go-original-wordmark.svg +0 -1
  27. package/lib-next/theme/ApiItem/Layout/icons/javascript-original.svg +0 -1
  28. package/lib-next/theme/ApiItem/Layout/icons/linux-original.svg +0 -1
  29. package/lib-next/theme/ApiItem/Layout/icons/python-original.svg +0 -1
  30. package/src/theme/ApiItem/Layout/icons/bash-original.svg +0 -1
  31. package/src/theme/ApiItem/Layout/icons/go-original-wordmark.svg +0 -1
  32. package/src/theme/ApiItem/Layout/icons/javascript-original.svg +0 -1
  33. package/src/theme/ApiItem/Layout/icons/linux-original.svg +0 -1
  34. package/src/theme/ApiItem/Layout/icons/python-original.svg +0 -1
@@ -73,6 +73,8 @@
73
73
 
74
74
  :global(.theme-api-markdown code) {
75
75
  max-width: 600px;
76
+ max-height: 500px;
77
+ overflow: auto;
76
78
  }
77
79
 
78
80
  @media (min-width: 997px) {
@@ -159,18 +161,20 @@
159
161
  padding-left: 2px;
160
162
  }
161
163
 
164
+ /* CodeTabs */
165
+
162
166
  :global(.code__tab--python::after) {
163
167
  content: "";
164
- width: 32px;
165
- height: 32px;
166
- background: url(./icons/python-original.svg);
168
+ width: 28px;
169
+ height: 28px;
170
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/python/python-original.svg");
167
171
  margin-block: auto;
168
172
  }
169
173
 
170
174
  :global(.code__tab--python) {
171
175
  color: var(--ifm-color-success);
172
- padding-left: 2rem;
173
- padding-right: 2rem;
176
+ padding-left: 1.4rem;
177
+ padding-right: 1.4rem;
174
178
  }
175
179
 
176
180
  :global(.code__tab--python.tabs__item--active) {
@@ -185,16 +189,16 @@
185
189
 
186
190
  :global(.code__tab--go::after) {
187
191
  content: "";
188
- width: 32px;
189
- height: 32px;
190
- background: url(./icons/go-original-wordmark.svg);
192
+ width: 28px;
193
+ height: 28px;
194
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/go/go-original-wordmark.svg");
191
195
  margin-block: auto;
192
196
  }
193
197
 
194
198
  :global(.code__tab--go) {
195
199
  color: var(--ifm-color-info);
196
- padding-left: 2rem;
197
- padding-right: 2rem;
200
+ padding-left: 1.4rem;
201
+ padding-right: 1.4rem;
198
202
  }
199
203
 
200
204
  :global(.code__tab--go.tabs__item--active) {
@@ -209,16 +213,16 @@
209
213
 
210
214
  :global(.code__tab--javascript::after) {
211
215
  content: "";
212
- width: 32px;
213
- height: 32px;
214
- background: url(./icons/javascript-original.svg);
216
+ width: 28px;
217
+ height: 28px;
218
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/javascript/javascript-original.svg");
215
219
  margin-block: auto;
216
220
  }
217
221
 
218
222
  :global(.code__tab--javascript) {
219
223
  color: var(--ifm-color-warning);
220
- padding-left: 2rem;
221
- padding-right: 2rem;
224
+ padding-left: 1.4rem;
225
+ padding-right: 1.4rem;
222
226
  }
223
227
 
224
228
  :global(.code__tab--javascript.tabs__item--active) {
@@ -233,16 +237,16 @@
233
237
 
234
238
  :global(.code__tab--bash::after) {
235
239
  content: "";
236
- width: 32px;
237
- height: 32px;
238
- background: url(./icons/linux-original.svg);
240
+ width: 28px;
241
+ height: 28px;
242
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/linux/linux-original.svg");
239
243
  margin-block: auto;
240
244
  }
241
245
 
242
246
  :global(.code__tab--bash) {
243
247
  color: var(--ifm-color-danger);
244
- padding-left: 2rem;
245
- padding-right: 2rem;
248
+ padding-left: 1.4rem;
249
+ padding-right: 1.4rem;
246
250
  }
247
251
 
248
252
  :global(.code__tab--bash.tabs__item--active) {
@@ -254,3 +258,99 @@
254
258
  max-height: 500px;
255
259
  overflow: auto;
256
260
  }
261
+
262
+ :global(.code__tab--ruby::after) {
263
+ content: "";
264
+ width: 28px;
265
+ height: 28px;
266
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/ruby/ruby-plain.svg");
267
+ margin-block: auto;
268
+ }
269
+
270
+ :global(.code__tab--ruby) {
271
+ color: var(--ifm-color-danger);
272
+ padding-left: 1.4rem;
273
+ padding-right: 1.4rem;
274
+ }
275
+
276
+ :global(.code__tab--ruby.tabs__item--active) {
277
+ border-bottom-color: var(--ifm-color-danger);
278
+ background-color: var(--ifm-color-emphasis-100);
279
+ }
280
+
281
+ :global(.language-ruby) {
282
+ max-height: 500px;
283
+ overflow: auto;
284
+ }
285
+
286
+ :global(.code__tab--csharp::after) {
287
+ content: "";
288
+ width: 28px;
289
+ height: 28px;
290
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/csharp/csharp-original.svg");
291
+ margin-block: auto;
292
+ }
293
+
294
+ :global(.code__tab--csharp) {
295
+ color: var(--ifm-color-gray-500);
296
+ padding-left: 1.4rem;
297
+ padding-right: 1.4rem;
298
+ }
299
+
300
+ :global(.code__tab--csharp.tabs__item--active) {
301
+ border-bottom-color: var(--ifm-color-gray-500);
302
+ background-color: var(--ifm-color-emphasis-100);
303
+ }
304
+
305
+ :global(.language-csharp) {
306
+ max-height: 500px;
307
+ overflow: auto;
308
+ }
309
+
310
+ :global(.code__tab--nodejs::after) {
311
+ content: "";
312
+ width: 28px;
313
+ height: 28px;
314
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/nodejs/nodejs-original.svg");
315
+ margin-block: auto;
316
+ }
317
+
318
+ :global(.code__tab--nodejs) {
319
+ color: var(--ifm-color-success);
320
+ padding-left: 1.4rem;
321
+ padding-right: 1.4rem;
322
+ }
323
+
324
+ :global(.code__tab--nodejs.tabs__item--active) {
325
+ border-bottom-color: var(--ifm-color-success);
326
+ background-color: var(--ifm-color-emphasis-100);
327
+ }
328
+
329
+ :global(.language-nodejs) {
330
+ max-height: 500px;
331
+ overflow: auto;
332
+ }
333
+
334
+ :global(.code__tab--php::after) {
335
+ content: "";
336
+ width: 28px;
337
+ height: 28px;
338
+ background: url("https://raw.githubusercontent.com/devicons/devicon/master/icons/php/php-original.svg");
339
+ margin-block: auto;
340
+ }
341
+
342
+ :global(.code__tab--php) {
343
+ color: var(--ifm-color-gray-500);
344
+ padding-left: 1.4rem;
345
+ padding-right: 1.4rem;
346
+ }
347
+
348
+ :global(.code__tab--php.tabs__item--active) {
349
+ border-bottom-color: var(--ifm-color-gray-500);
350
+ background-color: var(--ifm-color-emphasis-100);
351
+ }
352
+
353
+ :global(.language-php) {
354
+ max-height: 500px;
355
+ overflow: auto;
356
+ }
@@ -11,11 +11,11 @@ import CodeBlock from "@theme/CodeBlock";
11
11
 
12
12
  import styles from "./styles.module.css";
13
13
 
14
- function ResponseSamples({ responseExample }) {
14
+ function ResponseSamples({ responseExample, language }) {
15
15
  return (
16
16
  <div className={styles.responseSamplesContainer}>
17
17
  <CodeBlock
18
- language="javascript"
18
+ language={language ? language : "json"}
19
19
  className={styles.responseSamplesCodeBlock}
20
20
  >
21
21
  {responseExample}
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
  import React from "react";
8
+ import format from "xml-formatter";
8
9
  import ContentType from "../ContentType";
9
10
  import FormSelect from "../FormSelect";
10
11
  import { useTypedDispatch, useTypedSelector } from "../hooks";
@@ -188,7 +189,15 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
188
189
 
189
190
  if (contentType === "application/xml") {
190
191
  if (jsonRequestBodyExample) {
191
- exampleBodyString = json2xml(jsonRequestBodyExample);
192
+ try {
193
+ exampleBodyString = format(json2xml(jsonRequestBodyExample, ""), {
194
+ indentation: " ",
195
+ lineSeparator: "\n",
196
+ collapseContent: true,
197
+ });
198
+ } catch {
199
+ exampleBodyString = json2xml(jsonRequestBodyExample);
200
+ }
192
201
  }
193
202
 
194
203
  language = "xml";
@@ -7,5 +7,11 @@
7
7
  }
8
8
 
9
9
  .code__tabs {
10
- justify-content: space-around;
10
+ display: table-row-group;
11
+ }
12
+
13
+ @media only screen and (min-width: 768px) and (max-width: 996px) {
14
+ .code__tabs {
15
+ justify-content: space-around;
16
+ }
11
17
  }
@@ -15,50 +15,76 @@ import buildPostmanRequest from "./../buildPostmanRequest";
15
15
  import styles from "./styles.module.css";
16
16
  export const languageSet = [
17
17
  {
18
- tabName: "cURL",
19
18
  highlight: "bash",
20
19
  language: "curl",
21
- codeLanguage: "bash",
22
- variant: "curl",
20
+ logoClass: "bash",
23
21
  options: {
24
22
  longFormat: false,
25
23
  followRedirect: true,
26
24
  trimRequestBody: true,
27
25
  },
26
+ variant: "cURL",
28
27
  },
29
28
  {
30
- tabName: "Python",
31
29
  highlight: "python",
32
30
  language: "python",
33
- codeLanguage: "python",
34
- variant: "requests",
31
+ logoClass: "python",
35
32
  options: {
36
33
  followRedirect: true,
37
34
  trimRequestBody: true,
38
35
  },
36
+ variant: "requests",
39
37
  },
40
38
  {
41
- tabName: "Go",
42
39
  highlight: "go",
43
40
  language: "go",
44
- codeLanguage: "go",
45
- variant: "native",
41
+ logoClass: "go",
46
42
  options: {
47
43
  followRedirect: true,
48
44
  trimRequestBody: true,
49
45
  },
46
+ variant: "native",
50
47
  },
51
48
  {
52
- tabName: "Node",
53
49
  highlight: "javascript",
54
50
  language: "nodejs",
55
- codeLanguage: "javascript",
56
- variant: "axios",
51
+ logoClass: "nodejs",
57
52
  options: {
58
53
  ES6_enabled: true,
59
54
  followRedirect: true,
60
55
  trimRequestBody: true,
61
56
  },
57
+ variant: "axios",
58
+ },
59
+ {
60
+ highlight: "ruby",
61
+ language: "ruby",
62
+ logoClass: "ruby",
63
+ options: {
64
+ followRedirect: true,
65
+ trimRequestBody: true,
66
+ },
67
+ variant: "Net::HTTP",
68
+ },
69
+ {
70
+ highlight: "csharp",
71
+ language: "csharp",
72
+ logoClass: "csharp",
73
+ options: {
74
+ followRedirect: true,
75
+ trimRequestBody: true,
76
+ },
77
+ variant: "RestSharp",
78
+ },
79
+ {
80
+ highlight: "php",
81
+ language: "php",
82
+ logoClass: "php",
83
+ options: {
84
+ followRedirect: true,
85
+ trimRequestBody: true,
86
+ },
87
+ variant: "cURL",
62
88
  },
63
89
  ];
64
90
 
@@ -95,9 +121,15 @@ function Curl({ postman, codeSamples }) {
95
121
  ];
96
122
  const defaultLang = languageSet.filter(
97
123
  (lang) =>
98
- lang.codeLanguage === localStorage.getItem("docusaurus.tab.code-samples")
124
+ lang.language === localStorage.getItem("docusaurus.tab.code-samples")
99
125
  );
100
- const [language, setLanguage] = useState(defaultLang[0] ?? langs[0]);
126
+ const [language, setLanguage] = useState(() => {
127
+ if (langs.length === 1) {
128
+ return langs[0];
129
+ }
130
+
131
+ return defaultLang[0] ?? langs[0];
132
+ });
101
133
  const [codeText, setCodeText] = useState("");
102
134
  useEffect(() => {
103
135
  if (language && !!language.options) {
@@ -127,6 +159,38 @@ function Curl({ postman, codeSamples }) {
127
159
  );
128
160
  } else if (language && !!language.source) {
129
161
  setCodeText(language.source);
162
+ } else if (language && !language.options) {
163
+ const langSource = languageSet.filter(
164
+ (lang) => lang.language === language.language
165
+ ); // Merges user-defined language with default languageSet
166
+ // This allows users to define only the minimal properties necessary in languageTabs
167
+ // User-defined properties should override languageSet properties
168
+
169
+ const mergedLanguage = { ...langSource[0], ...language };
170
+ const postmanRequest = buildPostmanRequest(postman, {
171
+ queryParams,
172
+ pathParams,
173
+ cookieParams,
174
+ contentType,
175
+ accept,
176
+ headerParams,
177
+ body,
178
+ server,
179
+ auth,
180
+ });
181
+ codegen.convert(
182
+ mergedLanguage.language,
183
+ mergedLanguage.variant,
184
+ postmanRequest,
185
+ mergedLanguage.options,
186
+ (error, snippet) => {
187
+ if (error) {
188
+ return;
189
+ }
190
+
191
+ setCodeText(snippet);
192
+ }
193
+ );
130
194
  } else {
131
195
  setCodeText("");
132
196
  }
@@ -156,12 +220,16 @@ function Curl({ postman, codeSamples }) {
156
220
  <CodeTab
157
221
  value={lang.language}
158
222
  label={""}
159
- key={lang.tabName || lang.label}
223
+ key={
224
+ lang.variant
225
+ ? `${lang.language}-${lang.variant}`
226
+ : lang.language
227
+ }
160
228
  attributes={{
161
- className: `code__tab--${lang.codeLanguage}`,
229
+ className: `code__tab--${lang.logoClass}`,
162
230
  }}
163
231
  >
164
- <CodeBlock language={lang.codeLanguage}>{codeText}</CodeBlock>
232
+ <CodeBlock language={lang.highlight}>{codeText}</CodeBlock>
165
233
  </CodeTab>
166
234
  );
167
235
  })}