Skip to content

Commit c31265a

Browse files
authored
Merge pull request #114 from ethdebug/schema-retitle-fix
Fix display of schema extensions that change only title
2 parents 1fddb29 + 9a2060a commit c31265a

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

packages/web/src/theme/JSONSchemaViewer/components/UnnecessaryComposition.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ export default function UnnecessaryCompositionSchema({
9696
);
9797

9898
if (onlyExtendsDocumentation) {
99+
const onlyChangesTitle = Object.keys(documentation).length === 1 &&
100+
"title" in documentation;
101+
102+
if (onlyChangesTitle) {
103+
return <>
104+
<SchemaHierarchyComponent
105+
innerJsonPointer={`/${unnecessaryCompositionKeyword}/0`}
106+
>
107+
<CreateNodes schema={unnecessarilyComposedSchema} />
108+
</SchemaHierarchyComponent>
109+
</>;
110+
}
111+
99112
const { description } = documentation;
100113

101114
return <>
@@ -166,7 +179,7 @@ export default function UnnecessaryCompositionSchema({
166179

167180
function separateDocumentationFromSemantics(schema: JSONSchema): {
168181
documentation: Exclude<JSONSchema, boolean>,
169-
semantics: Exclude<JSONSchema, boolean>
182+
semantics: JSONSchema
170183
} {
171184
if (typeof schema === "boolean") {
172185
return {
@@ -185,13 +198,19 @@ function separateDocumentationFromSemantics(schema: JSONSchema): {
185198
...semantics
186199
} = schema;
187200

201+
const documentation = Object.entries({
202+
title,
203+
description,
204+
examples,
205+
default: default_
206+
}).filter((
207+
pair: [string, string | object | undefined]
208+
): pair is [string, string | object] => pair[1] !== undefined).map(
209+
([key, value]) => ({ [key]: value })
210+
).reduce((a, b) => ({ ...a, ...b }), {}) as Partial<Pick<typeof schema, "title" | "description" | "examples" | "default">>;
211+
188212
return {
189-
documentation: {
190-
title,
191-
description,
192-
examples,
193-
default: default_
194-
},
213+
documentation,
195214
semantics
196215
};
197216
}

0 commit comments

Comments
 (0)