22

什么是 swagger-ui,它有什么用?

我访问过http://swagger.io/,但我需要更多信息。

请指导我。

4

2 回答 2

18

Swagger UI 是一个工具,它获取 Swagger 规范文件,直观地呈现它们并允许您执行操作。

Swagger 本身就是一个记录和描述 REST API 的规范。可以在此处找到规范 - https://github.com/swagger-api/swagger-spec/。存储库包含规范本身、json 模式、示例等。存储库的主要 README 还指向其他工具,包括用于生成规范的库和框架。

在创建 Swagger 规范时,您可以使用其中一个框架并将其与现有代码集成以自动生成此类文档。

如果您没有现有的应用程序或希望手动记录它,您可以使用 Swagger-Editor 工具或您选择的文本编辑器。

于 2014-11-30T19:01:25.150 回答
1

maven依赖:

    <dependency>
         <groupId>io.springfox</groupId>
         <artifactId>springfox-swagger2</artifactId>
         <version>2.4.0</version>
    </dependency>  
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
    </dependency>

==================================================== ===========================

@Configuration
@EnableSwagger2   
    public class SwaggerConfig {

        private static final String SEARCH = "spring-rest-swagger";

        @Bean
        public Docket myApp() {
            return new Docket(DocumentationType.SWAGGER_2).groupName(SEARCH)
                    .apiInfo(apiInfo()).tags(new Tag(SEARCH, "spring-rest-swagger API"));
        }

        private ApiInfo apiInfo() {
            return new ApiInfoBuilder().title(SEARCH).build();
        }
    }

==================================================== ==============================

供参考使用下面的链接:(一步一步的解释)

https://www.youtube.com/watch?v=xeYpiHLpme0&t=1s

于 2019-12-30T11:23:02.413 回答