2016-02-22 26 views
7

Come generare file JSON da file java contenenti annotazioni specifiche di Swagger, in modo che Swagger-UI possa leggerlo.Come convertire Java Swagger Annotation in Swagger json schema?

+0

Si prega di guardare i campioni nel repository [swagger-samples] (https://github.com/swagger-api/swagger-samples) che dimostrano come questo è fatto. Dipende da una serie di cose, incluso il tuo framework, ecc. – fehguy

+0

Sto usando Java e SpringBoot per framework. –

+0

Nel repository swagger-samples, lo swagger JSON viene creato manualmente, suppongo. Non voglio farlo manualmente. –

risposta

1

Come si dice "Io non voglio farlo manualmente", usare il plugin Swagger Maven:

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

allora si può fare mvn compile e sarà generare il file swagger.json.