2017-01-13 7 views
2

私はswagger codegenに新しく、バージョン2.1.6を使用しています。私はyamlとswagger-codegen-mavenでrestサービスを生成しようとしています。闊歩によって生成されたデフォルトのswgger-code-genサービスの実装を上書きする方法は?

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

ServiceImplがある:以下 はのpom.xmlの一部である代わりにreturn Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();の、ここで

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(); 
    } 

} 

、私は自分の要求ハンドラとIドンへの要求処理をマッピングしたいと思いますそれをハードコードしてAPIを休止したい。

考え方は、rest-apiは再利用可能(jarファイル)です。 Dependency Jarとしてのrest-apiを含むシステムは、戦争の構築を担当します。パッケージング構造は、私に与えられた石の彫刻された要件の一種です。 :)

どのように私はDefaultCodeGenなどをオーバーライドのようないくつかのクレイジーなことをやっていないこのServiceImplのコードを無効にするか知っていますか?これを達成するためにテンプレートを使用することは可能ですか?

いずれの入力も感謝します。

答えて

1

コードのその部分を生成するテンプレートはthis oneです。 テンプレートを変更することで、必要な動作を実現できるはずです。

+0

ひげそりテンプレートを設定した後、テンプレートを使用してサービスimplを作成できます。しかし、私は奇妙なシナリオに直面した。私はyamlに複数のAPIを持っているので、私は異なるAPIのために複数のサービスインプラントをセットアップすることができませんでした。だから私が取った回避策は、複数のyamlを作成し、swagger-codegenを実行することでした。任意のアイデアを複数のyamlを作成せずに複数のサービスを実装する方法を教えてください。 – bkrish

+0

@bkrish私はうまくいきましたが、新しいシナリオを修正する方法はわかりませんが、誰か他の人が知っているかもしれないので、新しい質問をしてください。 – moondaisy

+0

Gotcha。お手伝いありがとう! – bkrish

関連する問題