Created
November 21, 2016 04:52
-
-
Save jackqt/791449f460eef795ad5ccc0d615ad04f to your computer and use it in GitHub Desktop.
Usage of swagger-codegen-maven-plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<org.springframework.cloud.version>1.2.1.RELEASE</org.springframework.cloud.version> | |
<org.springframework.boot.version>1.4.1.RELEASE</org.springframework.boot.version> | |
<java.version>1.7</java.version> | |
<springfox-version>2.5.0</springfox-version> | |
</properties> | |
<groupId>com.jackqt.backend.service</groupId> | |
<artifactId>swagger-code-gen</artifactId> | |
<version>1.0.0-SNAPSHOT</version> | |
<packaging>jar</packaging> | |
<build> | |
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-surefire-plugin</artifactId> | |
<version>2.19.1</version> | |
<configuration> | |
<systemPropertyVariables> | |
<io.springfox.staticdocs.outputDir>${swagger.output.dir}</io.springfox.staticdocs.outputDir> | |
<io.springfox.staticdocs.snippetsOutputDir>${swagger.snippetOutput.dir}</io.springfox.staticdocs.snippetsOutputDir> | |
</systemPropertyVariables> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.5.1</version> | |
<configuration> | |
<includes> | |
<include> | |
src/main/java/** | |
</include> | |
</includes> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>io.swagger</groupId> | |
<artifactId>swagger-codegen-maven-plugin</artifactId> | |
<executions> | |
<execution> | |
<id>generate-to-springboot-code</id> | |
<goals> | |
<goal>generate</goal> | |
</goals> | |
<configuration> | |
<inputSpec>${project.basedir}/src/docs/swagger/swagger.yaml</inputSpec> | |
<language>spring</language> | |
<output>${project.build.directory}/swagger-generated-sources</output> | |
<configurationFile>${project.basedir}/src/main/resources/config.json</configurationFile> | |
</configuration> | |
</execution> | |
<execution> | |
<id>export-to-html-doc</id> | |
<goals> | |
<goal>generate</goal> | |
</goals> | |
<configuration> | |
<inputSpec>${project.basedir}/src/docs/swagger/swagger.yaml</inputSpec> | |
<language>html</language> | |
<output>${project.build.directory}/swagger-generated-sources</output> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
<dependencies> | |
<!--Spring Boot dependencies --> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-web</artifactId> | |
<version>${org.springframework.boot.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-tomcat</artifactId> | |
<version>${org.springframework.boot.version}</version> | |
<scope>provided</scope> | |
</dependency> | |
<!--SpringFox dependencies --> | |
<dependency> | |
<groupId>io.springfox</groupId> | |
<artifactId>springfox-swagger2</artifactId> | |
<version>${springfox-version}</version> | |
</dependency> | |
<dependency> | |
<groupId>io.springfox</groupId> | |
<artifactId>springfox-swagger-ui</artifactId> | |
<version>${springfox-version}</version> | |
</dependency> | |
<!--Swagger dependencies --> | |
<dependency> | |
<groupId>io.swagger</groupId> | |
<artifactId>swagger-codegen</artifactId> | |
<version>2.2.2-SNAPSHOT</version> | |
</dependency> | |
<dependency> | |
<groupId>io.swagger</groupId> | |
<artifactId>swagger-codegen-maven-plugin</artifactId> | |
<version>2.2.1</version> | |
</dependency> | |
</dependencies> | |
</project> |
The configuration file could be this:
{
"groupId":"com.jackqt.backend.service",
"artifactId":"jackqt-service-code-gen",
"artifactVersion":"1.0.0-SNAPSHOT",
"library":"spring-boot",
"apiPackage":"com.jackqt.backend.service.controller",
"modelPackage":"com.jackqt.backend.service.model",
"invokerPackage":"com.jackqt.backend.service.util",
"basePackage":"com.jackqt.backend.service",
"configPackage":"com.jackqt.backend.service.config",
"interfaceOnly":"false"
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For customize the generated code, just add configuration file, like:
config.json
into the project folder somewhere, and addconfigurationFile
element under<configuration>
element, for example: