docusaurus-theme-openapi-docs 0.0.0-697 → 0.0.0-699

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.
@@ -17,11 +17,11 @@ function create(tag, props) {
17
17
  }
18
18
  exports.create = create;
19
19
  function guard(value, cb) {
20
- if (!!value) {
21
- const children = cb(value);
22
- return render(children);
20
+ if (value === undefined || value === "") {
21
+ return "";
23
22
  }
24
- return "";
23
+ const children = cb(value);
24
+ return render(children);
25
25
  }
26
26
  exports.guard = guard;
27
27
  function render(children) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const utils_1 = require("./utils");
10
+ describe("guard", () => {
11
+ it("should guard empty strings", () => {
12
+ const actual = (0, utils_1.guard)("", (_) => {
13
+ throw new Error("Should not be called");
14
+ });
15
+ expect(actual).toBe("");
16
+ });
17
+ it("should guard undefined", () => {
18
+ const actual = (0, utils_1.guard)(undefined, (value) => {
19
+ throw new Error("Should not be called");
20
+ });
21
+ expect(actual).toBe("");
22
+ });
23
+ it("should not guard strings", () => {
24
+ const actual = (0, utils_1.guard)("hello", (value) => value);
25
+ expect(actual).toBe("hello");
26
+ });
27
+ it("should not guard numbers", () => {
28
+ const actual = (0, utils_1.guard)(1, (value) => `${value}`);
29
+ expect(actual).toBe("1");
30
+ });
31
+ it("should not guard numbers equals to 0", () => {
32
+ const actual = (0, utils_1.guard)(0, (value) => `${value}`);
33
+ expect(actual).toBe("0");
34
+ });
35
+ it("should not guard false booleans", () => {
36
+ const actual = (0, utils_1.guard)(false, (value) => `${value}`);
37
+ expect(actual).toBe("false");
38
+ });
39
+ it("should not guard true booleans", () => {
40
+ const actual = (0, utils_1.guard)(true, (value) => `${value}`);
41
+ expect(actual).toBe("true");
42
+ });
43
+ });
@@ -40,6 +40,7 @@ function ApiItem(props) {
40
40
  const { frontMatter } = MDXComponent;
41
41
  const { info_path: infoPath } = frontMatter;
42
42
  let { api } = frontMatter;
43
+ const { schema } = frontMatter;
43
44
  // decompress and parse
44
45
  if (api) {
45
46
  api = JSON.parse(
@@ -163,6 +164,29 @@ function ApiItem(props) {
163
164
  )
164
165
  )
165
166
  );
167
+ } else if (schema) {
168
+ return react_1.default.createElement(
169
+ DocProvider,
170
+ { content: props.content },
171
+ react_1.default.createElement(
172
+ theme_common_1.HtmlClassNameProvider,
173
+ { className: docHtmlClassName },
174
+ react_1.default.createElement(Metadata_1.default, null),
175
+ react_1.default.createElement(
176
+ Layout_1.default,
177
+ null,
178
+ react_1.default.createElement(
179
+ "div",
180
+ { className: (0, clsx_1.default)("row", "theme-api-markdown") },
181
+ react_1.default.createElement(
182
+ "div",
183
+ { className: "col col--12" },
184
+ react_1.default.createElement(MDXComponent, null)
185
+ )
186
+ )
187
+ )
188
+ )
189
+ );
166
190
  }
167
191
  // Non-API docs
168
192
  return react_1.default.createElement(
@@ -79,14 +79,11 @@ function SchemaItem({
79
79
  </div>
80
80
  ));
81
81
 
82
- const renderDefaultValue = guard(
83
- typeof defaultValue === "boolean" ? defaultValue.toString() : defaultValue,
84
- (value) => (
85
- <div className="">
86
- <ReactMarkdown children={`**Default value:** \`${value}\``} />
87
- </div>
88
- )
89
- );
82
+ const renderDefaultValue = guard(defaultValue, (value) => (
83
+ <div className="">
84
+ <ReactMarkdown children={`**Default value:** \`${value}\``} />
85
+ </div>
86
+ ));
90
87
 
91
88
  const schemaContent = (
92
89
  <div>
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": "0.0.0-697",
4
+ "version": "0.0.0-699",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -43,7 +43,7 @@
43
43
  "clsx": "^1.1.1",
44
44
  "copy-text-to-clipboard": "^3.1.0",
45
45
  "crypto-js": "^4.1.1",
46
- "docusaurus-plugin-openapi-docs": "0.0.0-697",
46
+ "docusaurus-plugin-openapi-docs": "0.0.0-699",
47
47
  "docusaurus-plugin-sass": "^0.2.3",
48
48
  "file-saver": "^2.0.5",
49
49
  "lodash": "^4.17.20",
@@ -68,5 +68,5 @@
68
68
  "engines": {
69
69
  "node": ">=14"
70
70
  },
71
- "gitHead": "a6bbe786231f3938c6333379a036c614afb27029"
71
+ "gitHead": "ef318267f54c34bedf50f0b309c9bb30fd665b53"
72
72
  }
@@ -0,0 +1,48 @@
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 { guard } from "./utils";
9
+
10
+ describe("guard", () => {
11
+ it("should guard empty strings", () => {
12
+ const actual = guard("", (_) => {
13
+ throw new Error("Should not be called");
14
+ });
15
+ expect(actual).toBe("");
16
+ });
17
+
18
+ it("should guard undefined", () => {
19
+ const actual = guard(undefined, (value) => {
20
+ throw new Error("Should not be called");
21
+ });
22
+ expect(actual).toBe("");
23
+ });
24
+
25
+ it("should not guard strings", () => {
26
+ const actual = guard("hello", (value) => value);
27
+ expect(actual).toBe("hello");
28
+ });
29
+
30
+ it("should not guard numbers", () => {
31
+ const actual = guard(1, (value) => `${value}`);
32
+ expect(actual).toBe("1");
33
+ });
34
+
35
+ it("should not guard numbers equals to 0", () => {
36
+ const actual = guard(0, (value) => `${value}`);
37
+ expect(actual).toBe("0");
38
+ });
39
+
40
+ it("should not guard false booleans", () => {
41
+ const actual = guard(false, (value) => `${value}`);
42
+ expect(actual).toBe("false");
43
+ });
44
+ it("should not guard true booleans", () => {
45
+ const actual = guard(true, (value) => `${value}`);
46
+ expect(actual).toBe("true");
47
+ });
48
+ });
@@ -24,11 +24,11 @@ export function guard<T>(
24
24
  value: T | undefined | string,
25
25
  cb: (value: T) => Children
26
26
  ): string {
27
- if (!!value) {
28
- const children = cb(value as T);
29
- return render(children);
27
+ if (value === undefined || value === "") {
28
+ return "";
30
29
  }
31
- return "";
30
+ const children = cb(value as T);
31
+ return render(children);
32
32
  }
33
33
 
34
34
  export function render(children: Children): string {
@@ -44,12 +44,17 @@ interface ApiFrontMatter extends DocFrontMatter {
44
44
  readonly api?: ApiItemType;
45
45
  }
46
46
 
47
+ interface SchemaFrontMatter extends DocFrontMatter {
48
+ readonly schema?: boolean;
49
+ }
50
+
47
51
  export default function ApiItem(props: Props): JSX.Element {
48
52
  const docHtmlClassName = `docs-doc-id-${props.content.metadata.unversionedId}`;
49
53
  const MDXComponent = props.content;
50
54
  const { frontMatter } = MDXComponent;
51
55
  const { info_path: infoPath } = frontMatter as DocFrontMatter;
52
56
  let { api } = frontMatter as ApiFrontMatter;
57
+ const { schema } = frontMatter as SchemaFrontMatter;
53
58
  // decompress and parse
54
59
  if (api) {
55
60
  api = JSON.parse(
@@ -159,6 +164,21 @@ export default function ApiItem(props: Props): JSX.Element {
159
164
  </HtmlClassNameProvider>
160
165
  </DocProvider>
161
166
  );
167
+ } else if (schema) {
168
+ return (
169
+ <DocProvider content={props.content}>
170
+ <HtmlClassNameProvider className={docHtmlClassName}>
171
+ <DocItemMetadata />
172
+ <DocItemLayout>
173
+ <div className={clsx("row", "theme-api-markdown")}>
174
+ <div className="col col--12">
175
+ <MDXComponent />
176
+ </div>
177
+ </div>
178
+ </DocItemLayout>
179
+ </HtmlClassNameProvider>
180
+ </DocProvider>
181
+ );
162
182
  }
163
183
 
164
184
  // Non-API docs
@@ -79,14 +79,11 @@ function SchemaItem({
79
79
  </div>
80
80
  ));
81
81
 
82
- const renderDefaultValue = guard(
83
- typeof defaultValue === "boolean" ? defaultValue.toString() : defaultValue,
84
- (value) => (
85
- <div className="">
86
- <ReactMarkdown children={`**Default value:** \`${value}\``} />
87
- </div>
88
- )
89
- );
82
+ const renderDefaultValue = guard(defaultValue, (value) => (
83
+ <div className="">
84
+ <ReactMarkdown children={`**Default value:** \`${value}\``} />
85
+ </div>
86
+ ));
90
87
 
91
88
  const schemaContent = (
92
89
  <div>