Skip to content

Commit

Permalink
Make error messages for objects and arrays more helpful
Browse files Browse the repository at this point in the history
- This changes NullPointerExceptions for arrays into error messages for
known problems
- The error message for objects was too noisy, so the change here is to
just output the property name
  • Loading branch information
luandy64 committed Apr 21, 2020
1 parent ea75869 commit 8fa22a4
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions scripts/tap-generate-docs/src/tap_generate_docs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,31 @@
"description" ""}]
(cond (= "object" (property-json-schema-partial "type"))
(if (nil? (property-json-schema-partial "properties"))
(throw (ex-info "Found object type without properties defined: " {:property-name property-name
:property property
:schema schema}))
(throw (ex-info "Found object type without properties defined: " {:property-name property-name}))
(assoc base-converted-property
"subattributes"
(convert-object-properties tap-fs schema (property-json-schema-partial "properties"))))

(= "array" (property-json-schema-partial "type"))
(let [items (property-json-schema-partial "items")
item-type (items "type")
converted-property (do
(when ((set item-type) "array")
(throw (ex-info (str "Currently cannot handle a type with arrays of arrays. "
"Discuss how docs output should work if encountered.")
{:property property})))
(if (or (= "object" item-type)
((set item-type) "object"))
(convert-array-object-type tap-fs schema property items)
[(convert-multiary-type tap-fs schema ["value" items])]))]
;; TODO Log (or verify that it's already logged) dropped value
(if (empty? converted-property)
base-converted-property
(assoc base-converted-property
"subattributes"
converted-property)))
(if (nil? (property-json-schema-partial "items"))
(throw (ex-info "Found array type without items defined: " {:property-name property-name}))
(let [items (property-json-schema-partial "items")
item-type (items "type")
converted-property (do
(when ((set item-type) "array")
(throw (ex-info (str "Currently cannot handle a type with arrays of arrays. "
"Discuss how docs output should work if encountered.")
{:property property})))
(if (or (= "object" item-type)
((set item-type) "object"))
(convert-array-object-type tap-fs schema property items)
[(convert-multiary-type tap-fs schema ["value" items])]))]
;; TODO Log (or verify that it's already logged) dropped value
(if (empty? converted-property)
base-converted-property
(assoc base-converted-property
"subattributes"
converted-property))))

(and (= "string" (property-json-schema-partial "type"))
(contains? property-json-schema-partial "enum"))
Expand Down

0 comments on commit 8fa22a4

Please sign in to comment.