Skip to content

Commit b7872d6

Browse files
authored
Merge pull request #985 from PaloAltoNetworks/edge-allof
Combines mergedSchemas with original to ensure no edge properties are lost in schema item
2 parents 6f7b058 + 1283280 commit b7872d6

File tree

2 files changed

+51
-17
lines changed
  • packages

2 files changed

+51
-17
lines changed

packages/docusaurus-plugin-openapi-docs/src/markdown/createSchema.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -687,50 +687,57 @@ function createEdges({
687687
const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
688688
schema.allOf
689689
);
690+
delete schema.allOf;
691+
const combinedSchemas = { ...schema, ...mergedSchemas };
690692

691693
if (SCHEMA_TYPE === "request") {
692-
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
694+
if (combinedSchemas.readOnly && combinedSchemas.readOnly === true) {
693695
return undefined;
694696
}
695697
}
696698

697699
if (SCHEMA_TYPE === "response") {
698-
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
700+
if (combinedSchemas.writeOnly && combinedSchemas.writeOnly === true) {
699701
return undefined;
700702
}
701703
}
702704

703-
const mergedSchemaName = getSchemaName(mergedSchemas);
705+
const mergedSchemaName = getSchemaName(combinedSchemas);
706+
707+
if (name === "eventName") {
708+
console.log(mergedSchemaName, combinedSchemas);
709+
}
710+
704711
if (
705-
mergedSchemas.oneOf !== undefined ||
706-
mergedSchemas.anyOf !== undefined
712+
combinedSchemas.oneOf !== undefined ||
713+
combinedSchemas.anyOf !== undefined
707714
) {
708715
return createDetailsNode(
709716
name,
710717
mergedSchemaName,
711-
mergedSchemas,
718+
combinedSchemas,
712719
required,
713-
schema.nullable
720+
combinedSchemas.nullable
714721
);
715722
}
716723

717-
if (mergedSchemas.properties !== undefined) {
724+
if (combinedSchemas.properties !== undefined) {
718725
return createDetailsNode(
719726
name,
720727
mergedSchemaName,
721-
mergedSchemas,
728+
combinedSchemas,
722729
required,
723-
schema.nullable
730+
combinedSchemas.nullable
724731
);
725732
}
726733

727-
if (mergedSchemas.additionalProperties !== undefined) {
734+
if (combinedSchemas.additionalProperties !== undefined) {
728735
return createDetailsNode(
729736
name,
730737
mergedSchemaName,
731-
mergedSchemas,
738+
combinedSchemas,
732739
required,
733-
schema.nullable
740+
combinedSchemas.nullable
734741
);
735742
}
736743

@@ -739,9 +746,9 @@ function createEdges({
739746
return createDetailsNode(
740747
name,
741748
mergedSchemaName,
742-
mergedSchemas,
749+
combinedSchemas,
743750
required,
744-
schema.nullable
751+
combinedSchemas.nullable
745752
);
746753
}
747754

@@ -750,8 +757,8 @@ function createEdges({
750757
name,
751758
required: Array.isArray(required) ? required.includes(name) : required,
752759
schemaName: mergedSchemaName,
753-
qualifierMessage: getQualifierMessage(mergedSchemas),
754-
schema: mergedSchemas,
760+
qualifierMessage: getQualifierMessage(combinedSchemas),
761+
schema: combinedSchemas,
755762
});
756763
}
757764

packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem/index.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default function SchemaItem(props: Props) {
6666
let deprecated;
6767
let schemaDescription;
6868
let defaultValue: string | undefined;
69+
let example: string | undefined;
6970
let nullable;
7071
let enumDescriptions: [string, string][] = [];
7172

@@ -74,6 +75,7 @@ export default function SchemaItem(props: Props) {
7475
schemaDescription = schema.description;
7576
enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
7677
defaultValue = schema.default;
78+
example = schema.example;
7779
nullable = schema.nullable;
7880
}
7981

@@ -157,6 +159,30 @@ export default function SchemaItem(props: Props) {
157159
return undefined;
158160
}
159161

162+
function renderExample() {
163+
if (example !== undefined) {
164+
if (typeof example === "string") {
165+
return (
166+
<div>
167+
<strong>Example: </strong>
168+
<span>
169+
<code>{example}</code>
170+
</span>
171+
</div>
172+
);
173+
}
174+
return (
175+
<div>
176+
<strong>Example: </strong>
177+
<span>
178+
<code>{JSON.stringify(example)}</code>
179+
</span>
180+
</div>
181+
);
182+
}
183+
return undefined;
184+
}
185+
160186
const schemaContent = (
161187
<div>
162188
<span className="openapi-schema__container">
@@ -179,6 +205,7 @@ export default function SchemaItem(props: Props) {
179205
{renderEnumDescriptions}
180206
{renderQualifierMessage}
181207
{renderDefaultValue()}
208+
{renderExample()}
182209
{collapsibleSchemaContent ?? collapsibleSchemaContent}
183210
</div>
184211
);

0 commit comments

Comments
 (0)