docusaurus-theme-openapi-docs 0.0.0-1005 → 0.0.0-1007
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/lib/theme/Schema/index.js +38 -97
- package/package.json +3 -3
- package/src/theme/Schema/index.tsx +46 -78
|
@@ -114,10 +114,7 @@ const AnyOneOf = ({ schema, schemaType }) => {
|
|
|
114
114
|
react_1.default.createElement(
|
|
115
115
|
TabItem_1.default,
|
|
116
116
|
{ key: index, label: label, value: `${index}-item-properties` },
|
|
117
|
-
(
|
|
118
|
-
anyOneSchema.type
|
|
119
|
-
) ||
|
|
120
|
-
anyOneSchema.const) &&
|
|
117
|
+
(isPrimitive(anyOneSchema) || anyOneSchema.const) &&
|
|
121
118
|
react_1.default.createElement(SchemaItem_1.default, {
|
|
122
119
|
collapsible: false,
|
|
123
120
|
name: undefined,
|
|
@@ -484,111 +481,45 @@ const SchemaNodeDetails = ({
|
|
|
484
481
|
);
|
|
485
482
|
};
|
|
486
483
|
const Items = ({ schema, schemaType }) => {
|
|
487
|
-
//
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
null,
|
|
492
|
-
react_1.default.createElement(ArrayBrackets_1.OpeningArrayBracket, null),
|
|
493
|
-
react_1.default.createElement(Properties, {
|
|
494
|
-
schema: schema.items,
|
|
495
|
-
schemaType: schemaType,
|
|
496
|
-
}),
|
|
497
|
-
react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
// Handles case when schema.items has additionalProperties
|
|
501
|
-
if (schema.items?.additionalProperties) {
|
|
502
|
-
return react_1.default.createElement(
|
|
503
|
-
react_1.default.Fragment,
|
|
504
|
-
null,
|
|
505
|
-
react_1.default.createElement(ArrayBrackets_1.OpeningArrayBracket, null),
|
|
506
|
-
react_1.default.createElement(AdditionalProperties, {
|
|
507
|
-
schema: schema.items,
|
|
508
|
-
schemaType: schemaType,
|
|
509
|
-
}),
|
|
510
|
-
react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
|
|
511
|
-
);
|
|
484
|
+
// Process schema.items to handle allOf merging
|
|
485
|
+
let itemsSchema = schema.items;
|
|
486
|
+
if (schema.items?.allOf) {
|
|
487
|
+
itemsSchema = mergeAllOf(schema.items);
|
|
512
488
|
}
|
|
513
|
-
//
|
|
514
|
-
|
|
489
|
+
// Handle complex schemas with multiple schema types
|
|
490
|
+
const hasOneOfAnyOf = itemsSchema?.oneOf || itemsSchema?.anyOf;
|
|
491
|
+
const hasProperties = itemsSchema?.properties;
|
|
492
|
+
const hasAdditionalProperties = itemsSchema?.additionalProperties;
|
|
493
|
+
if (hasOneOfAnyOf || hasProperties || hasAdditionalProperties) {
|
|
515
494
|
return react_1.default.createElement(
|
|
516
495
|
react_1.default.Fragment,
|
|
517
496
|
null,
|
|
518
497
|
react_1.default.createElement(ArrayBrackets_1.OpeningArrayBracket, null),
|
|
519
|
-
|
|
520
|
-
schema: schema.items,
|
|
521
|
-
schemaType: schemaType,
|
|
522
|
-
}),
|
|
523
|
-
react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
|
-
// Handles case when schema.items has allOf
|
|
527
|
-
if (schema.items?.allOf) {
|
|
528
|
-
const mergedSchemas = mergeAllOf(schema.items);
|
|
529
|
-
// Handles combo anyOf/oneOf + properties
|
|
530
|
-
if (
|
|
531
|
-
(mergedSchemas.oneOf || mergedSchemas.anyOf) &&
|
|
532
|
-
mergedSchemas.properties
|
|
533
|
-
) {
|
|
534
|
-
return react_1.default.createElement(
|
|
535
|
-
react_1.default.Fragment,
|
|
536
|
-
null,
|
|
537
|
-
react_1.default.createElement(
|
|
538
|
-
ArrayBrackets_1.OpeningArrayBracket,
|
|
539
|
-
null
|
|
540
|
-
),
|
|
498
|
+
hasOneOfAnyOf &&
|
|
541
499
|
react_1.default.createElement(AnyOneOf, {
|
|
542
|
-
schema:
|
|
500
|
+
schema: itemsSchema,
|
|
543
501
|
schemaType: schemaType,
|
|
544
502
|
}),
|
|
503
|
+
hasProperties &&
|
|
545
504
|
react_1.default.createElement(Properties, {
|
|
546
|
-
schema:
|
|
505
|
+
schema: itemsSchema,
|
|
547
506
|
schemaType: schemaType,
|
|
548
507
|
}),
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
// Handles only anyOf/oneOf
|
|
553
|
-
if (mergedSchemas.oneOf || mergedSchemas.anyOf) {
|
|
554
|
-
return react_1.default.createElement(
|
|
555
|
-
react_1.default.Fragment,
|
|
556
|
-
null,
|
|
557
|
-
react_1.default.createElement(
|
|
558
|
-
ArrayBrackets_1.OpeningArrayBracket,
|
|
559
|
-
null
|
|
560
|
-
),
|
|
561
|
-
react_1.default.createElement(AnyOneOf, {
|
|
562
|
-
schema: mergedSchemas,
|
|
508
|
+
hasAdditionalProperties &&
|
|
509
|
+
react_1.default.createElement(AdditionalProperties, {
|
|
510
|
+
schema: itemsSchema,
|
|
563
511
|
schemaType: schemaType,
|
|
564
512
|
}),
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
// Handles properties
|
|
569
|
-
if (mergedSchemas.properties) {
|
|
570
|
-
return react_1.default.createElement(
|
|
571
|
-
react_1.default.Fragment,
|
|
572
|
-
null,
|
|
573
|
-
react_1.default.createElement(
|
|
574
|
-
ArrayBrackets_1.OpeningArrayBracket,
|
|
575
|
-
null
|
|
576
|
-
),
|
|
577
|
-
react_1.default.createElement(Properties, {
|
|
578
|
-
schema: mergedSchemas,
|
|
579
|
-
schemaType: schemaType,
|
|
580
|
-
}),
|
|
581
|
-
react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
|
|
582
|
-
);
|
|
583
|
-
}
|
|
513
|
+
react_1.default.createElement(ArrayBrackets_1.ClosingArrayBracket, null)
|
|
514
|
+
);
|
|
584
515
|
}
|
|
585
516
|
// Handles basic types (string, number, integer, boolean, object)
|
|
586
517
|
if (
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
518
|
+
itemsSchema?.type === "string" ||
|
|
519
|
+
itemsSchema?.type === "number" ||
|
|
520
|
+
itemsSchema?.type === "integer" ||
|
|
521
|
+
itemsSchema?.type === "boolean" ||
|
|
522
|
+
itemsSchema?.type === "object"
|
|
592
523
|
) {
|
|
593
524
|
return react_1.default.createElement(
|
|
594
525
|
"div",
|
|
@@ -597,9 +528,9 @@ const Items = ({ schema, schemaType }) => {
|
|
|
597
528
|
react_1.default.createElement(SchemaItem_1.default, {
|
|
598
529
|
collapsible: false,
|
|
599
530
|
name: "", // No name for array items
|
|
600
|
-
schemaName: (0, schema_1.getSchemaName)(
|
|
601
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(
|
|
602
|
-
schema:
|
|
531
|
+
schemaName: (0, schema_1.getSchemaName)(itemsSchema),
|
|
532
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(itemsSchema),
|
|
533
|
+
schema: itemsSchema,
|
|
603
534
|
discriminator: false,
|
|
604
535
|
children: null,
|
|
605
536
|
}),
|
|
@@ -611,7 +542,7 @@ const Items = ({ schema, schemaType }) => {
|
|
|
611
542
|
react_1.default.Fragment,
|
|
612
543
|
null,
|
|
613
544
|
react_1.default.createElement(ArrayBrackets_1.OpeningArrayBracket, null),
|
|
614
|
-
Object.entries(
|
|
545
|
+
Object.entries(itemsSchema || {}).map(([key, val]) =>
|
|
615
546
|
react_1.default.createElement(SchemaEdge, {
|
|
616
547
|
key: key,
|
|
617
548
|
name: key,
|
|
@@ -884,3 +815,13 @@ const SchemaNode = ({ schema, schemaType }) => {
|
|
|
884
815
|
return renderChildren(schema, schemaType);
|
|
885
816
|
};
|
|
886
817
|
exports.default = SchemaNode;
|
|
818
|
+
const PRIMITIVE_TYPES = {
|
|
819
|
+
string: true,
|
|
820
|
+
number: true,
|
|
821
|
+
integer: true,
|
|
822
|
+
boolean: true,
|
|
823
|
+
null: true,
|
|
824
|
+
};
|
|
825
|
+
const isPrimitive = (schema) => {
|
|
826
|
+
return PRIMITIVE_TYPES[schema.type];
|
|
827
|
+
};
|
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-
|
|
4
|
+
"version": "0.0.0-1007",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/lodash": "^4.14.176",
|
|
37
37
|
"@types/pako": "^2.0.3",
|
|
38
38
|
"concurrently": "^5.2.0",
|
|
39
|
-
"docusaurus-plugin-openapi-docs": "0.0.0-
|
|
39
|
+
"docusaurus-plugin-openapi-docs": "0.0.0-1007",
|
|
40
40
|
"docusaurus-plugin-sass": "^0.2.3",
|
|
41
41
|
"eslint-plugin-prettier": "^5.0.1"
|
|
42
42
|
},
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"engines": {
|
|
80
80
|
"node": ">=14"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "864d5355b98d552679472455f533ef15313a0bee"
|
|
83
83
|
}
|
|
@@ -21,7 +21,10 @@ import {
|
|
|
21
21
|
getQualifierMessage,
|
|
22
22
|
getSchemaName,
|
|
23
23
|
} from "docusaurus-plugin-openapi-docs/lib/markdown/schema";
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
SchemaObject,
|
|
26
|
+
SchemaType,
|
|
27
|
+
} from "docusaurus-plugin-openapi-docs/lib/openapi/types";
|
|
25
28
|
import isEmpty from "lodash/isEmpty";
|
|
26
29
|
|
|
27
30
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
@@ -122,10 +125,7 @@ const AnyOneOf: React.FC<SchemaProps> = ({ schema, schemaType }) => {
|
|
|
122
125
|
value={`${index}-item-properties`}
|
|
123
126
|
>
|
|
124
127
|
{/* Handle primitive types directly */}
|
|
125
|
-
{(
|
|
126
|
-
anyOneSchema.type
|
|
127
|
-
) ||
|
|
128
|
-
anyOneSchema.const) && (
|
|
128
|
+
{(isPrimitive(anyOneSchema) || anyOneSchema.const) && (
|
|
129
129
|
<SchemaItem
|
|
130
130
|
collapsible={false}
|
|
131
131
|
name={undefined}
|
|
@@ -504,88 +504,42 @@ const Items: React.FC<{
|
|
|
504
504
|
schema: any;
|
|
505
505
|
schemaType: "request" | "response";
|
|
506
506
|
}> = ({ schema, schemaType }) => {
|
|
507
|
-
//
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
<OpeningArrayBracket />
|
|
512
|
-
<Properties schema={schema.items} schemaType={schemaType} />
|
|
513
|
-
<ClosingArrayBracket />
|
|
514
|
-
</>
|
|
515
|
-
);
|
|
507
|
+
// Process schema.items to handle allOf merging
|
|
508
|
+
let itemsSchema = schema.items;
|
|
509
|
+
if (schema.items?.allOf) {
|
|
510
|
+
itemsSchema = mergeAllOf(schema.items) as SchemaObject;
|
|
516
511
|
}
|
|
517
512
|
|
|
518
|
-
//
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
<OpeningArrayBracket />
|
|
523
|
-
<AdditionalProperties schema={schema.items} schemaType={schemaType} />
|
|
524
|
-
<ClosingArrayBracket />
|
|
525
|
-
</>
|
|
526
|
-
);
|
|
527
|
-
}
|
|
513
|
+
// Handle complex schemas with multiple schema types
|
|
514
|
+
const hasOneOfAnyOf = itemsSchema?.oneOf || itemsSchema?.anyOf;
|
|
515
|
+
const hasProperties = itemsSchema?.properties;
|
|
516
|
+
const hasAdditionalProperties = itemsSchema?.additionalProperties;
|
|
528
517
|
|
|
529
|
-
|
|
530
|
-
if (schema.items?.oneOf || schema.items?.anyOf) {
|
|
518
|
+
if (hasOneOfAnyOf || hasProperties || hasAdditionalProperties) {
|
|
531
519
|
return (
|
|
532
520
|
<>
|
|
533
521
|
<OpeningArrayBracket />
|
|
534
|
-
|
|
522
|
+
{hasOneOfAnyOf && (
|
|
523
|
+
<AnyOneOf schema={itemsSchema} schemaType={schemaType} />
|
|
524
|
+
)}
|
|
525
|
+
{hasProperties && (
|
|
526
|
+
<Properties schema={itemsSchema} schemaType={schemaType} />
|
|
527
|
+
)}
|
|
528
|
+
{hasAdditionalProperties && (
|
|
529
|
+
<AdditionalProperties schema={itemsSchema} schemaType={schemaType} />
|
|
530
|
+
)}
|
|
535
531
|
<ClosingArrayBracket />
|
|
536
532
|
</>
|
|
537
533
|
);
|
|
538
534
|
}
|
|
539
535
|
|
|
540
|
-
// Handles case when schema.items has allOf
|
|
541
|
-
if (schema.items?.allOf) {
|
|
542
|
-
const mergedSchemas = mergeAllOf(schema.items) as SchemaObject;
|
|
543
|
-
|
|
544
|
-
// Handles combo anyOf/oneOf + properties
|
|
545
|
-
if (
|
|
546
|
-
(mergedSchemas.oneOf || mergedSchemas.anyOf) &&
|
|
547
|
-
mergedSchemas.properties
|
|
548
|
-
) {
|
|
549
|
-
return (
|
|
550
|
-
<>
|
|
551
|
-
<OpeningArrayBracket />
|
|
552
|
-
<AnyOneOf schema={mergedSchemas} schemaType={schemaType} />
|
|
553
|
-
<Properties schema={mergedSchemas} schemaType={schemaType} />
|
|
554
|
-
<ClosingArrayBracket />
|
|
555
|
-
</>
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
// Handles only anyOf/oneOf
|
|
560
|
-
if (mergedSchemas.oneOf || mergedSchemas.anyOf) {
|
|
561
|
-
return (
|
|
562
|
-
<>
|
|
563
|
-
<OpeningArrayBracket />
|
|
564
|
-
<AnyOneOf schema={mergedSchemas} schemaType={schemaType} />
|
|
565
|
-
<ClosingArrayBracket />
|
|
566
|
-
</>
|
|
567
|
-
);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// Handles properties
|
|
571
|
-
if (mergedSchemas.properties) {
|
|
572
|
-
return (
|
|
573
|
-
<>
|
|
574
|
-
<OpeningArrayBracket />
|
|
575
|
-
<Properties schema={mergedSchemas} schemaType={schemaType} />
|
|
576
|
-
<ClosingArrayBracket />
|
|
577
|
-
</>
|
|
578
|
-
);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
536
|
// Handles basic types (string, number, integer, boolean, object)
|
|
583
537
|
if (
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
538
|
+
itemsSchema?.type === "string" ||
|
|
539
|
+
itemsSchema?.type === "number" ||
|
|
540
|
+
itemsSchema?.type === "integer" ||
|
|
541
|
+
itemsSchema?.type === "boolean" ||
|
|
542
|
+
itemsSchema?.type === "object"
|
|
589
543
|
) {
|
|
590
544
|
return (
|
|
591
545
|
<div style={{ marginLeft: ".5rem" }}>
|
|
@@ -593,9 +547,9 @@ const Items: React.FC<{
|
|
|
593
547
|
<SchemaItem
|
|
594
548
|
collapsible={false}
|
|
595
549
|
name="" // No name for array items
|
|
596
|
-
schemaName={getSchemaName(
|
|
597
|
-
qualifierMessage={getQualifierMessage(
|
|
598
|
-
schema={
|
|
550
|
+
schemaName={getSchemaName(itemsSchema)}
|
|
551
|
+
qualifierMessage={getQualifierMessage(itemsSchema)}
|
|
552
|
+
schema={itemsSchema}
|
|
599
553
|
discriminator={false}
|
|
600
554
|
children={null}
|
|
601
555
|
/>
|
|
@@ -608,7 +562,7 @@ const Items: React.FC<{
|
|
|
608
562
|
return (
|
|
609
563
|
<>
|
|
610
564
|
<OpeningArrayBracket />
|
|
611
|
-
{Object.entries(
|
|
565
|
+
{Object.entries(itemsSchema || {}).map(([key, val]: [string, any]) => (
|
|
612
566
|
<SchemaEdge
|
|
613
567
|
key={key}
|
|
614
568
|
name={key}
|
|
@@ -938,3 +892,17 @@ const SchemaNode: React.FC<SchemaProps> = ({ schema, schemaType }) => {
|
|
|
938
892
|
};
|
|
939
893
|
|
|
940
894
|
export default SchemaNode;
|
|
895
|
+
|
|
896
|
+
type PrimitiveSchemaType = Exclude<SchemaType, "object" | "array">;
|
|
897
|
+
|
|
898
|
+
const PRIMITIVE_TYPES: Record<PrimitiveSchemaType, true> = {
|
|
899
|
+
string: true,
|
|
900
|
+
number: true,
|
|
901
|
+
integer: true,
|
|
902
|
+
boolean: true,
|
|
903
|
+
null: true,
|
|
904
|
+
} as const;
|
|
905
|
+
|
|
906
|
+
const isPrimitive = (schema: SchemaObject) => {
|
|
907
|
+
return PRIMITIVE_TYPES[schema.type as PrimitiveSchemaType];
|
|
908
|
+
};
|