从 Swagger API 文档生成 PDF(抛出 ArrayIndexOutOfBoundsException)

Generate PDF from Swagger API documentation (throwing ArrayIndexOutOfBoundsException)

我正在尝试按照其他问题进行操作: . I am also using this template https://github.com/Swagger2Markup/swagger2markup-maven-project-template/blob/master/pom.xml

到目前为止我已经设置了swagger-maven-plugin并成功生成了swagger.json和swagger.yaml :)

问题是当我添加 swagger2markup-maven-plugin 和尝试 mvn compile 时。我得到:

[ERROR] Internal error: java.lang.ArrayIndexOutOfBoundsException: 10364 -> [Help 1]

如何正确设置?感谢任何帮助。

PS:我什至无法尝试 asciidoctor-maven-plugin,因为一旦我将 swagger2markup-maven-plugin 添加为插件,一切都会崩溃 :(

一些属性

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <swagger.directory>${project.basedir}/src/docs/swagger</swagger.directory>
    <asciidoc.directory>${project.build.directory}/asciidoc</asciidoc.directory>        
</properties>

<build>
    ...
    <plugins>
        <!-- swagger-maven-plugin GOES HERE. SEE BELOW -->
        <!-- swagger2markup-maven-plugin GOES HERE. SEE BELOW -->
    </plugins>
</build>

swagger-maven-插件

<!-- Use the swagger maven plugin to generate swagger file from sources -->
<plugin>
    <groupId>com.github.kongchen</groupId>
    <artifactId>swagger-maven-plugin</artifactId>
    <version>3.1.4</version>
    <configuration>
        <apiSources>
            <apiSource>
                <springmvc>false</springmvc>
                <locations>
                    <location>com.company.com.support.service</location>
                </locations>
                <schemes>http,https</schemes>
                <host>my.host.net</host>
                <basePath>/myapi</basePath>
                <info>
                    <title>MyTitle</title>
                    <version>v1</version>
                    <description>MyDescription</description>
                    <termsOfService>http://my.terms</termsOfService>
                    <contact>
                        <email>me@email.com</email>
                        <name>Just Me</name>
                        <url>www.company.com</url>
                    </contact>
                    <license>
                        <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
                        <name>Apache 2.0</name>
                    </license>
                </info>
                <outputPath>${swagger.directory}/document.html</outputPath>
                <swaggerDirectory>${swagger.directory}</swaggerDirectory>
                <outputFormats>json,yaml</outputFormats>
            </apiSource>
        </apiSources>
    </configuration>
    <executions>
        <execution>
            <?m2e execute onConfiguration?>
            <phase>compile</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

swagger2markup-maven-插件

<!-- Use the swagger2markup plugin to generate asciidoc from swagger.json -->
<plugin>
    <groupId>io.github.swagger2markup</groupId>
    <artifactId>swagger2markup-maven-plugin</artifactId>
    <version>1.0.1</version>
    <dependencies>
        <dependency>
            <groupId>io.github.swagger2markup</groupId>
            <artifactId>swagger2markup-import-files-ext</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.github.swagger2markup</groupId>
            <artifactId>swagger2markup</artifactId>
            <version>1.0.1</version>
        </dependency>
    </dependencies>
    <configuration>
        <swaggerInput>${swagger.directory}/swagger.yaml</swaggerInput>
        <outputDir>${asciidoc.directory}</outputDir>
        <config>
            <swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
            <swagger2markup.pathsGroupedBy>TAGS</swagger2markup.pathsGroupedBy>
            <swagger2markup.extensions.dynamicOverview.contentPath>${project.basedir}/src/docs/asciidoc/extensions/overview</swagger2markup.extensions.dynamicOverview.contentPath>
            <swagger2markup.extensions.dynamicDefinitions.contentPath>${project.basedir}/src/docs/asciidoc/extensions/definitions</swagger2markup.extensions.dynamicDefinitions.contentPath>
            <swagger2markup.extensions.dynamicPaths.contentPath>${project.basedir}/src/docs/asciidoc/extensions/paths</swagger2markup.extensions.dynamicPaths.contentPath>
            <swagger2markup.extensions.dynamicSecurity.contentPath>${project.basedir}src/docs/asciidoc/extensions/security</swagger2markup.extensions.dynamicSecurity.contentPath>
        </config>
    </configuration>
    <executions>
        <execution>
            <?m2e execute onConfiguration?>
            <phase>generate-sources</phase>
            <goals>
                <goal>convertSwagger2markup</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我找到了解决这个问题的方法。我应该去掉所有的依赖和额外的配置,让它更简单。

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <swagger.directory>${project.build.directory}/generated-docs/swagger</swagger.directory>
    <asciidoctor.directory>${project.build.directory}/generated-docs/asciidoc</asciidoctor.directory>
</properties>

<build>
    <plugins>

        <!-- Use the swagger maven plugin to generate swagger file from sources -->
        <plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>3.1.4</version>
            <configuration>
                <apiSources>
                    <apiSource>
                        <springmvc>false</springmvc>
                        <locations>
                            <location>com.company.com.support.service</location>
                        </locations>
                        <schemes>http,https</schemes>
                        <host>my.host.net</host>
                        <basePath>/myapi</basePath>
                        <info>
                            <title>MyTitle</title>
                            <version>v1</version>
                            <description>MyDescription</description>
                            <termsOfService>Some Terms</termsOfService>
                            <contact>
                                <email>me@email.com</email>
                                <name>Just Me</name>
                                <url>www.company.com</url>
                            </contact>
                            <license>
                                <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
                                <name>Apache 2.0</name>
                            </license>
                        </info>
                        <outputPath>${swagger.directory}/document.html</outputPath>
                        <swaggerDirectory>${swagger.directory}</swaggerDirectory>
                        <outputFormats>yaml</outputFormats>
                    </apiSource>
                </apiSources>
            </configuration>
            <executions>
                <execution>
                    <?m2e execute onConfiguration?>
                    <phase>compile</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <!-- Use the swagger2markup to generate asciidoc from swagger file -->
        <plugin>
            <groupId>io.github.swagger2markup</groupId>
            <artifactId>swagger2markup-maven-plugin</artifactId>
            <version>1.0.1</version>
            <configuration>
                <swaggerInput>${swagger.directory}/swagger.yaml</swaggerInput>
                <outputFile>${asciidoctor.directory}/api-documentation</outputFile>
                <config>
                    <swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
                </config>
            </configuration>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>convertSwagger2markup</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

并用mvn package执行。

IndexOutOfBoundsException 是来自你在XML中的处理指令,即:

<?m2e execute onConfiguration?>