【问题标题】:Spring Boot - Swagger generate json/yaml file and client code?Spring Boot - Swagger 生成 json/yaml 文件和客户端代码?
【发布时间】:2019-06-24 11:36:57
【问题描述】:

在我的 Spring Boot 应用程序中使用了 springfox 依赖项来显示 swagger ui。使用 @SwaggerDefinition@EnableSwagger2 等注解。

但它们不会生成任何 html 或 json/yaml 或任何客户端代码。 所以我使用了在以下位置找到的插件:https://github.com/kongchen/swagger-maven-example

<plugin>
    <groupId>com.github.kongchen</groupId>
    <artifactId>swagger-maven-plugin</artifactId>
    ......
</plugin>

但他们也没有帮助,我猜他们正在扫描整个包中的所有 @Api 类以生成 json,但我没有。

有什么建议吗?

【问题讨论】:

    标签: spring-boot swagger swagger-2.0 swagger-codegen springfox


    【解决方案1】:

    这对我有用 kongchen plugin

        <plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>3.1.7</version>
            <executions>
                <execution>
                <phase>generate-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <apiSources>
                    <apiSource>
                        <info>
                            <title>Swagger API Specification for Your Project</title>
                            <version>v0.28</version>
                            <description>Swagger API Specification for Your Project</description>
                        </info>
                        <locations>
                            <location>com.yourpackage.api</location>
                            <location>com.yourpackage.api.controllers</location>
                        </locations>
                        <springmvc>true</springmvc>
                        <outputFormats>json,yaml</outputFormats>
                        <swaggerDirectory>
                            ${project.build.directory}/generated/swagger-api-spec
                        </swaggerDirectory>
                    </apiSource>
                </apiSources>
            </configuration>
        </plugin>
    

    【讨论】:

    • 这也适用于我,诀窍是使用 2 个位置,一个带有控制器,一个没有 ?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 2019-11-15
    • 1970-01-01
    • 2016-03-24
    • 2016-08-13
    相关资源
    最近更新 更多