2016-02-22 9 views
7

Swagger固有の注釈を含むJavaファイルからJSONファイルを生成して、Swagger-UIがそれを読むことができるようにする方法。Java Swagger AnnotationをSwagger jsonスキーマに変換するにはどうすればいいですか?

<plugin> 
    <groupId>com.github.kongchen</groupId> 
    <artifactId>swagger-maven-plugin</artifactId> 
    <version>3.1.4</version> 
    <configuration> 
     <apiSources> 
      <apiSource> 
       <springmvc>true/false</springmvc> 
       <locations> 
        <location>com.yourpackage.something</location> 
       </locations> 
       <host>yourhost.com</host> 
       <basePath>/some/path</basePath> 
       <info> 
        <title>Your Project Title</title> 
        <version>${project.version}</version> 
        <description>Some nice stuff</description> 
        <termsOfService>...</termsOfService> 
        <contact> 
         <email>[email protected]</email> 
         <name>Your Name</name> 
         <url>www.where.to.find.you</url> 
        </contact> 
       </info> 
       <swaggerDirectory>path/to/swagger/output</swaggerDirectory> 
       <outputFormats>json</outputFormats> 
      </apiSource> 
     </apiSources> 
    </configuration> 
    <executions> 
     <execution> 
      <phase>compile</phase> 
      <goals> 
       <goal>generate</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

次にあなたがmvn compileを行うことができますし、それがswagger.jsonファイルを生成します:あなたが闊歩Mavenプラグインを使用して、「私は手動でそれを行うにはしたくない」と言ったよう

+0

これがどのように行われているかを示す[swagger-samples](https://github.com/swagger-api/swagger-samples)リポジトリのサンプルを見てください。それはあなたのフレームワークなどを含む多くのものに依存します。 – fehguy

+0

私はフレームワークのためにJavaとSpringBootを使用しています。 –

+0

swagger-samplesリポジトリでは、swagger JSONが手動で作成されると思います。私は手動でやりたいとは思わない。 –

答えて

1

関連する問題