docusaurus-theme-openapi-docs 1.1.2 → 1.1.5

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 (41) hide show
  1. package/lib/markdown/schema.js +85 -20
  2. package/lib/theme/ApiDemoPanel/Body/index.js +1 -1
  3. package/lib/theme/ApiItem/Layout/styles.module.css +16 -0
  4. package/lib/theme/ApiLogo/index.js +29 -0
  5. package/lib/theme/DiscriminatorTabs/index.js +263 -0
  6. package/lib/theme/DiscriminatorTabs/styles.module.css +111 -0
  7. package/lib/theme/MimeTabs/index.js +260 -0
  8. package/lib/theme/MimeTabs/styles.module.css +125 -0
  9. package/lib/theme/ParamsItem/index.js +10 -0
  10. package/lib/theme/ResponseSamples/index.js +27 -0
  11. package/lib/theme/ResponseSamples/styles.module.css +7 -0
  12. package/lib/theme/SchemaItem/index.js +15 -3
  13. package/lib/theme/SchemaTabs/styles.module.css +0 -8
  14. package/lib-next/markdown/schema.js +88 -22
  15. package/lib-next/theme/ApiDemoPanel/Body/index.js +1 -1
  16. package/lib-next/theme/ApiItem/Layout/styles.module.css +16 -0
  17. package/lib-next/theme/ApiLogo/index.js +21 -0
  18. package/lib-next/theme/DiscriminatorTabs/index.js +263 -0
  19. package/lib-next/theme/DiscriminatorTabs/styles.module.css +111 -0
  20. package/lib-next/theme/MimeTabs/index.js +260 -0
  21. package/lib-next/theme/MimeTabs/styles.module.css +125 -0
  22. package/lib-next/theme/ParamsItem/index.js +10 -0
  23. package/lib-next/theme/ResponseSamples/index.js +27 -0
  24. package/lib-next/theme/ResponseSamples/styles.module.css +7 -0
  25. package/lib-next/theme/SchemaItem/index.js +15 -3
  26. package/lib-next/theme/SchemaTabs/styles.module.css +0 -8
  27. package/package.json +6 -6
  28. package/src/markdown/schema.ts +86 -20
  29. package/src/markdown/utils.ts +2 -2
  30. package/src/theme/ApiDemoPanel/Body/index.tsx +1 -1
  31. package/src/theme/ApiItem/Layout/styles.module.css +16 -0
  32. package/src/theme/ApiLogo/index.tsx +25 -0
  33. package/src/theme/DiscriminatorTabs/index.js +263 -0
  34. package/src/theme/DiscriminatorTabs/styles.module.css +111 -0
  35. package/src/theme/MimeTabs/index.js +260 -0
  36. package/src/theme/MimeTabs/styles.module.css +125 -0
  37. package/src/theme/ParamsItem/index.js +10 -0
  38. package/src/theme/ResponseSamples/index.js +27 -0
  39. package/src/theme/ResponseSamples/styles.module.css +7 -0
  40. package/src/theme/SchemaItem/index.js +15 -3
  41. package/src/theme/SchemaTabs/styles.module.css +0 -8
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ .tabItem {
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ height: 2rem;
13
+ margin-top: 0 !important;
14
+ margin-right: 0.5rem;
15
+ /* border: 1px solid var(--openapi-code-dim-dark);
16
+ border-radius: 0; */
17
+ font-weight: var(--ifm-font-weight-normal);
18
+ /* color: var(--openapi-code-dim-dark); */
19
+ font-size: 12px;
20
+ }
21
+
22
+ .tabItem:active {
23
+ background-color: var(--ifm-color-emphasis-100);
24
+ }
25
+
26
+ /* .tabItem:hover {
27
+ color: var(--ifm-color-emphasis-500) !important;
28
+ } */
29
+
30
+ .tabItem:last-child {
31
+ margin-right: 0 !important;
32
+ }
33
+
34
+ /* Open API Response Code Tabs */
35
+ .mimeTabsTopSection {
36
+ display: flex;
37
+ justify-content: space-between;
38
+ align-items: center;
39
+ }
40
+
41
+ .mimeTabsContainer {
42
+ display: flex;
43
+ align-items: center;
44
+ max-width: 390px;
45
+ /* padding-left: 1rem; */
46
+ overflow: hidden;
47
+ }
48
+
49
+ .mimeTabsListContainer {
50
+ overflow-y: hidden;
51
+ overflow-x: scroll;
52
+ scroll-behavior: smooth;
53
+ }
54
+
55
+ .mimeTabsListContainer::-webkit-scrollbar {
56
+ display: none;
57
+ }
58
+
59
+ /* Response Code Tabs - Colored Dots */
60
+ .mimeTabDot {
61
+ width: 12.5px;
62
+ height: 12.5px;
63
+ margin-right: 5px;
64
+ border-radius: 50%;
65
+ }
66
+
67
+ .mimeTabDotSuccess {
68
+ background-color: var(--ifm-color-success);
69
+ }
70
+
71
+ .mimeTabDotDanger {
72
+ background-color: var(--ifm-color-danger);
73
+ }
74
+
75
+ .mimeTabDotInfo {
76
+ background-color: var(--ifm-color-info);
77
+ }
78
+
79
+ .mimeTabActive {
80
+ border-bottom-color: var(--ifm-tabs-color-active-border);
81
+ border-bottom-left-radius: 0;
82
+ border-bottom-right-radius: 0;
83
+ color: var(--ifm-tabs-color-active);
84
+ background-color: var(--ifm-color-emphasis-100);
85
+ }
86
+
87
+ .mimeSchemaContainer {
88
+ max-width: 600px;
89
+ }
90
+
91
+ /* Tab Arrows */
92
+ .tabArrow {
93
+ content: "";
94
+ height: 1.25rem;
95
+ width: 1.25rem;
96
+ border: none;
97
+ min-width: 1.25rem;
98
+ background: var(--ifm-menu-link-sublist-icon) 50% / 2rem 2rem;
99
+ filter: var(--ifm-menu-link-sublist-icon-filter);
100
+ }
101
+
102
+ .tabArrow:hover {
103
+ cursor: pointer;
104
+ }
105
+
106
+ .tabArrowLeft {
107
+ transform: rotate(270deg);
108
+ }
109
+
110
+ .tabArrowRight {
111
+ transform: rotate(90deg);
112
+ }
113
+
114
+ @media screen and (max-width: 500px) {
115
+ .mimeTabsTopSection {
116
+ flex-direction: column;
117
+ align-items: flex-start;
118
+ }
119
+
120
+ .mimeTabsContainer {
121
+ width: 100%;
122
+ margin-top: var(--ifm-spacing-vertical);
123
+ padding: 0;
124
+ }
125
+ }
@@ -37,6 +37,15 @@ function ParamsItem({
37
37
  </div>
38
38
  ));
