Skip to content

Commit

Permalink
Merge pull request #985 from PaloAltoNetworks/edge-allof
Browse files Browse the repository at this point in the history
Combines mergedSchemas with original to ensure no edge properties are lost in schema item
  • Loading branch information
sserrata authored Oct 4, 2024
2 parents 6f7b058 + 1283280 commit b7872d6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -687,50 +687,57 @@ function createEdges({
const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
schema.allOf
);
delete schema.allOf;
const combinedSchemas = { ...schema, ...mergedSchemas };

if (SCHEMA_TYPE === "request") {
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
if (combinedSchemas.readOnly && combinedSchemas.readOnly === true) {
return undefined;
}
}

if (SCHEMA_TYPE === "response") {
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
if (combinedSchemas.writeOnly && combinedSchemas.writeOnly === true) {
return undefined;
}
}

const mergedSchemaName = getSchemaName(mergedSchemas);
const mergedSchemaName = getSchemaName(combinedSchemas);

if (name === "eventName") {
console.log(mergedSchemaName, combinedSchemas);
}

if (
mergedSchemas.oneOf !== undefined ||
mergedSchemas.anyOf !== undefined
combinedSchemas.oneOf !== undefined ||
combinedSchemas.anyOf !== undefined
) {
return createDetailsNode(
name,
mergedSchemaName,
mergedSchemas,
combinedSchemas,
required,
schema.nullable
combinedSchemas.nullable
);
}

if (mergedSchemas.properties !== undefined) {
if (combinedSchemas.properties !== undefined) {
return createDetailsNode(
name,
mergedSchemaName,
mergedSchemas,
combinedSchemas,
required,
schema.nullable
combinedSchemas.nullable
);
}

if (mergedSchemas.additionalProperties !== undefined) {
if (combinedSchemas.additionalProperties !== undefined) {
return createDetailsNode(
name,
mergedSchemaName,
mergedSchemas,
combinedSchemas,
required,
schema.nullable
combinedSchemas.nullable
);
}

Expand All @@ -739,9 +746,9 @@ function createEdges({
return createDetailsNode(
name,
mergedSchemaName,
mergedSchemas,
combinedSchemas,
required,
schema.nullable
combinedSchemas.nullable
);
}

Expand All @@ -750,8 +757,8 @@ function createEdges({
name,
required: Array.isArray(required) ? required.includes(name) : required,
schemaName: mergedSchemaName,
qualifierMessage: getQualifierMessage(mergedSchemas),
schema: mergedSchemas,
qualifierMessage: getQualifierMessage(combinedSchemas),
schema: combinedSchemas,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default function SchemaItem(props: Props) {
let deprecated;
let schemaDescription;
let defaultValue: string | undefined;
let example: string | undefined;
let nullable;
let enumDescriptions: [string, string][] = [];

Expand All @@ -74,6 +75,7 @@ export default function SchemaItem(props: Props) {
schemaDescription = schema.description;
enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
defaultValue = schema.default;
example = schema.example;
nullable = schema.nullable;
}

Expand Down Expand Up @@ -157,6 +159,30 @@ export default function SchemaItem(props: Props) {
return undefined;
}

function renderExample() {
if (example !== undefined) {
if (typeof example === "string") {
return (
<div>
<strong>Example: </strong>
<span>
<code>{example}</code>
</span>
</div>
);
}
return (
<div>
<strong>Example: </strong>
<span>
<code>{JSON.stringify(example)}</code>
</span>
</div>
);
}
return undefined;
}

const schemaContent = (
<div>
<span className="openapi-schema__container">
Expand All @@ -179,6 +205,7 @@ export default function SchemaItem(props: Props) {
{renderEnumDescriptions}
{renderQualifierMessage}
{renderDefaultValue()}
{renderExample()}
{collapsibleSchemaContent ?? collapsibleSchemaContent}
</div>
);
Expand Down

0 comments on commit b7872d6

Please sign in to comment.