docusaurus-plugin-openapi-docs 1.1.0 → 1.1.3

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.
@@ -16,17 +16,17 @@ describe("getQualifierMessage", () => {
16
16
  // minLength + maxLength
17
17
  //
18
18
  it("should render minLength", () => {
19
- const expected = "**Possible values:** 1 ≤ length";
19
+ const expected = "**Possible values:** `non-empty`";
20
20
  const actual = (0, schema_1.getQualifierMessage)({ minLength: 1 });
21
21
  expect(actual).toBe(expected);
22
22
  });
23
23
  it("should render maxLength", () => {
24
- const expected = "**Possible values:** length 40";
24
+ const expected = "**Possible values:** `<= 40 characters`";
25
25
  const actual = (0, schema_1.getQualifierMessage)({ maxLength: 40 });
26
26
  expect(actual).toBe(expected);
27
27
  });
28
28
  it("should render minLength and maxLength", () => {
29
- const expected = "**Possible values:** 1 length 40";
29
+ const expected = "**Possible values:** `non-empty` and `<= 40 characters`";
30
30
  const actual = (0, schema_1.getQualifierMessage)({ minLength: 1, maxLength: 40 });
31
31
  expect(actual).toBe(expected);
32
32
  });
@@ -39,7 +39,7 @@ describe("getQualifierMessage", () => {
39
39
  expect(actual).toBe(expected);
40
40
  });
41
41
  it("should render multiple string qualifiers", () => {
42
- const expected = "**Possible values:** 1 length 40, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
42
+ const expected = "**Possible values:** `non-empty` and `<= 40 characters`, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
43
43
  const actual = (0, schema_1.getQualifierMessage)({
44
44
  minLength: 1,
45
45
  maxLength: 40,
@@ -59,42 +59,42 @@ describe("getQualifierMessage", () => {
59
59
  // minimum + maximum + exclusiveMinimum + exclusiveMaximum
60
60
  //
61
61
  it("should render minimum", () => {
62
- const expected = "**Possible values:** 1 ≤ value";
62
+ const expected = "**Possible values:** `>= 1`";
63
63
  const actual = (0, schema_1.getQualifierMessage)({ minimum: 1 });
64
64
  expect(actual).toBe(expected);
65
65
  });
66
66
  it("should render maximum", () => {
67
- const expected = "**Possible values:** value 40";
67
+ const expected = "**Possible values:** `<= 40`";
68
68
  const actual = (0, schema_1.getQualifierMessage)({ maximum: 40 });
69
69
  expect(actual).toBe(expected);
70
70
  });
71
71
  it("should render numeric exclusiveMinimum", () => {
72
- const expected = "**Possible values:** 1 < value";
72
+ const expected = "**Possible values:** `> 1`";
73
73
  const actual = (0, schema_1.getQualifierMessage)({ exclusiveMinimum: 1 });
74
74
  expect(actual).toBe(expected);
75
75
  });
76
76
  it("should render numeric exclusiveMaximum", () => {
77
- const expected = "**Possible values:** value < 40";
77
+ const expected = "**Possible values:** `< 40`";
78
78
  const actual = (0, schema_1.getQualifierMessage)({ exclusiveMaximum: 40 });
79
79
  expect(actual).toBe(expected);
80
80
  });
81
81
  it("should render boolean exclusiveMinimum", () => {
82
- const expected = "**Possible values:** 1 < value";
82
+ const expected = "**Possible values:** `> 1`";
83
83
  const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: true });
84
84
  expect(actual).toBe(expected);
85
85
  });
86
86
  it("should render boolean exclusiveMaximum", () => {
87
- const expected = "**Possible values:** value < 40";
87
+ const expected = "**Possible values:** `< 40`";
88
88
  const actual = (0, schema_1.getQualifierMessage)({ maximum: 40, exclusiveMaximum: true });
89
89
  expect(actual).toBe(expected);
90
90
  });
91
91
  it("should render minimum when exclusiveMinimum is false", () => {
92
- const expected = "**Possible values:** 1 ≤ value";
92
+ const expected = "**Possible values:** `>= 1`";
93
93
  const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: false });
94
94
  expect(actual).toBe(expected);
95
95
  });
96
96
  it("should render maximum when exclusiveMaximum is false", () => {
97
- const expected = "**Possible values:** value 40";
97
+ const expected = "**Possible values:** `<= 40`";
98
98
  const actual = (0, schema_1.getQualifierMessage)({
99
99
  maximum: 40,
100
100
  exclusiveMaximum: false,
@@ -102,12 +102,12 @@ describe("getQualifierMessage", () => {
102
102
  expect(actual).toBe(expected);
103
103
  });
104
104
  it("should render minimum and maximum", () => {
105
- const expected = "**Possible values:** 1 value 40";
105
+ const expected = "**Possible values:** `>= 1` and `<= 40`";
106
106
  const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, maximum: 40 });
107
107
  expect(actual).toBe(expected);
108
108
  });
109
109
  it("should render boolean exclusiveMinimum and maximum", () => {
110
- const expected = "**Possible values:** 1 < value 40";
110
+ const expected = "**Possible values:** `> 1` and `<= 40`";
111
111
  const actual = (0, schema_1.getQualifierMessage)({
112
112
  minimum: 1,
113
113
  maximum: 40,
@@ -116,7 +116,7 @@ describe("getQualifierMessage", () => {
116
116
  expect(actual).toBe(expected);
117
117
  });
118
118
  it("should render minimum and boolean exclusiveMaximum", () => {
119
- const expected = "**Possible values:** 1 value < 40";
119
+ const expected = "**Possible values:** `>= 1` and `< 40`";
120
120
  const actual = (0, schema_1.getQualifierMessage)({
121
121
  minimum: 1,
122
122
  maximum: 40,
@@ -125,7 +125,7 @@ describe("getQualifierMessage", () => {
125
125
  expect(actual).toBe(expected);
126
126
  });
127
127
  it("should render numeric exclusiveMinimum and maximum", () => {
128
- const expected = "**Possible values:** 1 < value 40";
128
+ const expected = "**Possible values:** `> 1` and `<= 40`";
129
129
  const actual = (0, schema_1.getQualifierMessage)({
130
130
  exclusiveMinimum: 1,
131
131
  maximum: 40,
@@ -133,7 +133,7 @@ describe("getQualifierMessage", () => {
133
133
  expect(actual).toBe(expected);
134
134
  });
135
135
  it("should render minimum and numeric exclusiveMaximum", () => {
136
- const expected = "**Possible values:** 1 value < 40";
136
+ const expected = "**Possible values:** `>= 1` and `< 40`";
137
137
  const actual = (0, schema_1.getQualifierMessage)({
138
138
  minimum: 1,
139
139
  exclusiveMaximum: 40,
@@ -141,7 +141,7 @@ describe("getQualifierMessage", () => {
141
141
  expect(actual).toBe(expected);
142
142
  });
143
143
  it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => {
144
- const expected = "**Possible values:** 1 < value < 40";
144
+ const expected = "**Possible values:** `> 1` and `< 40`";
145
145
  const actual = (0, schema_1.getQualifierMessage)({
146
146
  exclusiveMinimum: 1,
147
147
  maximum: 40,
@@ -16,7 +16,8 @@ const openapi_to_postmanv2_1 = __importDefault(require("@paloaltonetworks/openap
16
16
  const postman_collection_1 = __importDefault(require("@paloaltonetworks/postman-collection"));
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
18
  const fs_extra_1 = __importDefault(require("fs-extra"));
19
- const lodash_1 = require("lodash");
19
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
20
+ const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
20
21
  const index_1 = require("../index");
21
22
  const createExample_1 = require("./createExample");
22
23
  const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
@@ -40,7 +41,8 @@ function jsonToCollection(data) {
40
41
  */
41
42
  async function createPostmanCollection(openapiData) {
42
43
  var _a, _b, _c, _d, _e, _f, _g, _h;
43
- const data = openapiData;
44
+ // Create copy of openapiData
45
+ const data = (0, cloneDeep_1.default)(openapiData);
44
46
  // Including `servers` breaks postman, so delete all of them.
45
47
  delete data.servers;
46
48
  for (let pathItemObject of Object.values(data.paths)) {
@@ -60,7 +62,7 @@ function createItems(openapiData, sidebarOptions) {
60
62
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
61
63
  // TODO: Find a better way to handle this
62
64
  let items = [];
63
- const infoId = (0, lodash_1.kebabCase)(openapiData.info.title);
65
+ const infoId = (0, kebabCase_1.default)(openapiData.info.title);
64
66
  if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
65
67
  // Only create an tag pages if categoryLinkSource set to tag.
66
68
  const tags = (_a = openapiData.tags) !== null && _a !== void 0 ? _a : [];
@@ -71,14 +73,13 @@ function createItems(openapiData, sidebarOptions) {
71
73
  .map((tag) => {
72
74
  var _a;
73
75
  const description = getTagDisplayName(tag.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []);
74
- const tagId = (0, lodash_1.kebabCase)(tag.name);
76
+ const tagId = (0, kebabCase_1.default)(tag.name);
75
77
  const tagPage = {
76
78
  type: "tag",
77
79
  id: tagId,
78
80
  unversionedId: tagId,
79
81
  title: description !== null && description !== void 0 ? description : "",
80
82
  description: description !== null && description !== void 0 ? description : "",
81
- slug: "/" + tagId,
82
83
  frontMatter: {},
83
84
  tag: {
84
85
  ...tag,
@@ -95,13 +96,14 @@ function createItems(openapiData, sidebarOptions) {
95
96
  unversionedId: infoId,
96
97
  title: openapiData.info.title,
97
98
  description: openapiData.info.description,
98
- slug: "/" + infoId,
99
99
  frontMatter: {},
100
100
  securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
101
101
  info: {
102
102
  ...openapiData.info,
103
103
  tags: (_c = openapiData.tags) === null || _c === void 0 ? void 0 : _c.map((tagName) => { var _a; return getTagDisplayName(tagName.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
104
104
  title: (_d = openapiData.info.title) !== null && _d !== void 0 ? _d : "Introduction",
105
+ logo: openapiData.info["x-logo"],
106
+ darkLogo: openapiData.info["x-dark-logo"],
105
107
  },
106
108
  };
107
109
  items.push(infoPage);
@@ -114,7 +116,9 @@ function createItems(openapiData, sidebarOptions) {
114
116
  operationObject.description =
115
117
  (_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
116
118
  }
117
- const baseId = (0, lodash_1.kebabCase)(title);
119
+ const baseId = operationObject.operationId
120
+ ? (0, kebabCase_1.default)(operationObject.operationId)
121
+ : (0, kebabCase_1.default)(operationObject.summary);
118
122
  const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
119
123
  const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
120
124
  // Add security schemes so we know how to handle security.
@@ -141,7 +145,6 @@ function createItems(openapiData, sidebarOptions) {
141
145
  unversionedId: baseId,
142
146
  title: title,
143
147
  description: description !== null && description !== void 0 ? description : "",
144
- slug: "/" + baseId,
145
148
  frontMatter: {},
146
149
  api: {
147
150
  ...defaults,
@@ -31,6 +31,13 @@ export interface InfoObject {
31
31
  license?: LicenseObject;
32
32
  version: string;
33
33
  tags?: String[];
34
+ "x-logo"?: LogoObject;
35
+ "x-dark-logo"?: LogoObject;
36
+ logo?: LogoObject;
37
+ darkLogo?: LogoObject;
38
+ }
39
+ export interface LogoObject {
40
+ url?: string;
34
41
  }
35
42
  export interface ContactObject {
36
43
  name?: string;
@@ -15,6 +15,7 @@ const openapi_core_1 = require("@redocly/openapi-core");
15
15
  const chalk_1 = __importDefault(require("chalk"));
16
16
  // @ts-ignore
17
17
  const swagger2openapi_1 = require("swagger2openapi");
18
+ const OpenAPIParser_1 = require("./services/OpenAPIParser");
18
19
  function serializer(replacer, cycleReplacer) {
19
20
  var stack = [], keys = [];
20
21
  if (cycleReplacer === undefined)
@@ -24,6 +25,18 @@ function serializer(replacer, cycleReplacer) {
24
25
  return value.title ? `circular(${value.title})` : "circular()";
25
26
  };
26
27
  return function (key, value) {
28
+ // Resolve discriminator ref pointers
29
+ if ((value === null || value === void 0 ? void 0 : value.discriminator) !== undefined) {
30
+ const parser = new OpenAPIParser_1.OpenAPIParser(stack[0]);
31
+ for (let [k, v] of Object.entries(value.discriminator.mapping)) {
32
+ const discriminator = k;
33
+ if (typeof v === "string" && v.charAt(0) === "#") {
34
+ const ref = v;
35
+ const resolvedRef = parser.byRef(ref);
36
+ value.discriminator.mapping[discriminator] = resolvedRef;
37
+ }
38
+ }
39
+ }
27
40
  if (stack.length > 0) {
28
41
  // @ts-ignore
29
42
  var thisPos = stack.indexOf(this);
@@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const path_1 = __importDefault(require("path"));
12
13
  const clsx_1 = __importDefault(require("clsx"));
13
14
  const lodash_1 = require("lodash");
14
15
  const uniq_1 = __importDefault(require("lodash/uniq"));
@@ -98,8 +99,8 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
98
99
  type: "generated-index",
99
100
  title: tag,
100
101
  slug: label
101
- ? "/category/" + (0, lodash_1.kebabCase)(label) + "/" + (0, lodash_1.kebabCase)(tag)
102
- : "/category/" + (0, lodash_1.kebabCase)(tag),
102
+ ? path_1.default.join("/category", basePath, (0, lodash_1.kebabCase)(label), (0, lodash_1.kebabCase)(tag))
103
+ : path_1.default.join("/category", basePath, (0, lodash_1.kebabCase)(tag)),
103
104
  };
104
105
  }
105
106
  return {
package/lib/types.d.ts CHANGED
@@ -51,7 +51,7 @@ export interface ApiMetadataBase {
51
51
  description: string;
52
52
  source: string;
53
53
  sourceDirName: string;
54
- slug: string;
54
+ slug?: string;
55
55
  permalink: string;
56
56
  sidebarPosition?: number;
57
57
  frontMatter: Record<string, unknown>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "1.1.0",
4
+ "version": "1.1.3",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -28,8 +28,8 @@
28
28
  "watch": "tsc --watch"
29
29
  },
30
30
  "devDependencies": {
31
- "@docusaurus/module-type-aliases": "2.0.0-beta.22",
32
- "@docusaurus/types": "2.0.0-beta.22",
31
+ "@docusaurus/module-type-aliases": "2.0.1",
32
+ "@docusaurus/types": "2.0.1",
33
33
  "@types/fs-extra": "^9.0.13",
34
34
  "@types/js-yaml": "^4.0.5",
35
35
  "@types/json-pointer": "^1.0.31",
@@ -40,10 +40,10 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@apidevtools/json-schema-ref-parser": "^9.0.9",
43
- "@docusaurus/mdx-loader": "2.0.0-beta.22",
44
- "@docusaurus/plugin-content-docs": "2.0.0-beta.22",
45
- "@docusaurus/utils": "2.0.0-beta.22",
46
- "@docusaurus/utils-validation": "2.0.0-beta.22",
43
+ "@docusaurus/mdx-loader": "2.0.1",
44
+ "@docusaurus/plugin-content-docs": "2.0.1",
45
+ "@docusaurus/utils": "2.0.1",
46
+ "@docusaurus/utils-validation": "2.0.1",
47
47
  "@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
48
48
  "@paloaltonetworks/postman-collection": "^4.1.0",
49
49
  "@redocly/openapi-core": "^1.0.0-beta.103",
@@ -67,5 +67,5 @@
67
67
  "engines": {
68
68
  "node": ">=14"
69
69
  },
70
- "gitHead": "31b50e968a9cc66b1c3cb078a0fed772054f8246"
70
+ "gitHead": "4897267289b035aed8155f6001e14c80ba9003a8"
71
71
  }
@@ -0,0 +1,21 @@
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 { LogoObject } from "../openapi/types";
9
+ import { create, guard } from "./utils";
10
+
11
+ export function createLogo(
12
+ logo: LogoObject | undefined,
13
+ darkLogo: LogoObject | undefined
14
+ ) {
15
+ return guard(logo || darkLogo, () => [
16
+ create("ApiLogo", {
17
+ logo: logo,
18
+ darkLogo: darkLogo,
19
+ }),
20
+ ]);
21
+ }
@@ -99,6 +99,7 @@ function createAnyOneOf(schema: SchemaObject): any {
99
99
  }
100
100
 
101
101
  function createProperties(schema: SchemaObject) {
102
+ const discriminator = schema.discriminator;
102
103
  return Object.entries(schema.properties!).map(([key, val]) =>
103
104
  createEdges({
104
105
  name: key,
@@ -106,6 +107,7 @@ function createProperties(schema: SchemaObject) {
106
107
  required: Array.isArray(schema.required)
107
108
  ? schema.required.includes(key)
108
109
  : false,
110
+ discriminator,
109
111
  })
110
112
  );
111
113
  }
@@ -277,6 +279,110 @@ function createItems(schema: SchemaObject) {
277
279
  );
278
280
  }
279
281
 
282
+ /**
283
+ * For handling discriminators that do not map to a same-level property
284
+ */
285
+ function createDiscriminator(schema: SchemaObject) {
286
+ const discriminator = schema.discriminator;
287
+ const propertyName = discriminator?.propertyName;
288
+ const propertyType = "string"; // should always be string
289
+ const mapping: any = discriminator?.mapping;
290
+
291
+ // Explicit mapping is required since we can't support implicit
292
+ if (mapping === undefined) {
293
+ return undefined;
294
+ }
295
+
296
+ // Attempt to get the property description we want to display
297
+ // TODO: how to make it predictable when handling allOf
298
+ let propertyDescription;
299
+ const firstMappingSchema = mapping[Object.keys(mapping)[0]];
300
+ if (firstMappingSchema.properties !== undefined) {
301
+ propertyDescription =
302
+ firstMappingSchema.properties![propertyName!].description;
303
+ }
304
+ if (firstMappingSchema.allOf !== undefined) {
305
+ const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
306
+ firstMappingSchema.allOf
307
+ );
308
+ if (mergedSchemas.properties !== undefined) {
309
+ propertyDescription =
310
+ mergedSchemas.properties[propertyName!]?.description;
311
+ }
312
+ }
313
+
314
+ if (propertyDescription === undefined) {
315
+ if (
316
+ schema.properties !== undefined &&
317
+ schema.properties![propertyName!] !== undefined
318
+ ) {
319
+ propertyDescription = schema.properties![propertyName!].description;
320
+ }
321
+ }
322
+
323
+ return create("div", {
324
+ className: "discriminatorItem",
325
+ children: create("div", {
326
+ children: [
327
+ create("strong", {
328
+ style: { paddingLeft: "1rem" },
329
+ children: propertyName,
330
+ }),
331
+ guard(propertyType, (name) =>
332
+ create("span", {
333
+ style: { opacity: "0.6" },
334
+ children: ` ${propertyType}`,
335
+ })
336
+ ),
337
+ guard(getQualifierMessage(schema.discriminator as any), (message) =>
338
+ create("div", {
339
+ style: {
340
+ paddingLeft: "1rem",
341
+ },
342
+ children: createDescription(message),
343
+ })
344
+ ),
345
+ guard(propertyDescription, (description) =>
346
+ create("div", {
347
+ style: {
348
+ paddingLeft: "1rem",
349
+ },
350
+ children: createDescription(description),
351
+ })
352
+ ),
353
+ create("DiscriminatorTabs", {
354
+ children: Object.keys(mapping!).map((key, index) => {
355
+ if (mapping[key].allOf !== undefined) {
356
+ const { mergedSchemas }: { mergedSchemas: SchemaObject } =
357
+ mergeAllOf(mapping[key].allOf);
358
+ // Cleanup duplicate property from mapping schema
359
+ delete mergedSchemas.properties![propertyName!];
360
+ mapping[key] = mergedSchemas;
361
+ }
362
+
363
+ if (mapping[key].properties !== undefined) {
364
+ // Cleanup duplicate property from mapping schema
365
+ delete mapping[key].properties![propertyName!];
366
+ }
367
+
368
+ const label = key;
369
+ return create("TabItem", {
370
+ label: label,
371
+ value: `${index}-item-discriminator`,
372
+ children: [
373
+ create("div", {
374
+ style: { marginLeft: "-4px" },
375
+ children: createNodes(mapping[key]),
376
+ }),
377
+ ],
378
+ });
379
+ }),
380
+ }),
381
+ ],
382
+ }),
383
+ });
384
+ }
385
+
280
386
  function createDetailsNode(
281
387
  name: string,
282
388
  schemaName: string,
@@ -331,18 +437,109 @@ function createDetailsNode(
331
437
  });
332
438
  }
333
439
 
440
+ /**
441
+ * For handling discriminators that map to a same-level property (like 'petType').
442
+ * Note: These should only be encountered while iterating through properties.
443
+ */
444
+ function createPropertyDiscriminator(
445
+ name: string,
446
+ schemaName: string,
447
+ schema: SchemaObject,
448
+ discriminator: any,
449
+ required: any
450
+ ): any {
451
+ if (schema === undefined) {
452
+ return undefined;
453
+ }
454
+
455
+ if (discriminator.mapping === undefined) {
456
+ return undefined;
457
+ }
458
+
459
+ return create("div", {
460
+ className: "discriminatorItem",
461
+ children: create("div", {
462
+ children: [
463
+ create("strong", { style: { paddingLeft: "1rem" }, children: name }),
464
+ guard(schemaName, (name) =>
465
+ create("span", {
466
+ style: { opacity: "0.6" },
467
+ children: ` ${schemaName}`,
468
+ })
469
+ ),
470
+ guard(required, () => [
471
+ create("strong", {
472
+ style: {
473
+ fontSize: "var(--ifm-code-font-size)",
474
+ color: "var(--openapi-required)",
475
+ },
476
+ children: " required",
477
+ }),
478
+ ]),
479
+ guard(getQualifierMessage(discriminator), (message) =>
480
+ create("div", {
481
+ style: {
482
+ paddingLeft: "1rem",
483
+ },
484
+ children: createDescription(message),
485
+ })
486
+ ),
487
+ guard(schema.description, (description) =>
488
+ create("div", {
489
+ style: {
490
+ paddingLeft: "1rem",
491
+ },
492
+ children: createDescription(description),
493
+ })
494
+ ),
495
+ create("DiscriminatorTabs", {
496
+ children: Object.keys(discriminator?.mapping!).map((key, index) => {
497
+ const label = key;
498
+ return create("TabItem", {
499
+ label: label,
500
+ value: `${index}-item-discriminator`,
501
+ children: [
502
+ create("div", {
503
+ style: { marginLeft: "-4px" },
504
+ children: createNodes(discriminator?.mapping[key]),
505
+ }),
506
+ ],
507
+ });
508
+ }),
509
+ }),
510
+ ],
511
+ }),
512
+ });
513
+ }
514
+
334
515
  interface EdgeProps {
335
516
  name: string;
336
517
  schema: SchemaObject;
337
518
  required: boolean;
519
+ discriminator?: any | unknown;
338
520
  }
339
521
 
340
522
  /**
341
523
  * Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
342
524
  */
343
- function createEdges({ name, schema, required }: EdgeProps): any {
525
+ function createEdges({
526
+ name,
527
+ schema,
528
+ required,
529
+ discriminator,
530
+ }: EdgeProps): any {
344
531
  const schemaName = getSchemaName(schema);
345
532
 
533
+ if (discriminator !== undefined && discriminator.propertyName === name) {
534
+ return createPropertyDiscriminator(
535
+ name,
536
+ "string",
537
+ schema,
538
+ discriminator,
539
+ required
540
+ );
541
+ }
542
+
346
543
  if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
347
544
  return createDetailsNode(name, schemaName, schema, required);
348
545
  }
@@ -409,6 +606,10 @@ function createEdges({ name, schema, required }: EdgeProps): any {
409
606
  * Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
410
607
  */
411
608
  function createNodes(schema: SchemaObject): any {
609
+ if (schema.discriminator !== undefined) {
610
+ return createDiscriminator(schema);
611
+ }
612
+
412
613
  if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
413
614
  return createAnyOneOf(schema);
414
615
  }