java - 如何将 Java Swagger 注释转换为 Swagger json 模式?

标签 java documentation swagger swagger-ui springfox

<分区>

如何从包含 Swagger 特定注释的 java 文件生成 JSON 文件,以便 Swagger-UI 可以读取它。

最佳答案

如您所说“我不想手动执行”,请使用 Swagger Maven 插件:

<plugin>
    <groupId>com.github.kongchen</groupId>
    <artifactId>swagger-maven-plugin</artifactId>
    <version>3.1.4</version>
    <configuration>
        <apiSources>
            <apiSource>
                <springmvc>true / false</springmvc>
                <locations>
                    <location>com.yourpackage.something</location>
                </locations>
                <host>yourhost.com</host>
                <basePath>/some/path</basePath>
                <info>
                    <title>Your Project Title</title>
                    <version>${project.version}</version>
                    <description>Some nice stuff</description>
                    <termsOfService>...</termsOfService>
                    <contact>
                        <email>someone@somewhere.com</email>
                        <name>Your Name</name>
                        <url>www.where.to.find.you</url>
                    </contact>
                </info>
                <swaggerDirectory>path/to/swagger/output</swaggerDirectory>
                <outputFormats>json</outputFormats>
            </apiSource>
        </apiSources>
    </configuration>
    <executions>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

然后你可以执行mvn compile,它会生成swagger.json文件。

关于java - 如何将 Java Swagger 注释转换为 Swagger json 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35546241/

相关文章:

java - 使用 java 的高效 LZ4 多文件压缩

java - Gradle 6/Java 11 "module not found"poi 和 poi-ooxml 错误,但 jars 存在

java - 人类可读的文档当前的 WebSphere 配置

r - 为 R 项目创建文档

java - 有没有办法在 swagger-ui 中显示我的 Maven 依赖项中存在的端点

java - 无法使用 Springfox 发送授权承载 token

mime-types - Swagger 如何添加对所有 mime 类型的支持

java - firebase 中的用户组

java - YouTube Java API 问题

documentation - 文档存储和组织的最佳实践?