Skip to content

Commit 27cf55c

Browse files
committed
fix record schema reading
1 parent 77e7a7d commit 27cf55c

1 file changed

Lines changed: 29 additions & 19 deletions

File tree

src/CWL/Decode.fs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,36 @@ module Decode =
138138
/// Decode an InputRecordSchema from a YAMLElement
139139
and inputRecordSchemaDecoder: (YAMLiciousTypes.YAMLElement -> InputRecordSchema) =
140140
Decode.object (fun get ->
141-
// Decode fields using Overflow to get the map form
142-
let fieldsDict =
143-
get.Optional.Field
144-
"fields"
145-
(Decode.object (fun get2 -> get2.Overflow.FieldList []))
146-
141+
// Try to decode fields as an array (flow-style) or as a map (block-style)
147142
let decodedFields =
148-
match fieldsDict with
149-
| Some dict ->
150-
let fields = ResizeArray<InputRecordField>()
151-
for kvp in dict do
152-
let fieldType = cwlTypeDecoder' kvp.Value
153-
154-
fields.Add({
155-
Name = kvp.Key
156-
Type = fieldType
157-
Doc = None
158-
Label = None
159-
})
160-
Some fields
143+
// Get the fields element directly
144+
let fieldsElement = get.Optional.Field "fields" id
145+
146+
match fieldsElement with
147+
| Some (YAMLElement.Object []) ->
148+
// Empty array case: fields: []
149+
Some (ResizeArray<InputRecordField>())
150+
| Some element ->
151+
// Try to decode as an array (flow-style: [{name: x, type: y}])
152+
try
153+
let fields = Decode.resizearray inputRecordFieldDecoder element
154+
Some fields
155+
with _ ->
156+
// Fall back to map form (block-style: {x: y})
157+
try
158+
let dict = Decode.object (fun get2 -> get2.Overflow.FieldList []) element
159+
let fields = ResizeArray<InputRecordField>()
160+
for kvp in dict do
161+
let fieldType = cwlTypeDecoder' kvp.Value
162+
163+
fields.Add({
164+
Name = kvp.Key
165+
Type = fieldType
166+
Doc = None
167+
Label = None
168+
})
169+
Some fields
170+
with _ -> None
161171
| None -> None
162172

163173
{

0 commit comments

Comments
 (0)