1

I am using http://clojure.github.io/data.json/ read-str to read swagger (https://openapis.org/specification) documents for semantic validation. One of the things to validate is no duplicate paths. For example:

/foo/{bar}/baz

is a duplicate of:

/foo/{dup}/baz

However, if the swagger file contains two "literal" identical paths:

/foo/bar/baz : ...
...
/foo/bar/baz : ...

When I use read-str, the last one "overwrites" the first one, so I can't see the duplicate - it is just dropped.

Is there a way to use clojure.data.json to complain on duplicate keys?

Or is there some other library I can use?

haroldcarr
  • 1,523
  • 15
  • 17
  • 1
    You will likely have to drop down into Java interop and use something like Jackson. See [Jackson detection of duplicate JSON POJO properties and Map keys](http://stackoverflow.com/questions/23781637/jackson-detection-of-duplicate-json-pojo-properties-and-map-keys) – Curtis Summers May 26 '16 at 12:54

1 Answers1

1

unfortunately, no. This library does not offer a hook at that level out of the box. It lets you add hooks to validate the individual keys and the individual values in isolation and not in a context where it can tell if the keys is already in the map. It just calls assoc so you get the Clojure behaviour by default.

(assoc! result out-key out-value)

You can copy the read-object function from json.clj in that project and add a validator to the result transient map. This would be brittle though.

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284