0

I am unable to set dynamic string to the Annotation value in groovy/grails

import io.swagger.annotations.ApiModelProperty

    class ProjectSearchRequest {

    String firstName ="prasanjeet"
    String lastName ="debnath"

    String dynamicString = firstName + " - " + lastName

    @ApiModelProperty(
            value = dynamicString
    )
    List<String> reportTypes
}
  • Have you tried making dynamic GString using just ‘def dynamicString = firstname’... and then using annotation ‘value = "$dynamicString"’ ? Although all this would give you is the ability to customise the description in the generated swagger which seems not of enormous benefit. Plus as it's an annotation I'm not sure this is evaluated at runtime or compile time so you may not be able to do this at all. – dawogfather Oct 23 '18 at 14:09
  • yes i tried. it also throws error. compiler is smart enough to recognize dynamic string with GString – Prasanjeet Debnath Oct 25 '18 at 04:20
  • Doesn't look like it can be done https://stackoverflow.com/a/5743184/708998 but maybe you could use class inheritance here and have different values that way possibly but they wouldn't be dynamic like a variable. If what your actually trying to achieve is an enumeration in the swagger that is output then you should be using 'allowableValues = [one, two, three]' anyway – dawogfather Oct 25 '18 at 04:35

0 Answers0