39
39
 
40
+ const renderDefaultValue = guard(
41
+ schema.items ? schema.items.default : schema.default,
42
+ (value) => (
43
+ <div>
44
+ <ReactMarkdown children={`**Default value:** \`${value}\``} />
45
+ </div>
46
+ )
47
+ );
48
+
40
49
  const renderExample = guard(example, (example) => (
41
50
  <div>{`Example: ${example}`}</div>
42
51
  ));
@@ -58,6 +67,7 @@ function ParamsItem({
58
67
  {renderSchemaName}
59
68
  {renderSchemaRequired}
60
69
  {renderSchema}
70
+ {renderDefaultValue}
61
71
  {renderDescription}
62
72
  {renderExample}
63
73
  {renderExamples}
@@ -0,0 +1,27 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import React from "react";
9
+
10
+ import CodeBlock from "@theme/CodeBlock";
11
+
12
+ import styles from "./styles.module.css";
13
+
14
+ function ResponseSamples({ responseExample }) {
15
+ return (
16
+ <div className={styles.responseSamplesContainer}>
17
+ <CodeBlock
18
+ language="javascript"
19
+ className={styles.responseSamplesCodeBlock}
20
+ >
21
+ {responseExample}
22
+ </CodeBlock>
23
+ </div>
24
+ );
25
+ }
26
+
27
+ export default ResponseSamples;
@@ -0,0 +1,7 @@
1
+ .responseSamplesContainer {
2
+ margin-top: 2rem;
3
+ }
4
+
5
+ .responseSamplesTabItem {
6
+ width: 100%;
7
+ }
@@ -21,10 +21,12 @@ function SchemaItem({
21
21
  required,
22
22
  schemaDescription,
23
23
  schemaName,
24
+ defaultValue,
24
25
  }) {
25
- const renderRequired = guard(required, () => (
26
- <strong className={styles.required}> required</strong>
27
- ));
26
+ const renderRequired = guard(
27
+ Array.isArray(required) ? required.includes(name) : required,
28
+ () => <strong className={styles.required}> required</strong>
29
+ );
28
30
 
29
31
  const renderSchemaDescription = guard(schemaDescription, (description) => (
30
32
  <div className={styles.schemaDescription}>
@@ -38,12 +40,22 @@ function SchemaItem({
38
40
  </div>
39
41
  ));
40
42
 
43
+ const renderDefaultValue = guard(
44
+ typeof defaultValue === "boolean" ? defaultValue.toString() : defaultValue,
45
+ (value) => (
46
+ <div className={styles.schemaQualifierMessage}>
47
+ <ReactMarkdown children={`**Default value:** \`${value}\``} />
48
+ </div>
49
+ )
50
+ );
51
+
41
52
  const schemaContent = (
42
53
  <div>
43
54
  <strong>{name}</strong>
44
55
  <span className={styles.schemaName}> {schemaName}</span>
45
56
  {renderRequired}
46
57
  {renderQualifierMessage}
58
+ {renderDefaultValue}
47
59
  {renderSchemaDescription}
48
60
  </div>
49
61
  );
@@ -38,14 +38,6 @@
38
38
  display: none;
39
39
  }
40
40
 
41
- .schemaTabsContainer {
42
- display: flex;
43
- align-items: center;
44
- max-width: 390px;
45
- padding-left: 3px;
46
- overflow: hidden;
47
- }
48
-
49
41
  .schemaTabsListContainer {
50
42
  padding: 0 0.25rem;
51
43
  overflow-y: hidden;
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.2",
4
+ "version": "1.1.5",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -31,8 +31,8 @@
31
31
  "format:lib-next": "prettier --config ../../.prettierrc.json --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
32
32
  },
33
33
  "devDependencies": {
34
- "@docusaurus/module-type-aliases": "2.0.0-rc.1",
35
- "@docusaurus/types": "2.0.0-rc.1",
34
+ "@docusaurus/module-type-aliases": "2.0.1",
35
+ "@docusaurus/types": "2.0.1",
36
36
  "@types/concurrently": "^6.3.0",
37
37
  "@types/crypto-js": "^4.1.0",
38
38
  "@types/fs-extra": "^9.0.13",
@@ -42,7 +42,7 @@
42
42
  "concurrently": "^5.2.0"
43
43
  },
44
44
  "dependencies": {
45
- "@docusaurus/theme-common": "2.0.0-rc.1",
45
+ "@docusaurus/theme-common": "2.0.1",
46
46
  "@mdx-js/react": "^1.6.21",
47
47
  "@paloaltonetworks/postman-code-generators": "1.1.5-hotfix.5",
48
48
  "@paloaltonetworks/postman-collection": "^4.1.0",
@@ -50,7 +50,7 @@
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.2",
53
+ "docusaurus-plugin-openapi-docs": "^1.1.5",
54
54
  "immer": "^9.0.7",
55
55
  "lodash": "^4.17.20",
56
56
  "process": "^0.11.10",
@@ -68,5 +68,5 @@
68
68
  "engines": {
69
69
  "node": ">=14"
70
70
  },
71
- "gitHead": "0c66efff6ff553647265abdc27d4ca847c6d8045"
71
+ "gitHead": "21d33582a9fcac2ddd23443497af910982b36dae"
72
72
  }
@@ -8,22 +8,36 @@
8
8
  import { SchemaObject } from "../types";
9
9
 
10
10
  function prettyName(schema: SchemaObject, circular?: boolean) {
11
- if (schema.$ref) {
12
- return schema.$ref.replace("#/components/schemas/", "") + circular
13
- ? " (circular)"
14
- : "";
15
- }
16
-
17
11
  if (schema.format) {
18
12
  return schema.format;
19
13
  }
20
14
 
21
15
  if (schema.allOf) {
16
+ if (typeof schema.allOf[0] === "string") {
17
+ // @ts-ignore
18
+ if (schema.allOf[0].includes("circular")) {
19
+ return schema.allOf[0];
20
+ }
21
+ }
22
+ return "object";
23
+ }
24
+
25
+ if (schema.oneOf) {
26
+ return "object";
27
+ }
28
+
29
+ if (schema.anyOf) {
22
30
  return "object";
23
31
  }
24
32
 
25
33
  if (schema.type === "object") {
26
34
  return schema.xml?.name ?? schema.type;
35
+ // return schema.type;
36
+ }
37
+
38
+ if (schema.type === "array") {
39
+ return schema.xml?.name ?? schema.type;
40
+ // return schema.type;
27
41
  }
28
42
 
29
43
  return schema.title ?? schema.type;
@@ -42,8 +56,6 @@ export function getSchemaName(
42
56
 
43
57
  export function getQualifierMessage(schema?: SchemaObject): string | undefined {
44
58
  // TODO:
45
- // - maxItems
46
- // - minItems
47
59
  // - uniqueItems
48
60
  // - maxProperties
49
61
  // - minProperties
@@ -52,7 +64,11 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
52
64
  return undefined;
53
65
  }
54
66
 
55
- if (schema.items) {
67
+ if (
68
+ schema.items &&
69
+ schema.minItems === undefined &&
70
+ schema.maxItems === undefined
71
+ ) {
56
72
  return getQualifierMessage(schema.items);
57
73
  }
58
74
 
@@ -60,15 +76,38 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
60
76
 
61
77
  let qualifierGroups = [];
62
78
 
79
+ if (schema.items && schema.items.enum) {
80
+ if (schema.items.enum) {
81
+ qualifierGroups.push(
82
+ `[${schema.items.enum.map((e) => `\`${e}\``).join(", ")}]`
83
+ );
84
+ }
85
+ }
86
+
63
87
  if (schema.minLength || schema.maxLength) {
64
88
  let lengthQualifier = "";
65
- if (schema.minLength) {
66
- lengthQualifier += `${schema.minLength} ≤ `;
89
+ let minLength;
90
+ let maxLength;
91
+ if (schema.minLength && schema.minLength > 1) {
92
+ minLength = `\`>= ${schema.minLength} characters\``;
93
+ }
94
+ if (schema.minLength && schema.minLength === 1) {
95
+ minLength = `\`non-empty\``;
67
96
  }
68
- lengthQualifier += "length";
69
97
  if (schema.maxLength) {
70
- lengthQualifier += ` ${schema.maxLength}`;
98
+ maxLength = `\`<= ${schema.maxLength} characters\``;
99
+ }
100
+
101
+ if (minLength && !maxLength) {
102
+ lengthQualifier += minLength;
103
+ }
104
+ if (maxLength && !minLength) {
105
+ lengthQualifier += maxLength;
106
+ }
107
+ if (minLength && maxLength) {
108
+ lengthQualifier += `${minLength} and ${maxLength}`;
71
109
  }
110
+
72
111
  qualifierGroups.push(lengthQualifier);
73
112
  }
74
113
 
@@ -79,21 +118,33 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
79
118
  typeof schema.exclusiveMaximum === "number"
80
119
  ) {
81
120
  let minmaxQualifier = "";
121
+ let minimum;
122
+ let maximum;
82
123
  if (typeof schema.exclusiveMinimum === "number") {
83
- minmaxQualifier += `${schema.exclusiveMinimum} < `;
124
+ minimum = `\`> ${schema.exclusiveMinimum}\``;
84
125
  } else if (schema.minimum && !schema.exclusiveMinimum) {
85
- minmaxQualifier += `${schema.minimum} ≤ `;
126
+ minimum = `\`>= ${schema.minimum}\``;
86
127
  } else if (schema.minimum && schema.exclusiveMinimum === true) {
87
- minmaxQualifier += `${schema.minimum} < `;
128
+ minimum = `\`> ${schema.minimum}\``;
88
129
  }
89
- minmaxQualifier += "value";
90
130
  if (typeof schema.exclusiveMaximum === "number") {
91
- minmaxQualifier += ` < ${schema.exclusiveMaximum}`;
131
+ maximum = `\`< ${schema.exclusiveMaximum}\``;
92
132
  } else if (schema.maximum && !schema.exclusiveMaximum) {
93
- minmaxQualifier += ` ${schema.maximum}`;
133
+ maximum = `\`<= ${schema.maximum}\``;
94
134
  } else if (schema.maximum && schema.exclusiveMaximum === true) {
95
- minmaxQualifier += ` < ${schema.maximum}`;
135
+ maximum = `\`< ${schema.maximum}\``;
136
+ }
137
+
138
+ if (minimum && !maximum) {
139
+ minmaxQualifier += minimum;
140
+ }
141
+ if (maximum && !minimum) {
142
+ minmaxQualifier += maximum;
96
143
  }
144
+ if (minimum && maximum) {
145
+ minmaxQualifier += `${minimum} and ${maximum}`;
146
+ }
147
+
97
148
  qualifierGroups.push(minmaxQualifier);
98
149
  }
99
150
 
@@ -103,10 +154,25 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
103
154
  );
104
155
  }
105
156
 
157
+ // Check if discriminator mapping
158
+ const discriminator = schema as any;
159
+ if (discriminator.mapping) {
160
+ const values = Object.keys(discriminator.mapping);
161
+ qualifierGroups.push(`[${values.map((e) => `\`${e}\``).join(", ")}]`);
162
+ }
163
+
106
164
  if (schema.enum) {
107
165
  qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
108
166
  }
109
167
 
168
+ if (schema.minItems) {
169
+ qualifierGroups.push(`\`>= ${schema.minItems}\``);
170
+ }
171
+
172
+ if (schema.maxItems) {
173
+ qualifierGroups.push(`\`<= ${schema.maxItems}\``);
174
+ }
175
+
110
176
  if (qualifierGroups.length === 0) {
111
177
  return undefined;
112
178
  }
