Skip to content

Commit 9363fd4

Browse files
committed
Fix display bug for properties that don't show.
Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
1 parent da17df9 commit 9363fd4

File tree

1 file changed

+88
-57
lines changed

1 file changed

+88
-57
lines changed

src/components/ParserOpenRPC/DetailsBox/RenderParams.tsx

Lines changed: 88 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,54 @@ const renderSchema = (
125125
return renderObject(schemaItem, name || schemaItem.title)
126126
}
127127

128+
// Helper function to check if oneOf should be flattened for results
129+
const shouldFlattenOneOf = (oneOfArray, isResultSchema) => {
130+
if (!isResultSchema || !Array.isArray(oneOfArray) || oneOfArray.length !== 2) {
131+
return null
132+
}
133+
134+
// Filter out "empty" responses (notFound, null, etc.)
135+
const meaningfulOptions = oneOfArray.filter(option => {
136+
// Skip notFound references
137+
if (option.$ref?.includes('notFound')) return false
138+
if (option.$ref?.includes('null')) return false
139+
// Skip null types
140+
if (option.type === 'null') return false
141+
// Keep actual data structures
142+
return true
143+
})
144+
145+
// If exactly one meaningful option remains, return it for flattening
146+
if (meaningfulOptions.length === 1) {
147+
return meaningfulOptions[0]
148+
}
149+
150+
return null
151+
}
152+
153+
const renderCombinations = (item, itemName, type) => (
154+
<div>
155+
<SchemaProperty
156+
title={itemName || item.title}
157+
type={type}
158+
required={schemaItem.required || !!item.required}
159+
description={item.description || item.title || ''}
160+
pattern={item.pattern}
161+
defaultVal={item.default}
162+
showRequired={showRequired}
163+
/>
164+
<div className="padding-bottom--md">
165+
<CollapseBox isInitExpanded={false}>
166+
{item[type].map((option, index) => (
167+
<div key={`${index}`} className={styles.paramItemWrapper}>
168+
{renderSchema(option, schemas, option.title, showRequired, isExpandedByDefault)}
169+
</div>
170+
))}
171+
</CollapseBox>
172+
</div>
173+
</div>
174+
)
175+
128176
const renderArray = (item, itemName) => {
129177
const arrayType = getArrayTypeDescription(item.items, schemas)
130178

@@ -141,14 +189,16 @@ const renderSchema = (
141189

142190
// Helper function to render object properties directly (flatter structure)
143191
const renderObjectProperties = objectSchema => {
144-
if (!objectSchema || !objectSchema.properties) return null
192+
if (!objectSchema) return null
145193

146-
const requiredFields = Array.isArray(objectSchema.required) ? objectSchema.required : []
194+
const elements = []
147195

148-
return (
149-
<>
150-
{Object.entries(objectSchema.properties).map(
151-
([key, value]: [string, SchemaPropertyType]) => (
196+
// Render direct properties first
197+
if (objectSchema.properties) {
198+
const requiredFields = Array.isArray(objectSchema.required) ? objectSchema.required : []
199+
Object.entries(objectSchema.properties).forEach(
200+
([key, value]: [string, SchemaPropertyType]) => {
201+
elements.push(
152202
<div key={key} className={styles.paramItemWrapper}>
153203
{renderSchema(
154204
{
@@ -162,9 +212,38 @@ const renderSchema = (
162212
)}
163213
</div>
164214
)
165-
)}
166-
</>
167-
)
215+
}
216+
)
217+
}
218+
219+
// Handle combination schemas (oneOf/anyOf/allOf) within the same object
220+
// This is important for complex structures like Linea transaction objects
221+
if (objectSchema.oneOf) {
222+
elements.push(
223+
<div key="oneOf-variations" className={styles.paramItemWrapper}>
224+
<h6 className="type-paragraph-s font-primary font-weight-medium">Transaction Types:</h6>
225+
{renderCombinations(objectSchema, 'Transaction Types', 'oneOf')}
226+
</div>
227+
)
228+
}
229+
230+
if (objectSchema.anyOf) {
231+
elements.push(
232+
<div key="anyOf-variations" className={styles.paramItemWrapper}>
233+
{renderCombinations(objectSchema, 'Variations', 'anyOf')}
234+
</div>
235+
)
236+
}
237+
238+
if (objectSchema.allOf) {
239+
elements.push(
240+
<div key="allOf-variations" className={styles.paramItemWrapper}>
241+
{renderCombinations(objectSchema, 'Combined Types', 'allOf')}
242+
</div>
243+
)
244+
}
245+
246+
return elements.length > 0 ? <>{elements}</> : null
168247
}
169248

170249
return (
@@ -219,54 +298,6 @@ const renderSchema = (
219298
return renderArray(schemaItem.schema, name || schemaItem.schema.title)
220299
}
221300

222-
// Helper function to check if oneOf should be flattened for results
223-
const shouldFlattenOneOf = (oneOfArray, isResultSchema) => {
224-
if (!isResultSchema || !Array.isArray(oneOfArray) || oneOfArray.length !== 2) {
225-
return null
226-
}
227-
228-
// Filter out "empty" responses (notFound, null, etc.)
229-
const meaningfulOptions = oneOfArray.filter(option => {
230-
// Skip notFound references
231-
if (option.$ref?.includes('notFound')) return false
232-
if (option.$ref?.includes('null')) return false
233-
// Skip null types
234-
if (option.type === 'null') return false
235-
// Keep actual data structures
236-
return true
237-
})
238-
239-
// If exactly one meaningful option remains, return it for flattening
240-
if (meaningfulOptions.length === 1) {
241-
return meaningfulOptions[0]
242-
}
243-
244-
return null
245-
}
246-
247-
const renderCombinations = (item, itemName, type) => (
248-
<div>
249-
<SchemaProperty
250-
title={itemName || item.title}
251-
type={type}
252-
required={schemaItem.required || !!item.required}
253-
description={item.description || item.title || ''}
254-
pattern={item.pattern}
255-
defaultVal={item.default}
256-
showRequired={showRequired}
257-
/>
258-
<div className="padding-bottom--md">
259-
<CollapseBox isInitExpanded={false}>
260-
{item[type].map((option, index) => (
261-
<div key={`${index}`} className={styles.paramItemWrapper}>
262-
{renderSchema(option, schemas, option.title, showRequired, isExpandedByDefault)}
263-
</div>
264-
))}
265-
</CollapseBox>
266-
</div>
267-
</div>
268-
)
269-
270301
// Handle oneOf flattening for results (when showRequired is false)
271302
const isResultSchema = !showRequired
272303

0 commit comments

Comments
 (0)