docusaurus-plugin-openapi-docs 4.7.1 → 5.0.0
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.
- package/README.md +11 -8
- package/lib/index.js +4 -4
- package/lib/markdown/createLicense.js +5 -1
- package/lib/markdown/createSchema.js +3 -34
- package/lib/markdown/schema.d.ts +0 -1
- package/lib/markdown/schema.js +0 -105
- package/lib/markdown/utils.js +3 -1
- package/lib/openapi/createSchemaExample.test.js +26 -0
- package/lib/openapi/openapi.js +17 -13
- package/lib/openapi/openapi.test.js +152 -0
- package/lib/openapi/types.d.ts +1 -0
- package/lib/openapi/utils/loadAndResolveSpec.js +5 -4
- package/lib/openapi/utils/utils/openapi.d.ts +0 -2
- package/lib/openapi/utils/utils/openapi.js +0 -82
- package/lib/sidebars/index.js +24 -8
- package/lib/sidebars/index.test.js +68 -0
- package/package.json +13 -13
- package/src/index.ts +4 -4
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +0 -100
- package/src/markdown/createLicense.ts +7 -1
- package/src/markdown/createSchema.ts +4 -43
- package/src/markdown/schema.ts +0 -126
- package/src/markdown/utils.ts +3 -1
- package/src/openapi/createSchemaExample.test.ts +32 -0
- package/src/openapi/openapi.test.ts +176 -0
- package/src/openapi/openapi.ts +31 -15
- package/src/openapi/types.ts +1 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +8 -6
- package/src/openapi/utils/utils/openapi.ts +0 -110
- package/src/sidebars/index.test.ts +94 -0
- package/src/sidebars/index.ts +28 -9
- package/lib/markdown/schema.test.js +0 -181
- package/src/markdown/schema.test.ts +0 -208
- /package/lib/{markdown/schema.test.d.ts → sidebars/index.test.d.ts} +0 -0
|
@@ -450,116 +450,6 @@ export function getDefinitionName(pointer?: string): string | undefined {
|
|
|
450
450
|
return name;
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
-
function humanizeMultipleOfConstraint(
|
|
454
|
-
multipleOf: number | undefined
|
|
455
|
-
): string | undefined {
|
|
456
|
-
if (multipleOf === undefined) {
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
const strigifiedMultipleOf = multipleOf.toString(10);
|
|
460
|
-
if (!/^0\.0*1$/.test(strigifiedMultipleOf)) {
|
|
461
|
-
return `multiple of ${strigifiedMultipleOf}`;
|
|
462
|
-
}
|
|
463
|
-
return `decimal places <= ${strigifiedMultipleOf.split(".")[1].length}`;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
function humanizeRangeConstraint(
|
|
467
|
-
description: string,
|
|
468
|
-
min: number | undefined,
|
|
469
|
-
max: number | undefined
|
|
470
|
-
): string | undefined {
|
|
471
|
-
let stringRange;
|
|
472
|
-
if (min !== undefined && max !== undefined) {
|
|
473
|
-
if (min === max) {
|
|
474
|
-
stringRange = `= ${min} ${description}`;
|
|
475
|
-
} else {
|
|
476
|
-
stringRange = `[ ${min} .. ${max} ] ${description}`;
|
|
477
|
-
}
|
|
478
|
-
} else if (max !== undefined) {
|
|
479
|
-
stringRange = `<= ${max} ${description}`;
|
|
480
|
-
} else if (min !== undefined) {
|
|
481
|
-
if (min === 1) {
|
|
482
|
-
stringRange = "non-empty";
|
|
483
|
-
} else {
|
|
484
|
-
stringRange = `>= ${min} ${description}`;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
return stringRange;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
export function humanizeNumberRange(schema: OpenAPISchema): string | undefined {
|
|
492
|
-
const minimum =
|
|
493
|
-
typeof schema.exclusiveMinimum === "number"
|
|
494
|
-
? Math.min(schema.exclusiveMinimum, schema.minimum ?? Infinity)
|
|
495
|
-
: schema.minimum;
|
|
496
|
-
const maximum =
|
|
497
|
-
typeof schema.exclusiveMaximum === "number"
|
|
498
|
-
? Math.max(schema.exclusiveMaximum, schema.maximum ?? -Infinity)
|
|
499
|
-
: schema.maximum;
|
|
500
|
-
const exclusiveMinimum =
|
|
501
|
-
typeof schema.exclusiveMinimum === "number" || schema.exclusiveMinimum;
|
|
502
|
-
const exclusiveMaximum =
|
|
503
|
-
typeof schema.exclusiveMaximum === "number" || schema.exclusiveMaximum;
|
|
504
|
-
|
|
505
|
-
if (minimum !== undefined && maximum !== undefined) {
|
|
506
|
-
return `${exclusiveMinimum ? "( " : "[ "}${minimum} .. ${maximum}${
|
|
507
|
-
exclusiveMaximum ? " )" : " ]"
|
|
508
|
-
}`;
|
|
509
|
-
} else if (maximum !== undefined) {
|
|
510
|
-
return `${exclusiveMaximum ? "< " : "<= "}${maximum}`;
|
|
511
|
-
} else if (minimum !== undefined) {
|
|
512
|
-
return `${exclusiveMinimum ? "> " : ">= "}${minimum}`;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
export function humanizeConstraints(schema: OpenAPISchema): string[] {
|
|
517
|
-
const res: string[] = [];
|
|
518
|
-
|
|
519
|
-
const stringRange = humanizeRangeConstraint(
|
|
520
|
-
"characters",
|
|
521
|
-
schema.minLength,
|
|
522
|
-
schema.maxLength
|
|
523
|
-
);
|
|
524
|
-
if (stringRange !== undefined) {
|
|
525
|
-
res.push(stringRange);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
const arrayRange = humanizeRangeConstraint(
|
|
529
|
-
"items",
|
|
530
|
-
schema.minItems,
|
|
531
|
-
schema.maxItems
|
|
532
|
-
);
|
|
533
|
-
if (arrayRange !== undefined) {
|
|
534
|
-
res.push(arrayRange);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
const propertiesRange = humanizeRangeConstraint(
|
|
538
|
-
"properties",
|
|
539
|
-
schema.minProperties,
|
|
540
|
-
schema.maxProperties
|
|
541
|
-
);
|
|
542
|
-
if (propertiesRange !== undefined) {
|
|
543
|
-
res.push(propertiesRange);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
const multipleOfConstraint = humanizeMultipleOfConstraint(schema.multipleOf);
|
|
547
|
-
if (multipleOfConstraint !== undefined) {
|
|
548
|
-
res.push(multipleOfConstraint);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
const numberRange = humanizeNumberRange(schema);
|
|
552
|
-
if (numberRange !== undefined) {
|
|
553
|
-
res.push(numberRange);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
if (schema.uniqueItems) {
|
|
557
|
-
res.push("unique");
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
return res;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
453
|
export function sortByRequired(fields: any[], order: string[] = []) {
|
|
564
454
|
const unrequiredFields: any[] = [];
|
|
565
455
|
const orderedFields: any[] = [];
|
|
@@ -0,0 +1,94 @@
|
|
|
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 type { TagGroupObject, TagObject } from "../openapi/types";
|
|
9
|
+
import type { ApiMetadata } from "../types";
|
|
10
|
+
import generateSidebarSlice from "./index";
|
|
11
|
+
|
|
12
|
+
describe("generateSidebarSlice", () => {
|
|
13
|
+
describe("tagGroup with overlapping tags", () => {
|
|
14
|
+
const mockApiItems: ApiMetadata[] = [
|
|
15
|
+
{
|
|
16
|
+
type: "api",
|
|
17
|
+
id: "get-books",
|
|
18
|
+
unversionedId: "get-books",
|
|
19
|
+
title: "Get Books",
|
|
20
|
+
description: "",
|
|
21
|
+
source: "",
|
|
22
|
+
sourceDirName: "",
|
|
23
|
+
permalink: "/get-books",
|
|
24
|
+
frontMatter: {},
|
|
25
|
+
api: {
|
|
26
|
+
method: "get",
|
|
27
|
+
path: "/books",
|
|
28
|
+
tags: ["Books", "Deprecated"],
|
|
29
|
+
jsonRequestBodyExample: "",
|
|
30
|
+
info: { title: "Test API", version: "1.0.0" },
|
|
31
|
+
},
|
|
32
|
+
} as ApiMetadata,
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const mockTags: TagObject[][] = [
|
|
36
|
+
[
|
|
37
|
+
{ name: "Books", description: "Book operations" },
|
|
38
|
+
{ name: "Deprecated", description: "Deprecated endpoints" },
|
|
39
|
+
],
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const mockTagGroups: TagGroupObject[] = [
|
|
43
|
+
{ name: "Library", tags: ["Books"] },
|
|
44
|
+
{ name: "Deprecation", tags: ["Deprecated"] },
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
function collectKeys(obj: unknown): string[] {
|
|
48
|
+
const keys: string[] = [];
|
|
49
|
+
JSON.stringify(obj, (k, v) => {
|
|
50
|
+
if (k === "key" && typeof v === "string") {
|
|
51
|
+
keys.push(v);
|
|
52
|
+
}
|
|
53
|
+
return v;
|
|
54
|
+
});
|
|
55
|
+
return keys;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
it("should generate unique keys for items appearing in multiple tagGroups", () => {
|
|
59
|
+
const result = generateSidebarSlice(
|
|
60
|
+
{ groupPathsBy: "tagGroup" },
|
|
61
|
+
{ outputDir: "docs/test", specPath: "" },
|
|
62
|
+
mockApiItems,
|
|
63
|
+
mockTags,
|
|
64
|
+
"",
|
|
65
|
+
mockTagGroups
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const keys = collectKeys(result);
|
|
69
|
+
|
|
70
|
+
expect(keys.length).toBeGreaterThan(0);
|
|
71
|
+
expect(new Set(keys).size).toBe(keys.length);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should include tagGroup name in keys to differentiate same items", () => {
|
|
75
|
+
const result = generateSidebarSlice(
|
|
76
|
+
{ groupPathsBy: "tagGroup" },
|
|
77
|
+
{ outputDir: "docs/test", specPath: "" },
|
|
78
|
+
mockApiItems,
|
|
79
|
+
mockTags,
|
|
80
|
+
"",
|
|
81
|
+
mockTagGroups
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const keys = collectKeys(result);
|
|
85
|
+
|
|
86
|
+
expect(keys.filter((k) => k.includes("library")).length).toBeGreaterThan(
|
|
87
|
+
0
|
|
88
|
+
);
|
|
89
|
+
expect(
|
|
90
|
+
keys.filter((k) => k.includes("deprecation")).length
|
|
91
|
+
).toBeGreaterThan(0);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
package/src/sidebars/index.ts
CHANGED
|
@@ -77,7 +77,8 @@ function groupByTags(
|
|
|
77
77
|
sidebarOptions: SidebarOptions,
|
|
78
78
|
options: APIOptions,
|
|
79
79
|
tags: TagObject[][],
|
|
80
|
-
docPath: string
|
|
80
|
+
docPath: string,
|
|
81
|
+
tagGroupKey?: string
|
|
81
82
|
): ProcessedSidebar {
|
|
82
83
|
let { outputDir, label, showSchemas } = options;
|
|
83
84
|
|
|
@@ -130,8 +131,8 @@ function groupByTags(
|
|
|
130
131
|
output: string,
|
|
131
132
|
doc: string | undefined
|
|
132
133
|
): string => {
|
|
133
|
-
if (doc && output.
|
|
134
|
-
return output.
|
|
134
|
+
if (doc && output.startsWith(doc + "/")) {
|
|
135
|
+
return output.substring((doc + "/").length);
|
|
135
136
|
}
|
|
136
137
|
const slashIndex = output.indexOf("/", 1);
|
|
137
138
|
return slashIndex === -1
|
|
@@ -152,9 +153,11 @@ function groupByTags(
|
|
|
152
153
|
if (infoItems.length === 1) {
|
|
153
154
|
const infoItem = infoItems[0];
|
|
154
155
|
const id = infoItem.id;
|
|
156
|
+
const docId = basePath === "" || undefined ? `${id}` : `${basePath}/${id}`;
|
|
155
157
|
rootIntroDoc = {
|
|
156
158
|
type: "doc" as const,
|
|
157
|
-
id:
|
|
159
|
+
id: docId,
|
|
160
|
+
...(tagGroupKey && { key: kebabCase(`${tagGroupKey}-${docId}`) }),
|
|
158
161
|
};
|
|
159
162
|
}
|
|
160
163
|
|
|
@@ -219,15 +222,28 @@ function groupByTags(
|
|
|
219
222
|
(item) => !!item.schema["x-tags"]?.includes(tag)
|
|
220
223
|
);
|
|
221
224
|
|
|
225
|
+
const categoryLabel = tagObject?.["x-displayName"] ?? tag;
|
|
226
|
+
const categoryKey = tagGroupKey
|
|
227
|
+
? kebabCase(`${tagGroupKey}-${categoryLabel}`)
|
|
228
|
+
: undefined;
|
|
229
|
+
|
|
222
230
|
return {
|
|
223
231
|
type: "category" as const,
|
|
224
|
-
label:
|
|
232
|
+
label: categoryLabel,
|
|
233
|
+
...(categoryKey && { key: categoryKey }),
|
|
225
234
|
link: linkConfig,
|
|
226
235
|
collapsible: sidebarCollapsible,
|
|
227
236
|
collapsed: sidebarCollapsed,
|
|
228
|
-
items: [...taggedSchemaItems, ...taggedApiItems].map((item) =>
|
|
229
|
-
createDocItemFn(item, createDocItemFnContext)
|
|
230
|
-
|
|
237
|
+
items: [...taggedSchemaItems, ...taggedApiItems].map((item) => {
|
|
238
|
+
const docItem = createDocItemFn(item, createDocItemFnContext);
|
|
239
|
+
if (tagGroupKey && docItem.type === "doc") {
|
|
240
|
+
return {
|
|
241
|
+
...docItem,
|
|
242
|
+
key: kebabCase(`${tagGroupKey}-${tag}-${docItem.id}`),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return docItem;
|
|
246
|
+
}),
|
|
231
247
|
};
|
|
232
248
|
})
|
|
233
249
|
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
@@ -296,6 +312,8 @@ export default function generateSidebarSlice(
|
|
|
296
312
|
}
|
|
297
313
|
});
|
|
298
314
|
|
|
315
|
+
const tagGroupKey = kebabCase(tagGroup.name);
|
|
316
|
+
|
|
299
317
|
const groupCategory = {
|
|
300
318
|
type: "category" as const,
|
|
301
319
|
label: tagGroup.name,
|
|
@@ -306,7 +324,8 @@ export default function generateSidebarSlice(
|
|
|
306
324
|
sidebarOptions,
|
|
307
325
|
options,
|
|
308
326
|
[filteredTags],
|
|
309
|
-
docPath
|
|
327
|
+
docPath,
|
|
328
|
+
tagGroupKey
|
|
310
329
|
),
|
|
311
330
|
};
|
|
312
331
|
|
|
@@ -1,181 +0,0 @@
|
|
|
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 schema_1 = require("./schema");
|
|
10
|
-
describe("getQualifierMessage", () => {
|
|
11
|
-
it("should render nothing", () => {
|
|
12
|
-
const actual = (0, schema_1.getQualifierMessage)({});
|
|
13
|
-
expect(actual).toBeUndefined();
|
|
14
|
-
});
|
|
15
|
-
//
|
|
16
|
-
// minLength + maxLength
|
|
17
|
-
//
|
|
18
|
-
it("should render minLength", () => {
|
|
19
|
-
const expected = "**Possible values:** `non-empty`";
|
|
20
|
-
const actual = (0, schema_1.getQualifierMessage)({ minLength: 1 });
|
|
21
|
-
expect(actual).toBe(expected);
|
|
22
|
-
});
|
|
23
|
-
it("should render maxLength", () => {
|
|
24
|
-
const expected = "**Possible values:** `<= 40 characters`";
|
|
25
|
-
const actual = (0, schema_1.getQualifierMessage)({ maxLength: 40 });
|
|
26
|
-
expect(actual).toBe(expected);
|
|
27
|
-
});
|
|
28
|
-
it("should render minLength and maxLength", () => {
|
|
29
|
-
const expected = "**Possible values:** `non-empty` and `<= 40 characters`";
|
|
30
|
-
const actual = (0, schema_1.getQualifierMessage)({ minLength: 1, maxLength: 40 });
|
|
31
|
-
expect(actual).toBe(expected);
|
|
32
|
-
});
|
|
33
|
-
//
|
|
34
|
-
// pattern
|
|
35
|
-
//
|
|
36
|
-
it("should render pattern", () => {
|
|
37
|
-
const expected = "**Possible values:** Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
38
|
-
const actual = (0, schema_1.getQualifierMessage)({ pattern: "^[a-zA-Z0-9_-]*$" });
|
|
39
|
-
expect(actual).toBe(expected);
|
|
40
|
-
});
|
|
41
|
-
it("should render multiple string qualifiers", () => {
|
|
42
|
-
const expected = "**Possible values:** `non-empty` and `<= 40 characters`, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
43
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
44
|
-
minLength: 1,
|
|
45
|
-
maxLength: 40,
|
|
46
|
-
pattern: "^[a-zA-Z0-9_-]*$",
|
|
47
|
-
});
|
|
48
|
-
expect(actual).toBe(expected);
|
|
49
|
-
});
|
|
50
|
-
//
|
|
51
|
-
// enum
|
|
52
|
-
//
|
|
53
|
-
it("should render enum", () => {
|
|
54
|
-
const expected = "**Possible values:** [`cat`, `dog`, `mouse`]";
|
|
55
|
-
const actual = (0, schema_1.getQualifierMessage)({ enum: ["cat", "dog", "mouse"] });
|
|
56
|
-
expect(actual).toBe(expected);
|
|
57
|
-
});
|
|
58
|
-
//
|
|
59
|
-
// minimum + maximum + exclusiveMinimum + exclusiveMaximum
|
|
60
|
-
//
|
|
61
|
-
it("should render minimum", () => {
|
|
62
|
-
const expected = "**Possible values:** `>= 1`";
|
|
63
|
-
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1 });
|
|
64
|
-
expect(actual).toBe(expected);
|
|
65
|
-
});
|
|
66
|
-
it("should render maximum", () => {
|
|
67
|
-
const expected = "**Possible values:** `<= 40`";
|
|
68
|
-
const actual = (0, schema_1.getQualifierMessage)({ maximum: 40 });
|
|
69
|
-
expect(actual).toBe(expected);
|
|
70
|
-
});
|
|
71
|
-
it("should render numeric exclusiveMinimum", () => {
|
|
72
|
-
const expected = "**Possible values:** `> 1`";
|
|
73
|
-
const actual = (0, schema_1.getQualifierMessage)({ exclusiveMinimum: 1 });
|
|
74
|
-
expect(actual).toBe(expected);
|
|
75
|
-
});
|
|
76
|
-
it("should render numeric exclusiveMaximum", () => {
|
|
77
|
-
const expected = "**Possible values:** `< 40`";
|
|
78
|
-
const actual = (0, schema_1.getQualifierMessage)({ exclusiveMaximum: 40 });
|
|
79
|
-
expect(actual).toBe(expected);
|
|
80
|
-
});
|
|
81
|
-
it("should render boolean exclusiveMinimum", () => {
|
|
82
|
-
const expected = "**Possible values:** `> 1`";
|
|
83
|
-
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: true });
|
|
84
|
-
expect(actual).toBe(expected);
|
|
85
|
-
});
|
|
86
|
-
it("should render boolean exclusiveMaximum", () => {
|
|
87
|
-
const expected = "**Possible values:** `< 40`";
|
|
88
|
-
const actual = (0, schema_1.getQualifierMessage)({ maximum: 40, exclusiveMaximum: true });
|
|
89
|
-
expect(actual).toBe(expected);
|
|
90
|
-
});
|
|
91
|
-
it("should render minimum when exclusiveMinimum is false", () => {
|
|
92
|
-
const expected = "**Possible values:** `>= 1`";
|
|
93
|
-
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: false });
|
|
94
|
-
expect(actual).toBe(expected);
|
|
95
|
-
});
|
|
96
|
-
it("should render maximum when exclusiveMaximum is false", () => {
|
|
97
|
-
const expected = "**Possible values:** `<= 40`";
|
|
98
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
99
|
-
maximum: 40,
|
|
100
|
-
exclusiveMaximum: false,
|
|
101
|
-
});
|
|
102
|
-
expect(actual).toBe(expected);
|
|
103
|
-
});
|
|
104
|
-
it("should render minimum and maximum", () => {
|
|
105
|
-
const expected = "**Possible values:** `>= 1` and `<= 40`";
|
|
106
|
-
const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, maximum: 40 });
|
|
107
|
-
expect(actual).toBe(expected);
|
|
108
|
-
});
|
|
109
|
-
it("should render 0 minimum and maximum", () => {
|
|
110
|
-
const expected = "**Possible values:** `>= 0` and `<= 40`";
|
|
111
|
-
const actual = (0, schema_1.getQualifierMessage)({ minimum: 0, maximum: 40 });
|
|
112
|
-
expect(actual).toBe(expected);
|
|
113
|
-
});
|
|
114
|
-
it("should render minimum and 0 maximum", () => {
|
|
115
|
-
const expected = "**Possible values:** `>= -10` and `<= 0`";
|
|
116
|
-
const actual = (0, schema_1.getQualifierMessage)({ minimum: -10, maximum: 0 });
|
|
117
|
-
expect(actual).toBe(expected);
|
|
118
|
-
});
|
|
119
|
-
it("should render boolean exclusiveMinimum and maximum", () => {
|
|
120
|
-
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
121
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
122
|
-
minimum: 1,
|
|
123
|
-
maximum: 40,
|
|
124
|
-
exclusiveMinimum: true,
|
|
125
|
-
});
|
|
126
|
-
expect(actual).toBe(expected);
|
|
127
|
-
});
|
|
128
|
-
it("should render minimum and boolean exclusiveMaximum", () => {
|
|
129
|
-
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
130
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
131
|
-
minimum: 1,
|
|
132
|
-
maximum: 40,
|
|
133
|
-
exclusiveMaximum: true,
|
|
134
|
-
});
|
|
135
|
-
expect(actual).toBe(expected);
|
|
136
|
-
});
|
|
137
|
-
it("should render numeric exclusiveMinimum and maximum", () => {
|
|
138
|
-
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
139
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
140
|
-
exclusiveMinimum: 1,
|
|
141
|
-
maximum: 40,
|
|
142
|
-
});
|
|
143
|
-
expect(actual).toBe(expected);
|
|
144
|
-
});
|
|
145
|
-
it("should render minimum and numeric exclusiveMaximum", () => {
|
|
146
|
-
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
147
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
148
|
-
minimum: 1,
|
|
149
|
-
exclusiveMaximum: 40,
|
|
150
|
-
});
|
|
151
|
-
expect(actual).toBe(expected);
|
|
152
|
-
});
|
|
153
|
-
it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => {
|
|
154
|
-
const expected = "**Possible values:** `> 1` and `< 40`";
|
|
155
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
156
|
-
exclusiveMinimum: 1,
|
|
157
|
-
maximum: 40,
|
|
158
|
-
exclusiveMaximum: true,
|
|
159
|
-
});
|
|
160
|
-
expect(actual).toBe(expected);
|
|
161
|
-
});
|
|
162
|
-
it("should render nothing with empty boolean exclusiveMinimum", () => {
|
|
163
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
164
|
-
exclusiveMinimum: true,
|
|
165
|
-
});
|
|
166
|
-
expect(actual).toBeUndefined();
|
|
167
|
-
});
|
|
168
|
-
it("should render nothing with empty boolean exclusiveMaximum", () => {
|
|
169
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
170
|
-
exclusiveMaximum: true,
|
|
171
|
-
});
|
|
172
|
-
expect(actual).toBeUndefined();
|
|
173
|
-
});
|
|
174
|
-
it("should render nothing with empty boolean exclusiveMinimum and exclusiveMaximum", () => {
|
|
175
|
-
const actual = (0, schema_1.getQualifierMessage)({
|
|
176
|
-
exclusiveMinimum: true,
|
|
177
|
-
exclusiveMaximum: true,
|
|
178
|
-
});
|
|
179
|
-
expect(actual).toBeUndefined();
|
|
180
|
-
});
|
|
181
|
-
});
|
|
@@ -1,208 +0,0 @@
|
|
|
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 { getQualifierMessage } from "./schema";
|
|
9
|
-
|
|
10
|
-
describe("getQualifierMessage", () => {
|
|
11
|
-
it("should render nothing", () => {
|
|
12
|
-
const actual = getQualifierMessage({});
|
|
13
|
-
expect(actual).toBeUndefined();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
// minLength + maxLength
|
|
18
|
-
//
|
|
19
|
-
it("should render minLength", () => {
|
|
20
|
-
const expected = "**Possible values:** `non-empty`";
|
|
21
|
-
const actual = getQualifierMessage({ minLength: 1 });
|
|
22
|
-
expect(actual).toBe(expected);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("should render maxLength", () => {
|
|
26
|
-
const expected = "**Possible values:** `<= 40 characters`";
|
|
27
|
-
const actual = getQualifierMessage({ maxLength: 40 });
|
|
28
|
-
expect(actual).toBe(expected);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("should render minLength and maxLength", () => {
|
|
32
|
-
const expected = "**Possible values:** `non-empty` and `<= 40 characters`";
|
|
33
|
-
const actual = getQualifierMessage({ minLength: 1, maxLength: 40 });
|
|
34
|
-
expect(actual).toBe(expected);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
// pattern
|
|
39
|
-
//
|
|
40
|
-
it("should render pattern", () => {
|
|
41
|
-
const expected =
|
|
42
|
-
"**Possible values:** Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
43
|
-
const actual = getQualifierMessage({ pattern: "^[a-zA-Z0-9_-]*$" });
|
|
44
|
-
expect(actual).toBe(expected);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should render multiple string qualifiers", () => {
|
|
48
|
-
const expected =
|
|
49
|
-
"**Possible values:** `non-empty` and `<= 40 characters`, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
|
|
50
|
-
const actual = getQualifierMessage({
|
|
51
|
-
minLength: 1,
|
|
52
|
-
maxLength: 40,
|
|
53
|
-
pattern: "^[a-zA-Z0-9_-]*$",
|
|
54
|
-
});
|
|
55
|
-
expect(actual).toBe(expected);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
// enum
|
|
60
|
-
//
|
|
61
|
-
it("should render enum", () => {
|
|
62
|
-
const expected = "**Possible values:** [`cat`, `dog`, `mouse`]";
|
|
63
|
-
const actual = getQualifierMessage({ enum: ["cat", "dog", "mouse"] });
|
|
64
|
-
expect(actual).toBe(expected);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
// minimum + maximum + exclusiveMinimum + exclusiveMaximum
|
|
69
|
-
//
|
|
70
|
-
it("should render minimum", () => {
|
|
71
|
-
const expected = "**Possible values:** `>= 1`";
|
|
72
|
-
const actual = getQualifierMessage({ minimum: 1 });
|
|
73
|
-
expect(actual).toBe(expected);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("should render maximum", () => {
|
|
77
|
-
const expected = "**Possible values:** `<= 40`";
|
|
78
|
-
const actual = getQualifierMessage({ maximum: 40 });
|
|
79
|
-
expect(actual).toBe(expected);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("should render numeric exclusiveMinimum", () => {
|
|
83
|
-
const expected = "**Possible values:** `> 1`";
|
|
84
|
-
const actual = getQualifierMessage({ exclusiveMinimum: 1 });
|
|
85
|
-
expect(actual).toBe(expected);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("should render numeric exclusiveMaximum", () => {
|
|
89
|
-
const expected = "**Possible values:** `< 40`";
|
|
90
|
-
const actual = getQualifierMessage({ exclusiveMaximum: 40 });
|
|
91
|
-
expect(actual).toBe(expected);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("should render boolean exclusiveMinimum", () => {
|
|
95
|
-
const expected = "**Possible values:** `> 1`";
|
|
96
|
-
const actual = getQualifierMessage({ minimum: 1, exclusiveMinimum: true });
|
|
97
|
-
expect(actual).toBe(expected);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should render boolean exclusiveMaximum", () => {
|
|
101
|
-
const expected = "**Possible values:** `< 40`";
|
|
102
|
-
const actual = getQualifierMessage({ maximum: 40, exclusiveMaximum: true });
|
|
103
|
-
expect(actual).toBe(expected);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("should render minimum when exclusiveMinimum is false", () => {
|
|
107
|
-
const expected = "**Possible values:** `>= 1`";
|
|
108
|
-
const actual = getQualifierMessage({ minimum: 1, exclusiveMinimum: false });
|
|
109
|
-
expect(actual).toBe(expected);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("should render maximum when exclusiveMaximum is false", () => {
|
|
113
|
-
const expected = "**Possible values:** `<= 40`";
|
|
114
|
-
const actual = getQualifierMessage({
|
|
115
|
-
maximum: 40,
|
|
116
|
-
exclusiveMaximum: false,
|
|
117
|
-
});
|
|
118
|
-
expect(actual).toBe(expected);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("should render minimum and maximum", () => {
|
|
122
|
-
const expected = "**Possible values:** `>= 1` and `<= 40`";
|
|
123
|
-
const actual = getQualifierMessage({ minimum: 1, maximum: 40 });
|
|
124
|
-
expect(actual).toBe(expected);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("should render 0 minimum and maximum", () => {
|
|
128
|
-
const expected = "**Possible values:** `>= 0` and `<= 40`";
|
|
129
|
-
const actual = getQualifierMessage({ minimum: 0, maximum: 40 });
|
|
130
|
-
expect(actual).toBe(expected);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("should render minimum and 0 maximum", () => {
|
|
134
|
-
const expected = "**Possible values:** `>= -10` and `<= 0`";
|
|
135
|
-
const actual = getQualifierMessage({ minimum: -10, maximum: 0 });
|
|
136
|
-
expect(actual).toBe(expected);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("should render boolean exclusiveMinimum and maximum", () => {
|
|
140
|
-
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
141
|
-
const actual = getQualifierMessage({
|
|
142
|
-
minimum: 1,
|
|
143
|
-
maximum: 40,
|
|
144
|
-
exclusiveMinimum: true,
|
|
145
|
-
});
|
|
146
|
-
expect(actual).toBe(expected);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("should render minimum and boolean exclusiveMaximum", () => {
|
|
150
|
-
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
151
|
-
const actual = getQualifierMessage({
|
|
152
|
-
minimum: 1,
|
|
153
|
-
maximum: 40,
|
|
154
|
-
exclusiveMaximum: true,
|
|
155
|
-
});
|
|
156
|
-
expect(actual).toBe(expected);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("should render numeric exclusiveMinimum and maximum", () => {
|
|
160
|
-
const expected = "**Possible values:** `> 1` and `<= 40`";
|
|
161
|
-
const actual = getQualifierMessage({
|
|
162
|
-
exclusiveMinimum: 1,
|
|
163
|
-
maximum: 40,
|
|
164
|
-
});
|
|
165
|
-
expect(actual).toBe(expected);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("should render minimum and numeric exclusiveMaximum", () => {
|
|
169
|
-
const expected = "**Possible values:** `>= 1` and `< 40`";
|
|
170
|
-
const actual = getQualifierMessage({
|
|
171
|
-
minimum: 1,
|
|
172
|
-
exclusiveMaximum: 40,
|
|
173
|
-
});
|
|
174
|
-
expect(actual).toBe(expected);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => {
|
|
178
|
-
const expected = "**Possible values:** `> 1` and `< 40`";
|
|
179
|
-
const actual = getQualifierMessage({
|
|
180
|
-
exclusiveMinimum: 1,
|
|
181
|
-
maximum: 40,
|
|
182
|
-
exclusiveMaximum: true,
|
|
183
|
-
});
|
|
184
|
-
expect(actual).toBe(expected);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("should render nothing with empty boolean exclusiveMinimum", () => {
|
|
188
|
-
const actual = getQualifierMessage({
|
|
189
|
-
exclusiveMinimum: true,
|
|
190
|
-
});
|
|
191
|
-
expect(actual).toBeUndefined();
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it("should render nothing with empty boolean exclusiveMaximum", () => {
|
|
195
|
-
const actual = getQualifierMessage({
|
|
196
|
-
exclusiveMaximum: true,
|
|
197
|
-
});
|
|
198
|
-
expect(actual).toBeUndefined();
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("should render nothing with empty boolean exclusiveMinimum and exclusiveMaximum", () => {
|
|
202
|
-
const actual = getQualifierMessage({
|
|
203
|
-
exclusiveMinimum: true,
|
|
204
|
-
exclusiveMaximum: true,
|
|
205
|
-
});
|
|
206
|
-
expect(actual).toBeUndefined();
|
|
207
|
-
});
|
|
208
|
-
});
|
|
File without changes
|