@@ -21,11 +21,11 @@ export function create(tag: string, props: Props): string {
21
21
  }
22
22
 
23
23
  export function guard<T>(
24
- value: T | undefined,
24
+ value: T | undefined | string,
25
25
  cb: (value: T) => Children
26
26
  ): string {
27
27
  if (value) {
28
- const children = cb(value);
28
+ const children = cb(value as T);
29
29
  return render(children);
30
30
  }
31
31
  return "";
@@ -188,7 +188,7 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
188
188
  let language = "plaintext";
189
189
  let exampleBodyString = ""; //"body content";
190
190
 
191
- if (contentType === "application/json") {
191
+ if (contentType === "application/json" || contentType.endsWith("+json")) {
192
192
  if (jsonRequestBodyExample) {
193
193
  exampleBodyString = JSON.stringify(jsonRequestBodyExample, null, 2);
194
194
  }
@@ -126,6 +126,18 @@
126
126
  border-left: thin solid var(--ifm-color-gray-500) !important;
127
127
  }
128
128
 
129
+ :global(.discriminatorItem) {
130
+ list-style: none;
131
+ position: relative;
132
+ margin: 0 !important;
133
+ padding: 5px 0 5px 0 !important;
134
+ border-left: thin solid var(--ifm-color-gray-500) !important;
135
+ }
136
+
137
+ :global(.discriminatorTabsContainer) {
138
+ padding-left: 0 !important;
139
+ }
140
+
129
141
  :global(.schemaItem:hover) {
130
142
  background-color: var(--ifm-menu-color-background-active);
131
143
  }
@@ -163,6 +175,7 @@
163
175
 
164
176
  :global(.code__tab--python.tabs__item--active) {
165
177
  border-bottom-color: var(--ifm-color-success);
178
+ background-color: var(--ifm-color-emphasis-100);
166
179
  }
167
180
 
168
181
  :global(.language-python) {
@@ -186,6 +199,7 @@
186
199
 
187
200
  :global(.code__tab--go.tabs__item--active) {
188
201
  border-bottom-color: var(--ifm-color-info);
202
+ background-color: var(--ifm-color-emphasis-100);
189
203
  }
190
204
 
191
205
  :global(.language-go) {
@@ -209,6 +223,7 @@
209
223
 
210
224
  :global(.code__tab--javascript.tabs__item--active) {
211
225
  border-bottom-color: var(--ifm-color-warning);
226
+ background-color: var(--ifm-color-emphasis-100);
212
227
  }
213
228
 
214
229
  :global(.language-javascript) {
@@ -232,6 +247,7 @@
232
247
 
233
248
  :global(.code__tab--bash.tabs__item--active) {
234
249
  border-bottom-color: var(--ifm-color-danger);
250
+ background-color: var(--ifm-color-emphasis-100);
235
251
  }
236
252
 
237
253
  :global(.language-bash) {
@@ -0,0 +1,25 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import React from "react";
9
+
10
+ import { useColorMode } from "@docusaurus/theme-common";
11
+
12
+ export default function ApiLogo(props: any): JSX.Element {
13
+ const { colorMode } = useColorMode();
14
+ const { logo, darkLogo } = props;
15
+
16
+ return logo ? (
17
+ <img
18
+ alt={colorMode === "dark" && darkLogo ? darkLogo.altText : logo.altText}
19
+ src={colorMode === "dark" && darkLogo ? darkLogo.url : logo.url}
20
+ width="250px"
21
+ />
22
+ ) : (
23
+ <div />
24
+ );
25
+ }