Java 如何覆盖默认swgger代码生成服务实现?

Java 如何覆盖默认swgger代码生成服务实现?,java,maven,swagger,swagger-codegen,Java,Maven,Swagger,Swagger Codegen,我是一个新的大摇大摆codegen和我使用的版本2.1.6。我正试图通过yaml和swagger-codegen-maven生成rest服务。 以下是pom.xml的一部分: ..... <plugin> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>${io.swagger.swagg

我是一个新的大摇大摆codegen和我使用的版本2.1.6。我正试图通过yaml和swagger-codegen-maven生成rest服务。 以下是pom.xml的一部分:

.....
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${io.swagger.swagger-codegen-maven-plugin.version}</version>
<executions>
    <execution>
      <id>createprod</id>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
            <inputSpec>${project.basedir}/src/main/resources/swagger/rest-api-create-product.yaml</inputSpec>
            <language>io.swagger.codegen.languages.JavaResteasyServerCodegen</language>
          <!--   <templateDirectory>How_do_I_use_it</templateDirectory> -->

            <output>${project.build.directory}/generated-sources</output>
            <apiPackage>${swagger.resourcePackage}.handler</apiPackage>
            <modelPackage>${swagger.resourcePackage}.model</modelPackage>
            <invokerPackage>${swagger.resourcePackage}.handler</invokerPackage>
             <configOptions>
                 <sourceFolder>src/main/java</sourceFolder>
                 <interfaceOnly>true</interfaceOnly>
                 <configPackage>com.domain.service.configuration</configPackage>
                 <serializableModel>true</serializableModel>
             </configOptions>
        </configuration>
    </execution>
</executions>
  </plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9.1</version>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src/main/java</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
</plugins>  
在这里,不是
返回Response.ok().entity(新的ApiResponseMessage(ApiResponseMessage.ok,“magic!”).build(),我想将请求处理映射到我自己的请求处理程序,我不想将其硬编码到RESTAPI

其思想是,RESTAPI是可重用的(jar文件)。包含RESTAPI作为依赖项jar的系统将负责构建war。包装结构是给我的一种石刻要求。:)

有人知道我如何重写这个ServiceImpl代码而不做一些疯狂的事情,比如重写DefaultCodeGen等等吗?是否可以使用模板来实现这一点


任何输入都将不胜感激。

生成该部分代码的模板是。
您应该能够通过更改模板来实现所需的行为。

当您想要使用自定义模板时,您可以使用以下内容:

在maven中,添加另一个插件以下载包含自定义模板的maven依赖项,例如,您可以将它们上载到本地工件。 在这种情况下,工件称为swagger模板及其版本0.0.1

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-remote-resources-plugin</artifactId>
  <configuration>
    <resourceBundles>
      <resourceBundle>our.mvn.group:swagger-templates:0.0.1</resourceBundle>
    </resourceBundles>
  </configuration>
  <executions>
    <execution>
      <phase>initialize</phase>
      <goals>
        <goal>process</goal>
      </goals>
    </execution>
  </executions>
</plugin>

org.apache.maven.plugins
maven远程资源插件
我们的.mvn.group:swagger模板:0.0.1
初始化
过程
然后在swagger codegen maven插件配置部分,确保引用了正确的目录,添加以下内容:

<templateDirectory>${project.build.directory}/maven-shared-archive-resources/subdir</templateDirectory>
${project.build.directory}/maven共享归档资源/subdir

其中subdir是包含自定义模板的maven工件的src/main/resources目录中的子目录。您可以将您的胡须文件放在那里。

设置了胡须模板后,我可以使用模板创建我的服务impl。但我面临着奇怪的情况。因为我在yaml中有多个API,所以我无法为不同的API设置多个service impl。所以我采取的解决方法是创建多个yaml并运行swagger codegen。知道如何在不创建多个yaml的情况下适应多个服务impl吗?@bkrish我很高兴它能工作,但我不知道如何修复您的新场景,但请提出一个新问题,因为其他人可能知道。明白了。谢谢你的帮助!没有解释如何使用templateDirectory覆盖模板?
<templateDirectory>${project.build.directory}/maven-shared-archive-resources/subdir</templateDirectory>