docusaurus-plugin-openapi-docs 2.0.0-beta.2 → 2.0.0-beta.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.
@@ -5,6 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
+ import clsx from "clsx";
9
+
8
10
  import { MediaTypeObject, SchemaObject } from "../openapi/types";
9
11
  import {
10
12
  createClosingArrayBracket,
@@ -53,7 +55,7 @@ export function mergeAllOf(allOf: SchemaObject[]) {
53
55
  */
54
56
  function createAnyOneOf(schema: SchemaObject): any {
55
57
  const type = schema.oneOf ? "oneOf" : "anyOf";
56
- return create("li", {
58
+ return create("div", {
57
59
  children: [
58
60
  create("span", {
59
61
  className: "badge badge--info",
@@ -68,14 +70,17 @@ function createAnyOneOf(schema: SchemaObject): any {
68
70
 
69
71
  if (anyOneSchema.properties !== undefined) {
70
72
  anyOneChildren.push(createProperties(anyOneSchema));
73
+ delete anyOneSchema.properties;
71
74
  }
72
75
 
73
76
  if (anyOneSchema.allOf !== undefined) {
74
77
  anyOneChildren.push(createNodes(anyOneSchema));
78
+ delete anyOneSchema.allOf;
75
79
  }
76
80
 
77
81
  if (anyOneSchema.items !== undefined) {
78
82
  anyOneChildren.push(createItems(anyOneSchema));
83
+ delete anyOneSchema.items;
79
84
  }
80
85
 
81
86
  if (
@@ -159,6 +164,18 @@ function createAdditionalProperties(schema: SchemaObject) {
159
164
  // }
160
165
  const additionalProperties = schema.additionalProperties;
161
166
  const type: string | unknown = additionalProperties?.type;
167
+ // Handle free-form objects
168
+ if (String(additionalProperties) === "true" && schema.type === "object") {
169
+ return create("SchemaItem", {
170
+ name: "property name*",
171
+ required: false,
172
+ schemaName: "any",
173
+ qualifierMessage: getQualifierMessage(schema.additionalProperties),
174
+ schema: schema,
175
+ collapsible: false,
176
+ discriminator: false,
177
+ });
178
+ }
162
179
  if (
163
180
  (type === "object" || type === "array") &&
164
181
  (additionalProperties?.properties ||
@@ -168,12 +185,12 @@ function createAdditionalProperties(schema: SchemaObject) {
168
185
  additionalProperties?.oneOf ||
169
186
  additionalProperties?.anyOf)
170
187
  ) {
171
- const title = additionalProperties.title;
172
- const schemaName = title ? `object (${title})` : "object";
188
+ const title = additionalProperties.title as string;
189
+ const schemaName = getSchemaName(additionalProperties);
173
190
  const required = schema.required ?? false;
174
191
  return createDetailsNode(
175
192
  "property name*",
176
- schemaName,
193
+ title ?? schemaName,
177
194
  additionalProperties,
178
195
  required,
179
196
  schema.nullable
@@ -191,51 +208,30 @@ function createAdditionalProperties(schema: SchemaObject) {
191
208
  schema.additionalProperties?.additionalProperties;
192
209
  if (additionalProperties !== undefined) {
193
210
  const type = schema.additionalProperties?.additionalProperties?.type;
194
- const format = schema.additionalProperties?.additionalProperties?.format;
195
- return create("li", {
196
- children: create("div", {
197
- children: [
198
- create("code", { children: `property name*` }),
199
- guard(type, (type) =>
200
- create("span", {
201
- style: { opacity: "0.6" },
202
- children: ` ${type}`,
203
- })
204
- ),
205
- guard(format, (format) =>
206
- create("span", {
207
- style: { opacity: "0.6" },
208
- children: ` (${format})`,
209
- })
210
- ),
211
- guard(getQualifierMessage(schema.additionalProperties), (message) =>
212
- create("div", {
213
- style: { marginTop: "var(--ifm-table-cell-padding)" },
214
- children: createDescription(message),
215
- })
216
- ),
217
- ],
218
- }),
211
+ const schemaName = getSchemaName(
212
+ schema.additionalProperties?.additionalProperties!
213
+ );
214
+ return create("SchemaItem", {
215
+ name: "property name*",
216
+ required: false,
217
+ schemaName: schemaName ?? type,
218
+ qualifierMessage:
219
+ schema.additionalProperties ??
220
+ getQualifierMessage(schema.additionalProperties),
221
+ schema: schema,
222
+ collapsible: false,
223
+ discriminator: false,
219
224
  });
220
225
  }
221
- return create("li", {
222
- children: create("div", {
223
- children: [
224
- create("code", { children: `property name*` }),
225
- guard(type, (type) =>
226
- create("span", {
227
- style: { opacity: "0.6" },
228
- children: ` ${type}`,
229
- })
230
- ),
231
- guard(getQualifierMessage(schema.additionalProperties), (message) =>
232
- create("div", {
233
- style: { marginTop: "var(--ifm-table-cell-padding)" },
234
- children: createDescription(message),
235
- })
236
- ),
237
- ],
238
- }),
226
+ const schemaName = getSchemaName(schema.additionalProperties!);
227
+ return create("SchemaItem", {
228
+ name: "property name*",
229
+ required: false,
230
+ schemaName: schemaName,
231
+ qualifierMessage: getQualifierMessage(schema),
232
+ schema: schema.additionalProperties,
233
+ collapsible: false,
234
+ discriminator: false,
239
235
  });
240
236
  }
241
237
  return Object.entries(schema.additionalProperties!).map(([key, val]) =>
@@ -469,38 +465,56 @@ function createDetailsNode(
469
465
  children: [
470
466
  createDetailsSummary({
471
467
  children: [
472
- create("strong", { children: name }),
473
468
  create("span", {
474
- style: { opacity: "0.6" },
475
- children: ` ${schemaName}`,
476
- }),
477
- guard(
478
- (schema.nullable && schema.nullable === true) ||
479
- (nullable && nullable === true),
480
- () => [
469
+ className: "openapi-schema__container",
470
+ children: [
481
471
  create("strong", {
482
- style: {
483
- fontSize: "var(--ifm-code-font-size)",
484
- color: "var(--openapi-nullable)",
485
- },
486
- children: " nullable",
472
+ className: clsx("openapi-schema__property", {
473
+ "openapi-schema__strikethrough": schema.deprecated,
474
+ }),
475
+ children: name,
487
476
  }),
488
- ]
489
- ),
490
- guard(
491
- Array.isArray(required)
492
- ? required.includes(name)
493
- : required === true,
494
- () => [
495
- create("strong", {
496
- style: {
497
- fontSize: "var(--ifm-code-font-size)",
498
- color: "var(--openapi-required)",
499
- },
500
- children: " required",
477
+ create("span", {
478
+ className: "openapi-schema__name",
479
+ children: ` ${schemaName}`,
501
480
  }),
502
- ]
503
- ),
481
+ guard(
482
+ (Array.isArray(required)
483
+ ? required.includes(name)
484
+ : required === true) ||
485
+ schema.deprecated ||
486
+ nullable,
487
+ () => [
488
+ create("span", {
489
+ className: "openapi-schema__divider",
490
+ }),
491
+ ]
492
+ ),
493
+ guard(nullable, () => [
494
+ create("span", {
495
+ className: "openapi-schema__nullable",
496
+ children: "nullable",
497
+ }),
498
+ ]),
499
+ guard(
500
+ Array.isArray(required)
501
+ ? required.includes(name)
502
+ : required === true,
503
+ () => [
504
+ create("span", {
505
+ className: "openapi-schema__required",
506
+ children: "required",
507
+ }),
508
+ ]
509
+ ),
510
+ guard(schema.deprecated, () => [
511
+ create("span", {
512
+ className: "openapi-schema__deprecated",
513
+ children: "deprecated",
514
+ }),
515
+ ]),
516
+ ],
517
+ }),
504
518
  ],
505
519
  }),
506
520
  create("div", {
@@ -547,25 +561,30 @@ function createPropertyDiscriminator(
547
561
  }
548
562
 
549
563
  return create("div", {
550
- className: "openapi-discriminator__item",
564
+ className: "openapi-discriminator__item openapi-schema__list-item",
551
565
  children: create("div", {
552
566
  children: [
553
- create("strong", { style: { paddingLeft: "1rem" }, children: name }),
554
- guard(schemaName, (name) =>
555
- create("span", {
556
- style: { opacity: "0.6" },
557
- children: ` ${schemaName}`,
558
- })
559
- ),
560
- guard(required, () => [
561
- create("strong", {
562
- style: {
563
- fontSize: "var(--ifm-code-font-size)",
564
- color: "var(--openapi-required)",
565
- },
566
- children: " required",
567
- }),
568
- ]),
567
+ create("span", {
568
+ className: "openapi-schema__container",
569
+ children: [
570
+ create("strong", {
571
+ className: "openapi-discriminator__name openapi-schema__property",
572
+ children: name,
573
+ }),
574
+ guard(schemaName, (name) =>
575
+ create("span", {
576
+ className: "openapi-schema__name",
577
+ children: ` ${schemaName}`,
578
+ })
579
+ ),
580
+ guard(required, () => [
581
+ create("span", {
582
+ className: "openapi-schema__required",
583
+ children: "required",
584
+ }),
585
+ ]),
586
+ ],
587
+ }),
569
588
  guard(getQualifierMessage(discriminator), (message) =>
570
589
  create("div", {
571
590
  style: {
@@ -876,22 +895,23 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
876
895
  value: `${mimeType}`,
877
896
  children: [
878
897
  createDetails({
879
- className: "openapi-markdown__details",
898
+ className: "openapi-markdown__details mime",
880
899
  "data-collapsed": false,
881
900
  open: true,
882
901
  ...rest,
883
902
  children: [
884
903
  createDetailsSummary({
885
- style: { textAlign: "left" },
904
+ className: "openapi-markdown__details-summary-mime",
886
905
  children: [
887
- create("strong", { children: `${title}` }),
906
+ create("h3", {
907
+ className:
908
+ "openapi-markdown__details-summary-header-body",
909
+ children: `${title}`,
910
+ }),
888
911
  guard(body.required && body.required === true, () => [
889
- create("strong", {
890
- style: {
891
- fontSize: "var(--ifm-code-font-size)",
892
- color: "var(--openapi-required)",
893
- },
894
- children: " required",
912
+ create("span", {
913
+ className: "openapi-schema__required",
914
+ children: "required",
895
915
  }),
896
916
  ]),
897
917
  ],
@@ -941,15 +961,18 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
941
961
  value: `${randomFirstKey}-schema`,
942
962
  children: [
943
963
  createDetails({
944
- className: "openapi-markdown__details",
964
+ className: "openapi-markdown__details mime",
945
965
  "data-collapsed": false,
946
966
  open: true,
947
967
  ...rest,
948
968
  children: [
949
969
  createDetailsSummary({
950
- style: { textAlign: "left" },
970
+ className: "openapi-markdown__details-summary-mime",
951
971
  children: [
952
- create("strong", { children: `${title}` }),
972
+ create("h3", {
973
+ className: "openapi-markdown__details-summary-header-body",
974
+ children: `${title}`,
975
+ }),
953
976
  guard(firstBody.type === "array", (format) =>
954
977
  create("span", {
955
978
  style: { opacity: "0.6" },
@@ -958,11 +981,8 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
958
981
  ),
959
982
  guard(body.required, () => [
960
983
  create("strong", {
961
- style: {
962
- fontSize: "var(--ifm-code-font-size)",
963
- color: "var(--openapi-required)",
964
- },
965
- children: " required",
984
+ className: "openapi-schema__required",
985
+ children: "required",
966
986
  }),
967
987
  ]),
968
988
  ],
@@ -5,6 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
+ import clsx from "clsx";
9
+
8
10
  import { MediaTypeObject, SchemaObject } from "../openapi/types";
9
11
  import {
10
12
  createClosingArrayBracket,
@@ -58,14 +60,13 @@ export function mergeAllOf(allOf: SchemaObject[]) {
58
60
  */
59
61
  function createAnyOneOf(schema: SchemaObject): any {
60
62
  const type = schema.oneOf ? "oneOf" : "anyOf";
61
- return create("li", {
63
+ return create("div", {
62
64
  children: [
63
65
  create("span", {
64
66
  className: "badge badge--info",
65
67
  children: type,
66
68
  }),
67
69
  create("SchemaTabs", {
68
- className: "openapi-tabs__schema",
69
70
  children: schema[type]!.map((anyOneSchema, index) => {
70
71
  const label = anyOneSchema.title
71
72
  ? anyOneSchema.title
@@ -74,14 +75,17 @@ function createAnyOneOf(schema: SchemaObject): any {
74
75
 
75
76
  if (anyOneSchema.properties !== undefined) {
76
77
  anyOneChildren.push(createProperties(anyOneSchema));
78
+ delete anyOneSchema.properties;
77
79
  }
78
80
 
79
81
  if (anyOneSchema.allOf !== undefined) {
80
82
  anyOneChildren.push(createNodes(anyOneSchema));
83
+ delete anyOneSchema.allOf;
81
84
  }
82
85
 
83
86
  if (anyOneSchema.items !== undefined) {
84
87
  anyOneChildren.push(createItems(anyOneSchema));
88
+ delete anyOneSchema.items;
85
89
  }
86
90
 
87
91
  if (
@@ -92,7 +96,6 @@ function createAnyOneOf(schema: SchemaObject): any {
92
96
  ) {
93
97
  anyOneChildren.push(createNodes(anyOneSchema));
94
98
  }
95
-
96
99
  if (anyOneChildren.length) {
97
100
  if (schema.type === "array") {
98
101
  return create("TabItem", {
@@ -110,7 +113,7 @@ function createAnyOneOf(schema: SchemaObject): any {
110
113
  return create("TabItem", {
111
114
  label: label,
112
115
  value: `${index}-item-properties`,
113
- children: anyOneChildren,
116
+ children: anyOneChildren.filter(Boolean).flat(),
114
117
  });
115
118
  }
116
119
 
@@ -166,6 +169,18 @@ function createAdditionalProperties(schema: SchemaObject) {
166
169
  // }
167
170
  const additionalProperties = schema.additionalProperties;
168
171
  const type: string | unknown = additionalProperties?.type;
172
+ // Handle free-form objects
173
+ if (String(additionalProperties) === "true" && schema.type === "object") {
174
+ return create("SchemaItem", {
175
+ name: "property name*",
176
+ required: false,
177
+ schemaName: "any",
178
+ qualifierMessage: getQualifierMessage(schema.additionalProperties),
179
+ schema: schema,
180
+ collapsible: false,
181
+ discriminator: false,
182
+ });
183
+ }
169
184
  if (
170
185
  (type === "object" || type === "array") &&
171
186
  (additionalProperties?.properties ||
@@ -175,12 +190,12 @@ function createAdditionalProperties(schema: SchemaObject) {
175
190
  additionalProperties?.oneOf ||
176
191
  additionalProperties?.anyOf)
177
192
  ) {
178
- const title = additionalProperties.title;
179
- const schemaName = title ? `object (${title})` : "object";
193
+ const title = additionalProperties.title as string;
194
+ const schemaName = getSchemaName(additionalProperties);
180
195
  const required = schema.required ?? false;
181
196
  return createDetailsNode(
182
197
  "property name*",
183
- schemaName,
198
+ title ?? schemaName,
184
199
  additionalProperties,
185
200
  required,
186
201
  schema.nullable
@@ -198,51 +213,30 @@ function createAdditionalProperties(schema: SchemaObject) {
198
213
  schema.additionalProperties?.additionalProperties;
199
214
  if (additionalProperties !== undefined) {
200
215
  const type = schema.additionalProperties?.additionalProperties?.type;
201
- const format = schema.additionalProperties?.additionalProperties?.format;
202
- return create("li", {
203
- children: create("div", {
204
- children: [
205
- create("code", { children: `property name*` }),
206
- guard(type, (type) =>
207
- create("span", {
208
- style: { opacity: "0.6" },
209
- children: ` ${type}`,
210
- })
211
- ),
212
- guard(format, (format) =>
213
- create("span", {
214
- style: { opacity: "0.6" },
215
- children: ` (${format})`,
216
- })
217
- ),
218
- guard(getQualifierMessage(schema.additionalProperties), (message) =>
219
- create("div", {
220
- style: { marginTop: "var(--ifm-table-cell-padding)" },
221
- children: createDescription(message),
222
- })
223
- ),
224
- ],
225
- }),
216
+ const schemaName = getSchemaName(
217
+ schema.additionalProperties?.additionalProperties!
218
+ );
219
+ return create("SchemaItem", {
220
+ name: "property name*",
221
+ required: false,
222
+ schemaName: schemaName ?? type,
223
+ qualifierMessage:
224
+ schema.additionalProperties ??
225
+ getQualifierMessage(schema.additionalProperties),
226
+ schema: schema,
227
+ collapsible: false,
228
+ discriminator: false,
226
229
  });
227
230
  }
228
- return create("li", {
229
- children: create("div", {
230
- children: [
231
- create("code", { children: `property name*` }),
232
- guard(type, (type) =>
233
- create("span", {
234
- style: { opacity: "0.6" },
235
- children: ` ${type}`,
236
- })
237
- ),
238
- guard(getQualifierMessage(schema.additionalProperties), (message) =>
239
- create("div", {
240
- style: { marginTop: "var(--ifm-table-cell-padding)" },
241
- children: createDescription(message),
242
- })
243
- ),
244
- ],
245
- }),
231
+ const schemaName = getSchemaName(schema.additionalProperties!);
232
+ return create("SchemaItem", {
233
+ name: "property name*",
234
+ required: false,
235
+ schemaName: schemaName,
236
+ qualifierMessage: getQualifierMessage(schema),
237
+ schema: schema.additionalProperties,
238
+ collapsible: false,
239
+ discriminator: false,
246
240
  });
247
241
  }
248
242
  return Object.entries(schema.additionalProperties!).map(([key, val]) =>
@@ -476,38 +470,56 @@ function createDetailsNode(
476
470
  children: [
477
471
  createDetailsSummary({
478
472
  children: [
479
- create("strong", { children: name }),
480
473
  create("span", {
481
- style: { opacity: "0.6" },
482
- children: ` ${schemaName}`,
483
- }),
484
- guard(
485
- (schema.nullable && schema.nullable === true) ||
486
- (nullable && nullable === true),
487
- () => [
474
+ className: "openapi-schema__container",
475
+ children: [
488
476
  create("strong", {
489
- style: {
490
- fontSize: "var(--ifm-code-font-size)",
491
- color: "var(--openapi-nullable)",
492
- },
493
- children: " nullable",
477
+ className: clsx("openapi-schema__property", {
478
+ "openapi-schema__strikethrough": schema.deprecated,
479
+ }),
480
+ children: name,
494
481
  }),
495
- ]
496
- ),
497
- guard(
498
- Array.isArray(required)
499
- ? required.includes(name)
500
- : required === true,
501
- () => [
502
- create("strong", {
503
- style: {
504
- fontSize: "var(--ifm-code-font-size)",
505
- color: "var(--openapi-required)",
506
- },
507
- children: " required",
482
+ create("span", {
483
+ className: "openapi-schema__name",
484
+ children: ` ${schemaName}`,
508
485
  }),
509
- ]
510
- ),
486
+ guard(
487
+ (Array.isArray(required)
488
+ ? required.includes(name)
489
+ : required === true) ||
490
+ schema.deprecated ||
491
+ nullable,
492
+ () => [
493
+ create("span", {
494
+ className: "openapi-schema__divider",
495
+ }),
496
+ ]
497
+ ),
498
+ guard(nullable, () => [
499
+ create("span", {
500
+ className: "openapi-schema__nullable",
501
+ children: "nullable",
502
+ }),
503
+ ]),
504
+ guard(
505
+ Array.isArray(required)
506
+ ? required.includes(name)
507
+ : required === true,
508
+ () => [
509
+ create("span", {
510
+ className: "openapi-schema__required",
511
+ children: "required",
512
+ }),
513
+ ]
514
+ ),
515
+ guard(schema.deprecated, () => [
516
+ create("span", {
517
+ className: "openapi-schema__deprecated",
518
+ children: "deprecated",
519
+ }),
520
+ ]),
521
+ ],
522
+ }),
511
523
  ],
512
524
  }),
513
525
  create("div", {
@@ -554,25 +566,30 @@ function createPropertyDiscriminator(
554
566
  }
555
567
 
556
568
  return create("div", {
557
- className: "openapi-discriminator__item",
569
+ className: "openapi-discriminator__item openapi-schema__list-item",
558
570
  children: create("div", {
559
571
  children: [
560
- create("strong", { style: { paddingLeft: "1rem" }, children: name }),
561
- guard(schemaName, (name) =>
562
- create("span", {
563
- style: { opacity: "0.6" },
564
- children: ` ${schemaName}`,
565
- })
566
- ),
567
- guard(required, () => [
568
- create("strong", {
569
- style: {
570
- fontSize: "var(--ifm-code-font-size)",
571
- color: "var(--openapi-required)",
572
- },
573
- children: " required",
574
- }),
575
- ]),
572
+ create("span", {
573
+ className: "openapi-schema__container",
574
+ children: [
575
+ create("strong", {
576
+ className: "openapi-discriminator__name openapi-schema__property",
577
+ children: name,
578
+ }),
579
+ guard(schemaName, (name) =>
580
+ create("span", {
581
+ className: "openapi-schema__name",
582
+ children: ` ${schemaName}`,
583
+ })
584
+ ),
585
+ guard(required, () => [
586
+ create("span", {
587
+ className: "openapi-schema__required",
588
+ children: "required",
589
+ }),
590
+ ]),
591
+ ],
592
+ }),
576
593
  guard(getQualifierMessage(discriminator), (message) =>
577
594
  create("div", {
578
595
  style: {
@@ -905,24 +922,22 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
905
922
  value: `${title}`,
906
923
  children: [
907
924
  createDetails({
908
- className: "openapi-markdown__details",
925
+ className: "openapi-markdown__details response",
909
926
  "data-collapsed": false,
910
927
  open: true,
911
928
  ...rest,
912
929
  children: [
913
930
  createDetailsSummary({
914
- style: { textAlign: "left" },
931
+ className:
932
+ "openapi-markdown__details-summary-response",
915
933
  children: [
916
934
  create("strong", { children: `${title}` }),
917
935
  guard(
918
936
  body.required && body.required === true,
919
937
  () => [
920
- create("strong", {
921
- style: {
922
- fontSize: "var(--ifm-code-font-size)",
923
- color: "var(--openapi-required)",
924
- },
925
- children: " required",
938
+ create("span", {
939
+ className: "openapi-schema__required",
940
+ children: "required",
926
941
  }),
927
942
  ]
928
943
  ),