flowable-engine icon indicating copy to clipboard operation
flowable-engine copied to clipboard

generate client java sdk using swagger

Open mgrouch opened this issue 9 years ago • 1 comments

I modified flowable-rest pom.xml adding 2 more profiles

        <profile>
            <id>swag</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.kongchen</groupId>
                        <artifactId>swagger-maven-plugin</artifactId>
                        <version>3.1.4</version>
                        <configuration>
                            <apiSources>
                                <apiSource>
                                    <springmvc>true</springmvc>
                                    <locations>
                                        <location>org.flowable.rest</location>
                                    </locations>
                                    <schemes>
                                        <scheme>http</scheme>
                                        <scheme>https</scheme>
                                    </schemes>
                                    <host>localhost:8080</host>
                                    <basePath>/flowable-task/api</basePath>
                                    <info>
                                        <title>Swagger Maven Plugin Sample</title>
                                        <version>v1</version>
                                        <!-- use markdown here because I'm using markdown for output,
                                        if you need to use html or other markup language, you need to use your target language,
                                         and note escape your description for xml -->
                                        <description>
                                            This is a sample.
                                        </description>
                                        <termsOfService>
                                            http://www.github.com/kongchen/swagger-maven-plugin
                                        </termsOfService>
                                        <contact>
                                            <email>[email protected]</email>
                                            <name>Kong Chen</name>
                                            <url>http://kongch.com</url>
                                        </contact>
                                        <license>
                                            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
                                            <name>Apache 2.0</name>
                                        </license>
                                    </info>
                                    <!--<securityDefinitions>-->
                                    <!--<securityDefinition>-->
                                    <!--<name>basicAuth</name>-->
                                    <!--<type>basic</type>-->
                                    <!--</securityDefinition>-->
                                    <!--<securityDefinition>-->
                                    <!--<json>/securityDefinition.json</json>-->
                                    <!--</securityDefinition>-->
                                    <!--</securityDefinitions>-->
                                    <!-- Support classpath or file absolute path here.
                                    1) classpath e.g: "classpath:/markdown.hbs", "classpath:/templates/hello.html"
                                    2) file e.g: "${basedir}/src/main/resources/markdown.hbs",
                                        "${basedir}/src/main/resources/template/hello.html" -->
                                    <!--<templatePath>${basedir}/src/test/resources/strapdown.html.hbs</templatePath>-->
                                    <!--<outputPath>${basedir}/generated/document.html</outputPath>-->
                                    <swaggerDirectory>${basedir}/target/generated/swagger</swaggerDirectory>
                                    <!--<swaggerApiReader>com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader</swaggerApiReader>-->
                                    <attachSwaggerArtifact>true</attachSwaggerArtifact>
                                    <!--<modelConverters>io.swagger.validator.BeanValidator</modelConverters>-->
                                </apiSource>
                            </apiSources>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>compile</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>
                        <dependencies>
                            <!-- Adding dependency to swagger-hibernate-validations to enable the BeanValidator as a custom
                                 model converter -->
                            <dependency>
                                <groupId>io.swagger</groupId>
                                <artifactId>swagger-hibernate-validations</artifactId>
                                <version>1.5.6</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>swag-gen</id>
            <dependencies>
                <dependency>
                    <groupId>org.glassfish.jersey.core</groupId>
                    <artifactId>jersey-client</artifactId>
                    <version>${jersey-version}</version>
                </dependency>
                <dependency>
                    <groupId>org.glassfish.jersey.media</groupId>
                    <artifactId>jersey-media-multipart</artifactId>
                    <version>${jersey-version}</version>
                </dependency>
                <dependency>
                    <groupId>org.glassfish.jersey.media</groupId>
                    <artifactId>jersey-media-json-jackson</artifactId>
                    <version>2.22.1</version>
                </dependency>

                <!-- JSON processing: jackson -->
                <dependency>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                    <version>${jackson-version}</version>
                </dependency>
                <dependency>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                    <version>${jackson-version}</version>
                </dependency>
                <dependency>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                    <version>${jackson-version}</version>
                </dependency>
                <dependency>
                    <groupId>com.fasterxml.jackson.datatype</groupId>
                    <artifactId>jackson-datatype-joda</artifactId>
                    <version>2.1.5</version>
                </dependency>
                <dependency>
                    <groupId>joda-time</groupId>
                    <artifactId>joda-time</artifactId>
                    <version>${jodatime-version}</version>
                </dependency>
                <dependency>
                    <groupId>com.squareup.okhttp</groupId>
                    <artifactId>okhttp</artifactId>
                    <version>2.7.5</version>
                </dependency>
                <!-- Base64 encoding that works in both JVM and Android -->
                <dependency>
                    <groupId>com.brsanthu</groupId>
                    <artifactId>migbase64</artifactId>
                    <version>2.2</version>
                </dependency>

                <!-- test dependencies -->
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>${junit-version}</version>
                    <scope>compile</scope>
                </dependency>
            </dependencies>
            <properties>
                <swagger-core-version>1.5.8</swagger-core-version>
                <jersey-version>2.22.2</jersey-version>
                <jackson-version>2.7.0</jackson-version>
                <jodatime-version>2.9.3</jodatime-version>
                <maven-plugin-version>1.0.0</maven-plugin-version>
                <junit-version>4.12</junit-version>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-codegen-maven-plugin</artifactId>
                        <version>2.2.1</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <configuration>
                                    <inputSpec>target/generated/swagger/swagger.json</inputSpec>
                                    <language>java</language>
                                    <configOptions>
                                        <sourceFolder>src/gen/java/main</sourceFolder>
                                        <dateLibrary>joda</dateLibrary>
                                    </configOptions>
                                    <library>jersey2</library>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

The following sequence mvn compile -Pswag mvn compile -Pswag-gen

generates a client API.

I hope this helps

Thanks, --MG

mgrouch avatar Feb 02 '17 00:02 mgrouch

Please create a PR for code / config changes. Not issues.

yvoswillens avatar Feb 04 '17 13:02 yvoswillens