Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 73b460c

Browse files
committed
__value as a map implementation
1 parent 833758a commit 73b460c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/paos/service.clj

+10-6
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,17 @@
147147
(fault-template [this])
148148
(parse-fault [this fault-xml]))
149149

150-
(defn- content->fields [content type]
150+
(defn- content->fields [content type optional? enumeration]
151151
(let [content (filter #(not (string/starts-with? % "\n")) content)]
152152
(loop [el (first content) els (rest content) comments [] fields []]
153153
(if-not el
154154
fields
155155
(cond
156156
(string? el)
157-
{:__value nil
158-
:__type type}
157+
{:__value
158+
(cond-> {:__type type}
159+
optional? (merge {:__optional? true})
160+
enumeration (merge {:__enum enumeration}))}
159161

160162
(instance? Comment el)
161163
(recur (first els) (rest els) (conj comments (:content el)) fields)
@@ -177,7 +179,10 @@
177179
original-xml]
178180
(let [{:keys [type min-occurs max-occurs
179181
optional enumeration]} (into {} (map parse-comment comments))
180-
fields (content->fields content type)]
182+
fields (content->fields content
183+
type
184+
(or optional (= min-occurs 0))
185+
enumeration)]
181186
(reify
182187
Element
183188
(get-original [_] original-xml)
@@ -227,8 +232,7 @@
227232
(filter (fn [[_ attrv]]
228233
(= "?" attrv)))
229234
(map (fn [[attr-name _]]
230-
[(fix-fn attr-name) {:__value nil
231-
:__type "string"}]))
235+
[(fix-fn attr-name) {:__value {:__type "string"}}]))
232236
(into {})))]
233237
{:__attrs attrs}
234238
{})

test_resources/sample_message.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
<book:ComplexObjectWithComplexTag>
2727
<!--1 or more repetitions:-->
2828
<BookId BookType="?">
29-
<!--type: string-->
29+
<!--type: string - enumeration: [FOO_ID,BAR_ID]-->
30+
<!--Optional: true-->
3031
<ID>?</ID>
3132
<Type>
3233
<!--type: integer-->

0 commit comments

Comments
 (0)