I previously had an api which had a number of functions in it, all of which expected a map in a very particular format. When it came to documenting this API, I found that in the docstrings of each of these functions I was repeating "The map with which this function is called must be of such and such a format, and this field of the map means such and such."
So I thought it would be better for those functions to take a record, and that I could just document the record instead. However it doesn't seem to be possible to document records, at least in any way interpreted either by the doc
macro or Marginalia.
A solution suggested here is "just add a :doc key in the record's meta".
I tried (defrecord ^{:doc "Here is some documentation"} MyRecord [field1 field2])
but macroexpanding this suggests it doesn't have any effect. Also defrecord
returns an instance of java.lang.class
which doesn't implement IMeta so I'm not sure we can give it metadata?
- How should records be documented?
- Are records an appropriate solution here?
prismatic/schema
, that allows you to specify the type of data you will accept, also allowing verification of the arguments provided. – Elma