Skip to content

Commit

Permalink
Merge pull request #114 from ethdebug/schema-retitle-fix
Browse files Browse the repository at this point in the history
Fix display of schema extensions that change only title
  • Loading branch information
gnidan authored Oct 31, 2024
2 parents 1fddb29 + 9a2060a commit c31265a
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ export default function UnnecessaryCompositionSchema({
);

if (onlyExtendsDocumentation) {
const onlyChangesTitle = Object.keys(documentation).length === 1 &&
"title" in documentation;

if (onlyChangesTitle) {
return <>
<SchemaHierarchyComponent
innerJsonPointer={`/${unnecessaryCompositionKeyword}/0`}
>
<CreateNodes schema={unnecessarilyComposedSchema} />
</SchemaHierarchyComponent>
</>;
}

const { description } = documentation;

return <>
Expand Down Expand Up @@ -166,7 +179,7 @@ export default function UnnecessaryCompositionSchema({

function separateDocumentationFromSemantics(schema: JSONSchema): {
documentation: Exclude<JSONSchema, boolean>,
semantics: Exclude<JSONSchema, boolean>
semantics: JSONSchema
} {
if (typeof schema === "boolean") {
return {
Expand All @@ -185,13 +198,19 @@ function separateDocumentationFromSemantics(schema: JSONSchema): {
...semantics
} = schema;

const documentation = Object.entries({
title,
description,
examples,
default: default_
}).filter((
pair: [string, string | object | undefined]
): pair is [string, string | object] => pair[1] !== undefined).map(
([key, value]) => ({ [key]: value })
).reduce((a, b) => ({ ...a, ...b }), {}) as Partial<Pick<typeof schema, "title" | "description" | "examples" | "default">>;

return {
documentation: {
title,
description,
examples,
default: default_
},
documentation,
semantics
};
}

0 comments on commit c31265a

Please sign in to comment.