logo swagger-codegen (maven-plugin)

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.

homepage: github.com/swagger-api/swagger-codegen
fresh index:
last release: 2 months ago, first release: 6 years ago
packaging: maven-plugin
get this artifact from: central
see this artifact on: search.maven.org


Display vulnerabilities (snyk): Vulnerability check

This chart shows how much is this artifact used as a dependency in other Maven artifacts in Central repository and GitHub:


select version:

Add this snippet into pom.xml inside tag <project><build><plugins>:




Switch to artifact.
goals:
swagger-codegen:generate (phase: generate-sources)

Goal which generates client/server code from a swagger json/yaml definition.

swagger-codegen:help

Display help information on swagger-codegen-maven-plugin. Call mvn swagger-codegen:help -Ddetail=true -Dgoal=<goal-name> to display parameter details.

Often used code snippets:

<plugin>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-codegen-maven-plugin</artifactId>
  <executions>
    <execution>
      <phase>site</phase>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>
                                ${project.parent.parent.basedir}/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin/src/main/resources/admin-api.yaml
                            </inputSpec>
        <language>org.wso2.carbon.apimgt.rest.api.util.codegen.DynamicHtmlGen</language>
        <templateDirectory>
                                ${project.parent.parent.basedir}/components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/resources/doc-templates
                            </templateDirectory>
        <output>src/main/resources/api-docs</output>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.wso2.carbon.apimgt</groupId>
      <artifactId>org.wso2.carbon.apimgt.rest.api.util</artifactId>
      <version>${carbon.apimgt.version}</version>
    </dependency>
  </dependencies>
</plugin>
<plugin>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-codegen-maven-plugin</artifactId>
  <executions>
    <execution>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.basedir}/src/main/resources/store-api.yaml</inputSpec>
        <language>jaxrs-cxf-cdi</language>
        <configOptions>
          <apiPackage>org.wso2.carbon.apimgt.rest.api.store.v1</apiPackage>
          <modelPackage>org.wso2.carbon.apimgt.rest.api.store.v1.dto</modelPackage>
          <sourceFolder>src/gen/java</sourceFolder>
          <dateLibrary>java8</dateLibrary>
          <hideGenerationTimestamp>true</hideGenerationTimestamp>
        </configOptions>
        <output>.</output>
        <templateDirectory>
                                ../org.wso2.carbon.apimgt.rest.api.util/src/main/resources/server-templates
                            </templateDirectory>
        <skipOverwrite>true</skipOverwrite>
        <modelNameSuffix>DTO</modelNameSuffix>
      </configuration>
    </execution>
    <execution>
      <id>generate-apidocs</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.basedir}/src/main/resources/store-api.yaml</inputSpec>
        <language>org.wso2.carbon.apimgt.rest.api.util.codegen.DynamicHtmlGen</language>
        <templateDirectory>
                                ../org.wso2.carbon.apimgt.rest.api.util/src/main/resources/doc-templates
                            </templateDirectory>
        <output>${project.build.directory}/apidocs</output>
      </configuration>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-codegen-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>generate-server-stubs</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.basedir}/src/main/resources/publisher-api.yaml</inputSpec>
        <language>jaxrs-cxf-cdi</language>
        <configOptions>
          <apiPackage>org.wso2.carbon.apimgt.rest.api.publisher.v1</apiPackage>
          <modelPackage>org.wso2.carbon.apimgt.rest.api.publisher.v1.dto</modelPackage>
          <sourceFolder>src/gen/java</sourceFolder>
          <dateLibrary>java8</dateLibrary>
          <hideGenerationTimestamp>true</hideGenerationTimestamp>
        </configOptions>
        <output>.</output>
        <templateDirectory>
                                ../org.wso2.carbon.apimgt.rest.api.util/src/main/resources/server-templates
                            </templateDirectory>
        <skipOverwrite>true</skipOverwrite>
        <modelNameSuffix>DTO</modelNameSuffix>
      </configuration>
    </execution>
    <execution>
      <id>generate-apidocs</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.basedir}/src/main/resources/publisher-api.yaml</inputSpec>
        <language>org.wso2.carbon.apimgt.rest.api.util.codegen.DynamicHtmlGen</language>
        <templateDirectory>
                                ../org.wso2.carbon.apimgt.rest.api.util/src/main/resources/doc-templates
                            </templateDirectory>
        <output>${project.build.directory}/apidocs</output>
      </configuration>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-codegen-maven-plugin</artifactId>
  <executions>
    <execution>
      <phase>site</phase>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>
                                ${project.parent.parent.basedir}/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher/src/main/resources/publisher-api.yaml
                            </inputSpec>
        <language>org.wso2.carbon.apimgt.rest.api.util.codegen.DynamicHtmlGen</language>
        <templateDirectory>
                                ${project.parent.parent.basedir}/components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/resources/doc-templates
                            </templateDirectory>
        <output>src/main/resources/api-docs</output>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.wso2.carbon.apimgt</groupId>
      <artifactId>org.wso2.carbon.apimgt.rest.api.util</artifactId>
      <version>${carbon.apimgt.version}</version>
    </dependency>
  </dependencies>
</plugin>
<plugin>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-codegen-maven-plugin</artifactId>
  <version>${swagger-codegen-maven-plugin.version}</version>
  <executions>
    <execution>
      <phase>site</phase>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>
                                ${project.parent.parent.basedir}/components/apimgt/org.wso2.carbon.apimgt.rest.api.store/src/main/resources/store-api.yaml
                            </inputSpec>
        <language>org.wso2.carbon.apimgt.rest.api.util.codegen.DynamicHtmlGen</language>
        <templateDirectory>
                                ${project.parent.parent.basedir}/components/apimgt/org.wso2.carbon.apimgt.rest.api.util/src/main/resources/doc-templates
                            </templateDirectory>
        <output>src/main/resources/api-docs</output>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.wso2.carbon.apimgt</groupId>
      <artifactId>org.wso2.carbon.apimgt.rest.api.util</artifactId>
      <version>${carbon.apimgt.version}</version>
    </dependency>
  </dependencies>
</plugin>

© Jiri Pinkas 2015 - 2022. All rights reserved! Admin login To submit bugs / feature requests please use this github page
related: JavaVids | Top Java Blogs | Java školení
Apache and Apache Maven are trademarks of the Apache Software Foundation. The Central Repository is a service mark of Sonatype, Inc.