2015-07-20 61 views
0

有沒有人知道如何在Spring引導和Swagger 2.0中自定義tom級別的屬性?如何在Spring引導和Swagger 2.0中自定義tom級別的屬性?

我試過使用@SwaggerDefinition,但這似乎不起作用。我的代碼中是否有任何錯誤?

@SpringBootApplication 
@ComponentScan(basePackages = { "test" }) 
@EnableSwagger2 
@SwaggerDefinition(info = @Info(title = "My Api Documentation", 
    description = "My Api Documentation, Version:1.0", 
    version = "1.0", 
    contact = @Contact(name = "my name", email = "[email protected]", url = "http://my_page/") , 
    license = @License(name = "Apache 2.0", url = "http://www.apache.org/licenses/LICENSE-2.0"))) 
public class Application { 

    public static void main(String[] args) { 
    SpringApplication.run(Application.class, args); 
    } 
} 

和我從http://localhost:8080/v2/api-docs

{ 
swagger: "2.0", 
info: { 
description: "Api Documentation", 
version: "1.0", 
title: "Api Documentation", 
termsOfService: "urn:tos", 
contact: { 
name: "Contact Email" 
}, 
license: { 
name: "Apache 2.0", 
url: "http://www.apache.org/licenses/LICENSE-2.0" 
} 
}, 
host: "localhost:8080", 
basePath: "/", 
tags: [ 
{ 
name: "basic-error-controller", 
description: "Basic Error Controller" 
} 
], 
... 
} 

的頂級屬性(標題,詳細描述)下面JSON響應都應該已經改變。

+0

改進了語法,使問題更具可讀性。 – missimer

+0

非常感謝,我會盡我所能。 –

回答

0

我來回答我自己。 我沒有解決關於@SwaggerDefinition的問題,但我找到了另一種方法。

我可以在我的配置類中覆蓋Docket。

@SpringBootApplication 
@ComponentScan(basePackages = { "test" }) 
@EnableSwagger2 
public class Application { 

    @Bean 
    public Docket confApi() { 
    ResponseMessage msg_500 = new ResponseMessageBuilder().code(500).message("500 message").responseModel(new ModelRef("Error")).build(); 
    return new Docket(DocumentationType.SWAGGER_2).globalResponseMessage(RequestMethod.GET, Collections.singletonList(msg_500)) 
     .globalResponseMessage(RequestMethod.POST, Collections.singletonList(msg_500)) 
     .apiInfo(new ApiInfo("My Api Documentation", "My Api Documentation, Version: 1.0", "1.0", null, "[email protected]", null, null)); 
    } 

    public static void main(String[] args) { 
    SpringApplication.run(Application.class, args); 
    } 
} 
相關問題