swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.94k stars 6.03k forks source link

codegen 2.0 maven integration #343

Closed SirWellington closed 9 years ago

SirWellington commented 9 years ago

I'm looking for something like this that works with the 2.0 Spec. I've noticed that things have changed quite significantly since that was posted.

fehguy commented 9 years ago

Yes, it's quite simple with the 2.0 spec (from the develop_2.0 branch).

<project>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>my-test-app</artifactId>
  <groupId>my-test-group</groupId>
  <version>1.0-SNAPSHOT</version>
  <profiles>
    <profile>
      <id>java</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <configuration>
              <mainClass>com.wordnik.swagger.codegen.Codegen</mainClass>
              <arguments>
                <argument>-l</argument>
                <argument>java</argument>
                <argument>-i</argument>
                <!-- can pass a file or http location -->
                <argument>http://petstore.swagger.wordnik.com/v2/swagger.json</argument>
              </arguments>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>objc</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <configuration>
              <mainClass>com.wordnik.swagger.codegen.Codegen</mainClass>
              <arguments>
                <argument>-l</argument>
                <argument>objc</argument>
                <argument>-i</argument>
                <argument>http://petstore.swagger.wordnik.com/v2/swagger.json</argument>
              </arguments>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  <dependencies>
    <dependency>
      <groupId>com.wordnik</groupId>
      <artifactId>swagger-codegen</artifactId>
      <version>${swagger-codegen-version}</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <id>sonatype-snapshots</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
  <properties>
    <swagger-codegen-version>2.1.0-SNAPSHOT</swagger-codegen-version>
  </properties>
</project>

You simply execute like such:

# generate objc client
mvn exec:java -Pobjc

# generate java client
mvn exec:java -Pjava
SirWellington commented 9 years ago

Excellent! Thank you. I'll give it a try and post back.

fehguy commented 9 years ago

please reopen with questions