groovyjavadocgroovydoc

Is there a standard way to document groovy map properties?


Is there a standard way to document map properties in Groovy?

For the following function the config contains multiple optional properties like:

def publish(Map config) {
  config.ignore ?= true
  // ...
}

I looked at What is the standard way to use JavaDoc to document a Map? ; however, this doesn't work with dynamic Maps. Ideally I'm looking for something like JSDoc's @typedef or @property.


Solution

  • Other than adding the options to some JavaDoc for your method, there's no real way to document these...

    If this is a public API which requires documentation, you could move to passing actual parameters or you could create a class which is used for passing these options, ie:

    import groovy.transform.ToString
    import groovy.transform.Immutable
    
    @ToString
    @Immutable
    class Options {
        boolean debug = false
        File dir = new File('.')
        List<String> tags = []
    }
    
    println new Options()
    println new Options(debug: true, dir: new File("/tmp"))
    println new Options(tags: ['a', 'b'])
    

    Which prints

    Options(false, ., [])
    Options(true, /tmp, [])
    Options(false, ., [a, b])