2

I've generated a document using spring auto rest docs. This uses capital.scalable libraries combined with java docs and spring rest docs. My issue is with the List of enums while describing the request fields. Type column generates a value as Array[Object]. Also, the description column doesn't generate the must be one of statement with the enum values, as it does when only Enum is the field and not the list of enums.

public enum Discipline {
  ECONOMICS("economics"),
  SOCIOLOGYANTHROPOLOGY("sociologyanthropology");

  private final String discipline;

  Discipline(final String discipline) {
    this.discipline = discipline;
  }

  public String getId() {
    return discipline;
  }
}

Above is the enum that I have. It uses tostring correctly to display in the description when the field is used only as enum. But if list of enums i.e.

List<Discipline>

is the field, then it doesn't describe properly as mentioned above.

Please let me know what should be done to generate the document more effectively?

Florian Benz
  • 422
  • 4
  • 11
Ankit Bhatnagar
  • 745
  • 5
  • 16
  • Hi Ankit! Can you please add more information about the problem you are seeing such as the code for the controller/endpoint and the test? It would also be useful to know what version of Spring REST docs you are using. – jstrater Dec 14 '17 at 00:13
  • "List" didn't come properly. I've included that in code style so that it can be seen properly now. This is the actual field i.e. the list of enum objects as mentioned above. – Ankit Bhatnagar Dec 15 '17 at 08:38

1 Answers1

1

You are right that lists of enums are not properly supported yet.

If you have a request/response like:

class SomeRequest {

    public enum EnumTest {
        ONE, TWO
    }

    /**
     * List of enums
     */
    private List<EnumTest> enumTestList;
}

it is documented as List of enums documented with Spring Auto REST Docs with Spring Auto REST Docs at the moment.

It would be good if the type would be Array[String] and the description would list the elements of the enum, e.g. "Elements must be one of [...]".

Spring Auto REST Docs 1.0.11 fixes the type issue and thus Array[String] will be shown with this version.

I opened an issue to improve the documentation of lists of enums: https://github.com/ScaCap/spring-auto-restdocs/issues/194. Until this issue is resolved, one can manually add "Elements must be one of [...]" to the Javadoc of the list as a workaround.

Florian Benz
  • 422
  • 4
  • 11