Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jimschubert/0aae4406893284a33cdd9e66ccfe3af1 to your computer and use it in GitHub Desktop.
Save jimschubert/0aae4406893284a33cdd9e66ccfe3af1 to your computer and use it in GitHub Desktop.
Swagger Codegen Maven Plugin standalone example
  1. Save as pom.xml to an empty directory.
<?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>

    <groupId>IO.Swagger.Petstore</groupId>
    <artifactId>io.swagger.petstore</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.2.3-SNAPSHOT</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>http://petstore.swagger.io/v2/swagger.json</inputSpec>
                            <language>csharp</language>
                            <packageName>IO.Swagger.Petstore</packageName>
                            <modelPackage>IO.Swagger.Petstore.Models</modelPackage>
                            <apiPackage>IO.Swagger.Petstore.Apis</apiPackage>
                            <generateApiTests>false</generateApiTests>
                            <generateModelDocumentation>false</generateModelDocumentation>
                            <generateApiDocumentation>false</generateApiDocumentation>
                            <configOptions>
                                <targetFramework>v4.5</targetFramework>
                                <packageVersion>0.0.1</packageVersion>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
  1. Run mvn package

This outputs the expected folder structure (notice that I skipped api docs, model docs, and api tests to demonstrate the options working):

$ tree target/generated-sources/swagger/
target/generated-sources/swagger/
├── IO.Swagger.sln
├── README.md
├── build.bat
├── build.sh
├── git_push.sh
├── mono_nunit_test.sh
└── src
    ├── IO.Swagger
    │   ├── Client
    │   │   ├── ApiClient.cs
    │   │   ├── ApiException.cs
    │   │   ├── ApiResponse.cs
    │   │   ├── Configuration.cs
    │   │   ├── ExceptionFactory.cs
    │   │   └── IApiAccessor.cs
    │   ├── IO.Swagger.Petstore.Apis
    │   │   ├── PetApi.cs
    │   │   ├── StoreApi.cs
    │   │   └── UserApi.cs
    │   ├── IO.Swagger.Petstore.Models
    │   │   ├── ApiResponse.cs
    │   │   ├── Category.cs
    │   │   ├── Order.cs
    │   │   ├── Pet.cs
    │   │   ├── Tag.cs
    │   │   └── User.cs
    │   ├── IO.Swagger.csproj
    │   ├── IO.Swagger.nuspec
    │   ├── Properties
    │   │   └── AssemblyInfo.cs
    │   └── packages.config
    └── IO.Swagger.Test
        ├── IO.Swagger.Petstore.Models
        │   ├── ApiResponseTests.cs
        │   ├── CategoryTests.cs
        │   ├── OrderTests.cs
        │   ├── PetTests.cs
        │   ├── TagTests.cs
        │   └── UserTests.cs
        ├── IO.Swagger.Test.csproj
        └── packages.config

8 directories, 33 files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment