2017-08-28 54 views
2

I want to make Capo Mastro a clickable link in Java for swagger in @ApiOperation annotation, but I can't get any result.如何添加<a href> link to make an element clickable in java for Swagger

@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!

回答

2

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 
    ) 
+0

這不起作用 – Lilly

+0

_如何正確地這不工作?你有任何錯誤? Swagger UI不會呈現鏈接?你使用哪個版本的swagger-annotations?越詳細越好。 – Helen

+0

它顯示爲明文形式的鏈接。 Swagger 1.5.16 – Lilly

1

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

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

這不起作用要麼 – Lilly

+0

你得到了什麼錯誤? Swagger使用哪個版本? –

+0

它不會給我任何錯誤。它根本不顯示任何東西。我正在使用swagger 1.5.16 – Lilly

0

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

相關問題