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

时间:2016-09-23 03:12:49

标签: maven pdf swagger swagger-ui

我正在尝试做另外一个问题: Generate PDF from Swagger API documentation。我也在使用此模板https://github.com/Swagger2Markup/swagger2markup-maven-project-template/blob/master/pom.xml

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

问题出在我添加swagger2markup-maven-plugin和尝试mvn compile时。我明白了:

  

[错误]内部错误:java.lang.ArrayIndexOutOfBoundsException:10364 - > [帮助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>

招摇-行家-插件

<!-- 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-行家-插件

<!-- 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>

2 个答案:

答案 0 :(得分:0)

我找到了如何解决这个问题的方法。我应该摆脱所有的依赖关系和额外的配置,并使其更简单。

<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执行。

答案 1 :(得分:0)

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

<?m2e execute onConfiguration?>

相关问题