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}
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": "1.1.7",
4
+ "version": "1.1.10",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -44,13 +44,13 @@
44
44
  "dependencies": {
45
45
  "@docusaurus/theme-common": "2.0.1",
46
46
  "@mdx-js/react": "^1.6.21",
47
- "@paloaltonetworks/postman-code-generators": "1.1.5-hotfix.5",
47
+ "@paloaltonetworks/postman-code-generators": "^1.1.9",
48
48
  "@paloaltonetworks/postman-collection": "^4.1.0",
49
49
  "@reduxjs/toolkit": "^1.7.1",
50
50
  "buffer": "^6.0.3",
51
51
  "clsx": "^1.1.1",
52
52
  "crypto-js": "^4.1.1",
53
- "docusaurus-plugin-openapi-docs": "^1.1.6",
53
+ "docusaurus-plugin-openapi-docs": "^1.1.9",
54
54
  "immer": "^9.0.7",
55
55
  "lodash": "^4.17.20",
56
56
  "process": "^0.11.10",
@@ -59,7 +59,8 @@
59
59
  "react-markdown": "^8.0.1",
60
60
  "react-redux": "^7.2.0",
61
61
  "redux-devtools-extension": "^2.13.8",
62
- "webpack": "^5.61.0"
62
+ "webpack": "^5.61.0",
63
+ "xml-formatter": "^2.6.1"
63
64
  },
64
65
  "peerDependencies": {
65
66
  "react": "^16.8.4 || ^17.0.0",
@@ -68,5 +69,5 @@
68
69
  "engines": {
69
70
  "node": ">=14"
70
71
  },
71
- "gitHead": "604cd3723c770fd306318d594e8fb4e68c39724c"
72
+ "gitHead": "507eaaaf45e1fff8cb95bfdcd097a4fa4ba1ea05"
72
73
  }
@@ -8,6 +8,7 @@
8
8
  import React from "react";
9
9
 
10
10
  import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
11
+ import format from "xml-formatter";
11
12
 
12
13
  import ContentType from "../ContentType";
13
14
  import FormSelect from "../FormSelect";
@@ -197,7 +198,15 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
197
198
 
198
199
  if (contentType === "application/xml") {
199
200
  if (jsonRequestBodyExample) {
200
- exampleBodyString = json2xml(jsonRequestBodyExample);
201
+ try {
202
+ exampleBodyString = format(json2xml(jsonRequestBodyExample, ""), {
203
+ indentation: " ",
204
+ lineSeparator: "\n",
205
+ collapseContent: true,
206
+ });
207
+ } catch {
208
+ exampleBodyString = json2xml(jsonRequestBodyExample);
209
+ }
201
210
  }
202
211
  language = "xml";
203
212
  }
@@ -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
  }
@@ -19,61 +19,86 @@ import buildPostmanRequest from "./../buildPostmanRequest";
19
19
  import styles from "./styles.module.css";
20
20
 
21
21
  interface Language {
22
- tabName: string;
23
- highlight: string;
22
+ highlight?: string;
24
23
  language: string;
25
- codeLanguage?: string;
26
- variant: string;
27
- options: { [key: string]: boolean };
24
+ logoClass?: string;
25
+ variant?: string;
26
+ options?: { [key: string]: boolean };
28
27
  source?: string;
29
28
  }
30
29
 
