Search code examples
swaggerspringfox

Springfox: Description with headings


How can we get multiple headings inside description as following:

description: |
The Engine API  ....

# Errors

The API uses standard HTTP status codes ...


# Versioning

Some other text

In the above example, Errors and Versioning are two headers.

Currently, I am adding description as following:

ApiInfoBuilder().description(" ... ")

Solution

  • You can go with markdown like that:

    String description = "# The Engine API  ...\n" +
            "## Errors\n" +
            "The API uses standard HTTP status codes ...\n" +
            "## Versioning\n" +
            "Some other text\n";
    

    The \n new lines are important here.

    Or simply use plain HTML:

    String description = "<h2>The Engine API  ....</h2>" +
            "<h3>Errors</h3>" +
            "<p>The API uses standard HTTP status codes ...</p>" +
            "<h3>Versioning</h3>" +
            "<p>Some other text</p>";
    

    Then add the string to the API info:

    ApiInfoBuilder().description(description)