dk.swissarmyronin:swagger-packaging-maven-plugin

A packaging plugin for storing versioned Swagger files in a repository.

License

License

Categories

Categories

Maven Build Tools Swagger Program Interface REST Frameworks
GroupId

GroupId

dk.swissarmyronin
ArtifactId

ArtifactId

swagger-packaging-maven-plugin
Last Version

Last Version

1.2
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

dk.swissarmyronin:swagger-packaging-maven-plugin
A packaging plugin for storing versioned Swagger files in a repository.
Project URL

Project URL

https://github.com/SwissArmyRonin/swagger-packaging-maven-plugin
Source Code Management

Source Code Management

https://github.com/SwissArmyRonin/swagger-packaging-maven-plugin

Download swagger-packaging-maven-plugin

How to add to project

<plugin>
    <groupId>dk.swissarmyronin</groupId>
    <artifactId>swagger-packaging-maven-plugin</artifactId>
    <version>1.2</version>
</plugin>

Dependencies

compile (3)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 2.0
org.codehaus.plexus : plexus-utils jar 3.0.8
org.apache.maven : maven-core jar 3.1.1

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.2

test (1)

Group / Artifact Type Version
junit : junit jar 4.8.2

Project Modules

There are no modules declared in this project.

Swagger definition packaging

This plugin allows developers to treat Swagger YAML files as Maven modules. Swagger files are installed in the local repository and can be deployed to remote repositories.

Usage

NB: There is a problem with version 1.2, so the examples below use version 1.1.

To create a Swagger definition module, create a project containing the Swagger YAML definition with a POM file like the one in this example:

<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>dk.swissarmyronin.services</groupId>
  <artifactId>example-service</artifactId>
  <version>1.0</version>
  <packaging>swagger</packaging>
  <build>
    <plugins>
      <plugin>
        <groupId>dk.swissarmyronin</groupId>
        <artifactId>swagger-packaging-maven-plugin</artifactId>
        <version>1.1</version>
        <extensions>true</extensions>
        <configuration>
          <sourceDir>${basedir}/src/main/resources</sourceDir> <!-- Optional: defaults to ${project.basedir} -->
          <swaggerFile>example.yaml</swaggerFile> <!-- Optional: defaults to "${project.artifactId}.yaml" -->
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

To use the file for code generation in another project, insert the following plugin snippets in that project's POM file:

...
<plugins>
  <plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.0.2</version>
    <executions>
      <execution>
        <id>copy-swagger</id>
        <phase>initialize</phase>
        <goals>
          <goal>copy</goal>
        </goals>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>dk.tmnet.tmt</groupId>
              <artifactId>example-service</artifactId>
              <version>1.0</version>
              <type>yaml</type>
              <outputDirectory>${project.basedir}/src/main/resources</outputDirectory>
              <destFileName>example-service.yaml</destFileName>
            </artifactItem>
          </artifactItems>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.2.3</version>
    <executions>
      <execution>
        <id>generate-swagger</id>
        <goals>
          <goal>generate</goal>
        </goals>
        <configuration>
          <inputSpec>${project.basedir}/src/main/resources/example-service.yaml</inputSpec>
          <language>jaxrs</language>
          <output>${project.build.directory}/generated-sources/swagger</output>
        </configuration>
      </execution>
    </executions>
  </plugin>
...

If you have other projects, say Angular or .NET projects that need the Swagger file, they can download it at build time with the following command line (provided they have Maven installed):

mvn dependency:copy -Dartifact=dk.swissarmyronin.services:example-service:1.0:yaml -DoutputDirectory=.

... outputs "example-service-1.0.yaml" to current directory.

dk.swissarmyronin

SwissArmyRonin

Versions

Version
1.2
1.1