31
30
  export const languageSet: Language[] = [
32
31
  {
33
- tabName: "cURL",
34
32
  highlight: "bash",
35
33
  language: "curl",
36
- codeLanguage: "bash",
37
- variant: "curl",
34
+ logoClass: "bash",
38
35
  options: {
39
36
  longFormat: false,
40
37
  followRedirect: true,
41
38
  trimRequestBody: true,
42
39
  },
40
+ variant: "cURL",
43
41
  },
44
42
  {
45
- tabName: "Python",
46
43
  highlight: "python",
47
44
  language: "python",
48
- codeLanguage: "python",
49
- variant: "requests",
45
+ logoClass: "python",
50
46
  options: {
51
47
  followRedirect: true,
52
48
  trimRequestBody: true,
53
49
  },
50
+ variant: "requests",
54
51
  },
55
52
  {
56
- tabName: "Go",
57
53
  highlight: "go",
58
54
  language: "go",
59
- codeLanguage: "go",
60
- variant: "native",
55
+ logoClass: "go",
61
56
  options: {
62
57
  followRedirect: true,
63
58
  trimRequestBody: true,
64
59
  },
60
+ variant: "native",
65
61
  },
66
62
  {
67
- tabName: "Node",
68
63
  highlight: "javascript",
69
64
  language: "nodejs",
70
- codeLanguage: "javascript",
71
- variant: "axios",
65
+ logoClass: "nodejs",
72
66
  options: {
73
67
  ES6_enabled: true,
74
68
  followRedirect: true,
75
69
  trimRequestBody: true,
76
70
  },
71
+ variant: "axios",
72
+ },
73
+ {
74
+ highlight: "ruby",
75
+ language: "ruby",
76
+ logoClass: "ruby",
77
+ options: {
78
+ followRedirect: true,
79
+ trimRequestBody: true,
80
+ },
81
+ variant: "Net::HTTP",
82
+ },
83
+ {
84
+ highlight: "csharp",
85
+ language: "csharp",
86
+ logoClass: "csharp",
87
+ options: {
88
+ followRedirect: true,
89
+ trimRequestBody: true,
90
+ },
91
+ variant: "RestSharp",
92
+ },
93
+ {
94
+ highlight: "php",
95
+ language: "php",
96
+ logoClass: "php",
97
+ options: {
98
+ followRedirect: true,
99
+ trimRequestBody: true,
100
+ },
101
+ variant: "cURL",
77
102
  },
78
103
  ];
79
104
 
@@ -120,10 +145,15 @@ function Curl({ postman, codeSamples }: Props) {
120
145
 
121
146
  const defaultLang: Language[] = languageSet.filter(
122
147
  (lang) =>
123
- lang.codeLanguage === localStorage.getItem("docusaurus.tab.code-samples")
148
+ lang.language === localStorage.getItem("docusaurus.tab.code-samples")
124
149
  );
125
150
 
126
- const [language, setLanguage] = useState(defaultLang[0] ?? langs[0]);
151
+ const [language, setLanguage] = useState(() => {
152
+ if (langs.length === 1) {
153
+ return langs[0];
154
+ }
155
+ return defaultLang[0] ?? langs[0];
156
+ });
127
157
 
128
158
  const [codeText, setCodeText] = useState("");
129
159
 
@@ -155,6 +185,39 @@ function Curl({ postman, codeSamples }: Props) {
155
185
  );
156
186
  } else if (language && !!language.source) {
157
187
  setCodeText(language.source);
188
+ } else if (language && !language.options) {
189
+ const langSource = languageSet.filter(
190
+ (lang) => lang.language === language.language
191
+ );
192
+
193
+ // Merges user-defined language with default languageSet
194
+ // This allows users to define only the minimal properties necessary in languageTabs
195
+ // User-defined properties should override languageSet properties
196
+ const mergedLanguage = { ...langSource[0], ...language };
197
+ const postmanRequest = buildPostmanRequest(postman, {
198
+ queryParams,
199
+ pathParams,
200
+ cookieParams,
201
+ contentType,
202
+ accept,
203
+ headerParams,
204
+ body,
205
+ server,
206
+ auth,
207
+ });
208
+
209
+ codegen.convert(
210
+ mergedLanguage.language,
211
+ mergedLanguage.variant,
212
+ postmanRequest,
213
+ mergedLanguage.options,
214
+ (error: any, snippet: string) => {
215
+ if (error) {
216
+ return;
217
+ }
218
+ setCodeText(snippet);
219
+ }
220
+ );
158
221
  } else {
159
222
  setCodeText("");
160
223
  }
@@ -184,10 +247,14 @@ function Curl({ postman, codeSamples }: Props) {
184
247
  <CodeTab
185
248
  value={lang.language}
186
249
  label={""}
187
- key={lang.tabName || lang.label}
188
- attributes={{ className: `code__tab--${lang.codeLanguage}` }}
250
+ key={
251
+ lang.variant
252
+ ? `${lang.language}-${lang.variant}`
253
+ : lang.language
254
+ }
255
+ attributes={{ className: `code__tab--${lang.logoClass}` }}
189
256
  >
190
- <CodeBlock language={lang.codeLanguage}>{codeText}</CodeBlock>
257
+ <CodeBlock language={lang.highlight}>{codeText}</CodeBlock>
191
258
  </CodeTab>
192
259
  );
193
260
  })}