Lilly
Lilly

Reputation: 105

How to add <a href> link to make an element clickable in java for Swagger

I want to make Capo Mastro a clickable link in Java for swagger in @ApiOperation annotation, but I can't get any result.

@ApiOperation(
        value = "This method updates an existing capo mastro."+" <a href>Capo mastro<a>"+ can be managed only by system",
        response = SaveCapoMastroResponse.class
    )

I would really appreciate if anyone could help! Thank you!

Upvotes: 2

Views: 8373

Answers (3)

Helen
Helen

Reputation: 98011

Assuming you mean clickable in Swagger UI – you can add links in the operation description (notes attribute) using the Markdown syntax. The operation summary (value) does not support Markdown though.

@ApiOperation(
        value = "This method updates an existing capo mastro.",
        notes = "[Capo mastro](http://example.com) can be managed only by system.",
        response = SaveCapoMastroResponse.class
    )

HTML <a href=""> tag should work too, since Markdown supports HTML. Make sure to escape the inner " quotes.

@ApiOperation(
        value = "This method updates an existing capo mastro.",
        notes = "<a href=\"http://example.com\" target=\"_blank\">Capo mastro</a> can be managed only by system.",
        response = SaveCapoMastroResponse.class
    )

Upvotes: 4

Oleg Cherednik
Oleg Cherednik

Reputation: 18255

I add clickable image logo to the description:

private static ApiInfo v1ApiInfo() {
    return new ApiInfoBuilder()
            .version("1.0")
            .title("Council on Dairy Cattle Breeding (CDCB) API v1.0 Documentation"))
            .description("[![cdcb](/img/cdcb.png)](https://www.uscdcb.com/)").build();
}

/img/cdcb.png - this is image from available resource. I use SpringBoot + Maven and it automatically add public folder from resources; full path of image is /src/main/recources/public/img/cdcb.png

As result you get clickable image just like you can see below:

cdcb

Upvotes: 3

Raju Sharma
Raju Sharma

Reputation: 2516

You can use @ExternalDocs annotation to specify a link for api as below:

@ExternalDocs(value="Capo mastro", url="link to Capo mastro")

Upvotes: 1

Related Questions