我是 swagger codegen 的新手,我使用的是 2.1.6 版。我正在尝试通过 yaml 和 swagger-codegen-maven 生成休息服务。以下是 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>
swagger生成的ServiceImpl为:
import com.domain.servie.handler.*;
import com.domain.servie.model.*;
import com.domain.servie.model.InitSuccessResponse;
import com.domain.servie.model.FailureResponse;
import com.domain.servie.model.InitRequest;
import java.util.List;
import com.domain.servie.handler.NotFoundException;
import java.io.InputStream;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaResteasyServerCodegen", date = "2017-01-13T12:19:29.084-06:00")
public class InitWfApiServiceImpl extends InitWfApiService {
@Override
public Response createProductPost(String apiKey,InitRequest body,SecurityContext securityContext)
throws NotFoundException {
// do some magic!
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
}
}
在这里,而不是return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
,我想将请求处理映射到我自己的请求处理程序,并且我不想将它硬编码为 rest api。
这个想法是,rest-api 是可重用的(jar 文件)。包含 rest-api 作为依赖 jar 的系统将负责构建战争。包装结构是给我的一种石雕要求。:)
有谁知道我如何覆盖这个 ServiceImpl 代码而不做一些疯狂的事情,比如覆盖 DefaultCodeGen 等?是否可以使用模板来实现这一点?
任何输入将不胜感激。