harshit-sh
harshit-sh

Reputation: 386

Add a newline to swagger output

I am using swagger-jersey2-jaxrs version 1.5.15. I am on swagger-ui 3.0.9. I added a description to a header using @SwaggerDefinition annotation and tags (as the description parameter is now deprecated). The code goes like:

@Api(tags = { "Hello World" })
@SwaggerDefinition(tags = { @Tag(name = "Hello World", description = 
    "Description about world: " + "  \n" +
    "1. Hello " + "\n" +
    "2. World " + "<br>" 
 )})

By using this, I was able to add a description to the "Hello World" header. My question is how should I add a newline for every point. I tried the following but failed:

  1. Adding "\n" or "<br>" to string. \n" doesn't reflect a newline while "<br>" just adds the string "<br>" to the string that is rendered.

  2. I tried to use System.lineSeparator() and System.getProperty("line.separator") as well but that gives the error "The value for annotation attribute Tag.description must be a constant expression".

Swagger shows a newline when the first method above is used when using the notes parameter for the other annotations (doesn't work with @Api), any workaround to using that instead to get the newline?

Any suggestion is welcome, thanks in advance! :)

Upvotes: 17

Views: 57079

Answers (3)

Simply add

<br><br>

example :

  /autoComplete:
    post:
      tags:
        - AutoComplete Service
      summary: Various AutoComplete Services 
      description: > List 
        1. Name <br><br>
        2. Teams  <br><br>

Upvotes: 3

user2122524
user2122524

Reputation: 696

Use double "<br>" or "\n", swagger will show the text in the next line. For e.g:

@SwaggerDefinition(tags = { @Tag(name = "Hello World", description = "Description about world: \n\n" + "1. Hello \n\n" + "2. World <br><br>" )})

Upvotes: 28

E. Bavoux
E. Bavoux

Reputation: 555

You can use the following:

@SwaggerDefinition(tags = { @Tag(name = "Hello World", description =
    "Description about world: <br /> " +
            "1. Hello <br /> " +                  //With <br />, not  <br>
            "2. World ")})   

It works for me, it gives the following result, with line breaks:

enter image description here

Have fun !

Upvotes: 13

Related Questions