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

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
+ });
@@ -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-698",
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-698",
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": "4fd97549c952b6b527c1485255d9c2f75b838853"
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 {
@@ -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>