OpenApi 生成器 - 默认更改主机

问题描述 投票:0回答:1

每次生成 Java 类时,我都需要更改 host 值。

这是我的文档文件。

swagger: "2.0"
info:
  version: "0.14"
  title: Some title
host: api.default.host
basePath: /base/path/
schemes:
  - https

// ....

我尝试过类似的方法,但不幸的是,它不起作用

<build>
        <plugins>
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>testId</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>                         
                            <inputSpec>${project.basedir}/src/main/resources/test.yaml</inputSpec>
                            <generatorName>java</generatorName>
                            <apiPackage>com.test.api</apiPackage>
                            <modelPackage>com.test.model</modelPackage>
                            <invokerPackage>com.test.invoker</invokerPackage>
                            <generateApiTests>false</generateApiTests>
                            <generateApiDocumentation>false</generateApiDocumentation>
                            <configOptions>
                                <globalFeatures>
                                    <host>targetHost</host>
                                </globalFeatures>
                                <dateLibrary>java8</dateLibrary>
                                <java8>true</java8>
                            </configOptions>
                            <library>jersey2</library>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

我使用的是3.3.4版本的生成器,由于公司政策无法更改。

java yaml pom.xml openapi openapi-generator
1个回答
0
投票

@tbtach 关于使用 Maven 插件修改文件的评论帮助我找到了使用 maven-replacer-plugin 的解决方案,它允许您修改项目中任何文件中的“令牌”:https://code.google.com /archive/p/maven-replacer-plugin/.

请参阅问题第一部分的工作示例:maven-replacer-plugin 和多个文件

© www.soinside.com 2019 - 2024. All rights reserved.