2017-03-15 194 views
1

我使用swagger maven插件在構建時生成了swagger文檔。從java註解中生成swagger docus,缺少安全定義

這適用於基本@SwaggerDefinition註釋。 但是在最終的json和yaml文件中不會生成子部分securityDefinition

我在版本3.1.4

任何想法使用swagger-maven-plugin什麼可能會丟失?

@SwaggerDefinition(
     info = @Info(
       description = "Interact with example", 
       version = "V1.1.0", 
       title = "The example API", 
       termsOfService = "http://example.com", 
       contact = @Contact(
        name = "André Schild", 
        email = "[email protected]", 
        url = "http://example.com" 
       ), 
       license = @License(
        name = "example License", 
        url = "http://example.com/" 
       ) 
     ), 
     host = "api.example.com", 
     basePath = "/api/v1", 
     consumes = {"application/json"}, 
     produces = {"application/json"}, 
     schemes = {SwaggerDefinition.Scheme.HTTPS}, 
     securityDefinition = @SecurityDefinition(
       basicAuthDefinions = { 
         @BasicAuthDefinition(key = "basicAuth")}, 
       apiKeyAuthDefintions = { 
         @ApiKeyAuthDefinition(key = "exampleAuth", name = "apiKey", in = ApiKeyLocation.HEADER)}), 
      tags = { 
       @Tag(name = "API", description = "Api for example"), 
       @Tag(name = "V1", description = "V1 Api for example") 
     }, 
     externalDocs = @ExternalDocs(
       value = "example", 
       url = "http://example.com" 
     ) 
) 

這裏什麼最終招搖文件看起來像:

--- 
swagger: "2.0" 
info: 
    description: "Interact with example" 
    version: "V1.1.0" 
    title: "The example API" 
    termsOfService: "http://example.com" 
    contact: 
    name: "André Schild" 
    url: "http://example.com" 
    email: "[email protected]" 
    license: 
    name: "example License" 
    url: "http://example.com/" 
host: "api.example.com" 
basePath: "/api/v1" 
tags: 
- name: "categories" 
    description: "Operations about categories" 
paths: 
    /categories: 
    get: 
.... and more paths/definitions.... 

回答

0

我得到這個工作對我來說是通過創建一個單獨的類/接口,並@SwaggerDefinition與安全定義註釋的方式。它爲所有API提供了安全性定義。

像這樣:

@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = { @ApiKeyAuthDefinition(key = "ApiKey", name = "Authorization", in = ApiKeyLocation.HEADER) })) 
public interface SwaggerSecurityDefinition { 

} 
+2

嗯..這不適合我的工作。我在與其他定義相同的位置創建了新的接口類,但它不包含在文檔中。 –