Coder Social home page Coder Social logo

swagger-api / swaggerhub-maven-plugin Goto Github PK

View Code? Open in Web Editor NEW
29.0 8.0 21.0 489 KB

A simple maven plugin to access SwaggerHub hosting of OpenAPI/Swagger from a maven build process.

License: Apache License 2.0

Java 100.00%
swaggerhub maven on-prem saas

swaggerhub-maven-plugin's People

Contributors

barry-obrien avatar barryadk avatar echenarch avatar frantuma avatar hkosova avatar joeljons avatar jonathanparrilla avatar jsfrench avatar marczin avatar mend-for-github-com[bot] avatar michaelmelody91 avatar realalknowles avatar torgh avatar webron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swaggerhub-maven-plugin's Issues

Add support to upload apis/domains to a specific project

I seems that the plugin doesn't support uploading to a specific project. If the api/domain already exist, it is properly updated in its project but if it doesn't exist yet, there is now mean to specify in which project it has to be uploaded.

Update Upload/Download Tests to use JUnit4 runner

An issue was found during development that @test(expected = SomeException.class) isn't working as expected. The workaround currently being used is to catch the exception by the Upload/Download execute function and then asserting that a boolean is set to true in the catch block.

Similarly related; when executing Mojo goals within those test classes, params marked as required should cause tests to fail when they are not specified. We have seen on occasions during development and subsequent testing, that isn't the case.

JUnit4 is imported into the project but when the test runner isn't specified, an older version of JUnit is used to run tests. It's hoped that by specifying a runner, that we can solve both issues named above.

Execution config is ignored

Hi,
I've just tried this plugin, but I think there is some problems on configuring the execution:
This is the configuration:

            <groupId>io.swagger</groupId>
            <artifactId>swaggerhub-maven-plugin</artifactId>
            <version>1.0.2</version>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>download</goal>
                    </goals>
                    <configuration>
                        <owner>gerdzhikov</owner>
                        <api>testApi</api>
                        <version>1.0.0</version>
                        <outputFile>target/petStoreAPI.json</outputFile>
                        <token>eyJ...</token>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Runnig Maven with mvn swaggerhub:download -X fails with the following output:

[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal: io.swagger:swaggerhub-maven-plugin:1.0.2:download (default-cli)
[DEBUG] Style: Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<api>${download.api}</api>
<format default-value="json">${download.format}</format>
<host default-value="api.swaggerhub.com">${download.host}</host>
<outputFile>${download.outputFile}</outputFile>
<owner>${download.owner}</owner>
<port default-value="443">${download.port}</port>
<protocol default-value="https">${download.protocol}</protocol>
<token>${download.token}</token>
<version>${download.version}</version>
</configuration>
[DEBUG] =======================================================================
...
[DEBUG] Configuring mojo 'io.swagger:swaggerhub-maven-plugin:1.0.2:download' with basic configurator -->
[DEBUG] (f) format = json
[DEBUG] (f) host = api.swaggerhub.com
[DEBUG] (f) port = 443
[DEBUG] (f) protocol = https
[DEBUG] -- end configuration --
...
[ERROR] Failed to execute goal io.swagger:swaggerhub-maven-plugin:1.0.2:download (default-cli) on project member-module: The parameters 'owner', 'outputFile', 'api', 'version' for goal io.swagger:swaggerhub-maven-plugin:1.0.2:download are missing or invalid -> [Help 1]

When the Maven variables: download.api, download.owner, download.token, download.version and download.outputFile are set in the <properties> section of the POM, than everything work exactley as expected.

Am I doing something wrong, or this is some bug?

Add support for updating default version

We now upload new spec automatically on master build, but it is of little use when we have to manually set it as the default version for it to effectively reach consumers.

Please add an option for bumping the default version on file upload

Add support for downloading resolved specs

My OAS3 spec references a domain - when downloading I would like to get that resolved in the same way as the "Export/Download API/JSON/YAML Resolved" menu actions in SwaggerHub

cannot download due to ssl handshake

running:
mvn generate-resources and get the below...

Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Plugin upload appears to be successful when misconfigured

When specifying configuration to upload a definition to an on-prem SwaggerHub instance with an incorrect base path, the upload is logged as successful. When verifying in SwaggerHub, the API is unavailable and cannot be found.

Sample output for this issue:

[DEBUG] Configuring mojo 'io.swagger:swaggerhub-maven-plugin:1.0.6:upload' with basic configurator -->
[DEBUG]   (f) api = test-upload
[DEBUG]   (f) basepath = /bad-basepath
[DEBUG]   (f) branch = SWAGGERHUB
[DEBUG]   (f) enableScmIntegration = true
[DEBUG]   (f) format = json
[DEBUG]   (f) host = 11.10.1.96
[DEBUG]   (f) inputFile = target/swagger/swagger.json
[DEBUG]   (f) isPrivate = true
[DEBUG]   (f) owner = CC_Freestyle_Org
[DEBUG]   (f) port = 80
[DEBUG]   (f) protocol = http
[DEBUG]   (f) skipFailures = false
[DEBUG]   (f) token = e**********************************7
[DEBUG]   (f) uploadType = inputFile
[DEBUG]   (f) version = 2.5.14.0
[DEBUG] -- end configuration --
[INFO] Uploading to 11.10.1.96, basepath: /bad-basepath: api: test-upload, owner: swagger-owner, version: 2.5.14.0, inputFile: target/swagger/swagger.json, format: json, isPrivate: true, definitionDirectory: null, definitionFileNameRegex: null, uploadType: inputFile, skipFailures: false, token: e**********************************7
[DEBUG] Executing input file based upload...
[INFO] Uploading API name test-upload version 2.5.14.0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

extension with syncDirectory and syncFile goal (and get goal)

We have wrapped swaggerhub-maven-plugin to provide the following goals for our organization:

  • syncFile
  • syncDirectory
  • get (similar to download)

This gives us 2 benefits for us;

  1. default values for a number of properties (host, protocol, basepath, owner) that are shared between development teams
  2. synchronization logic instead of simple upload

Point 1 is not interesting to contribute back, but is there any interest in a contribution of syncFile and syncDirectory?

Below is our readme.md for reference:

ORGANISATION-swaggerhub-maven-plugin

Customized version of the swaggerhub-maven-plugin.

Customizations include

  • ORGANISATION specific defaults to reduce the footprint of the plugin definition in the pom files
  • Custom upload functionality ensuring that existing formal API versions are not overwritten with an updated specification using the same version

Current version

<plugin>
  <groupId>XX.ORGANISATION.maven</groupId>
  <artifactId>ORGANISATION-swaggerhub-maven-plugin</artifactId>
  <version>3.0.0</version>
</plugin>

Goals

get

The get goal can be used to retrieve an API specification from swaggerhub and store it locally for further processing.

Example

<plugin>
  <groupId>XX.ORGANISATION.maven</groupId>
  <artifactId>ORGANISATION-swaggerhub-maven-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>get</goal>
      </goals>
      <configuration>
        <api>...</api>
        <version>...</version>
        <outputFile>...</outputFile>
      </configuration>
    </execution>
  <executions>
</plugin>

Configuration

Property Mandatory Default Purpose
api Y The name of the API in swaggerhub
version Y The semantic version of the API in swaggerhub
outputFile N ${project.build.directory}/openapi-spec.json The output file

See also global configuration

syncDirectory

The syncDirectory goal allows you to synchronize a directory containing specification files with swaggerhub. You will use this sync implementation if you are working code first and generating your specifications. See sync logic for the overall sync logic.
By default this goal will run in the verify phase, so configuration is minimal.
This goal does rely on a number of conventions though, since potentially multiple specifications, both API and DOMAIN, are synchronised.

We expect a certain file format:

[public.|private.]<owner>.<api>[.<majorVersion>]{.json|.yml|.yaml} 

If you want your API or DOMAIN to be private on swaggerhub, you need to include the private. prefix; otherwise the specification will be public.
The owner should typically be ORGANISATION and is the swaggerhub owner of the specification. It is required.
The api is the name of the api or domain on swaggerhub. It is required.
You will need to use majorVersion if you simultaneously support more than 1 major version (otherwise the file names will be identical).
There is a choice between all supported formats and supported OAS version for SwaggerHub.

In contrast with thesyncFile goal, we also expect the semantic version of the API or DOMAIN to be present in the specification under $.info.version!

Example

<plugin>
  <groupId>XX.ORGANISATION.maven</groupId>
  <artifactId>ORGANISATION-swaggerhub-maven-plugin</artifactId>
    <configuration>
      <token>...</token>
    </configuration>
  <executions>
    <execution>
      <goals>
        <goal>syncDirectory</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Configuration

Property Mandatory Default Purpose
directory N ${project.build.directory}/definitionDirectory The directory where de definitions are found
skip N false Skips the execution

See also global configuration

syncFile

The syncFile goal allows you to synchronize a single api specificatin file with swaggerhub. You will use this sync implementation if you are writing an openapi spec from scratch. See sync logic for the overall sync logic.

Example

<plugin>
  <groupId>XX.ORGANISATION.maven</groupId>
  <artifactId>ORGANISATION-swaggerhub-maven-plugin</artifactId>
  <executions>
    <execution>
      <phase>deploy</phase>
      <goals>
        <goal>syncFile</goal>
      </goals>
      <configuration>
        <api>...</api>
        <version>...</version>
        <file>...</file>
        <private>...</private>
      </configuration>
    </execution>
  </executions>
</plugin>

Configuration

Property Mandatory Default Purpose
api Y The name of the API in swaggerhub
version N $.info.version defined in the file The semantic version of the API in swaggerhub
file N ${project.build.directory}/openapi.yaml The file to upload
private N false Indicates if the API is private or public
skip N false Skips the execution

See also global configuration

Sync logic

Snapshot versions

  • a version is considered to be a snapshot if the version contains a -
  • are always uploaded to swaggerhub

Release versions

  • a version is considered to be a release if the version does not contain a -
  • if a release version does not yet exists in swaggerhub the specification will be uploaded
  • if a release version already exists it will first be downloaded and compared with the new one that is going to be uploaded
    ** the build will fail if the 2 specification do not match
    ** nothing will be uploaded if both specifications are the same

API vs. Domain

The original swaggerhub-maven-plugin differentiates both concepts by explicitly specifing if you are uploading an API or a Domain specification.

The customize plugin applies the following rules:

  • no paths specified in the specication => Domain
  • paths specified in the specication => API

Configuration defaults

Global

These are the global configuration properties that can be overridden for every goal

Property Default Purpose
host swaggerhub.ORGANISATION.XX The swaggerhub host name
port 80 The swaggerhub port
protocol http The swaggerhub protocol
basePath v1 The swaggerhub API base path
owner ORGANISATION The default API/Domain owner
skipFailures false Ignore errors when interacting with swaggerhub

Proxy support

Hi,

as far as I have seen, currently the plugin does not support proxies (e.g. from Maven's settings.xml) ?
Is this planned somehow ?
Would you accept pull requests ?

Can't upload openapi.yaml file to swaggerhub

Can't upload to swagger hub

my plugin configuration

<plugin>
  <groupId>io.swagger</groupId>
  <artifactId>swaggerhub-maven-plugin</artifactId>
  <version>1.0.8</version>
  <executions>
	  <execution>
		  <goals>
			  <goal>upload</goal>
		  </goals>
		  <configuration>
			  <api>DtengAPI</api>
			  <owner>${MY_SWAGGER_USERNAME}</owner>
			  <version>0.0.2</version>
			  <inputFile>target/openapi.yaml</inputFile>
			  <token>${SWAGGERHUB_APIKEY}</token>
			  <definitionType>api</definitionType>
			  <uploadType>inputFile</uploadType>
			  <format>yaml</format>
		  </configuration>
	  </execution>
  </executions>
</plugin>

mvn swaggerhub:upload -X

gives

ERROR] Failed to execute goal io.swagger:swaggerhub-maven-plugin:1.0.8:upload (default-cli) on project rest-event-box: The parameters 'owner', 'uploadType', 'token' for goal io.swagger:swaggerhub-maven-plugin:1.0.8:upload are missing or invalid -> [Help 1]

I notice it doesn't seem to pick up my configurations

[DEBUG] Configuring mojo 'io.swagger:swaggerhub-maven-plugin:1.0.8:upload' with basic configurator -->
[DEBUG] (f) branch = SWAGGERHUB
[DEBUG] (f) definitionType = API
[DEBUG] (f) enableScmIntegration = true
[DEBUG] (f) format = json
[DEBUG] (f) host = api.swaggerhub.com
[DEBUG] (f) isPrivate = false
[DEBUG] (f) port = 443
[DEBUG] (f) protocol = https
[DEBUG] (f) skipFailures = false
[DEBUG] -- end configuration --

When I add back the deploy phase I get a different error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project rest-event-box: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]

I don't really want to configure repository to deploy artificats to since I have no need for that ?

Add default lifecycle phases

Neither goal is mapped to a default lifecycle phase so one has to be explicitly defined in the configuration. Each goal should have a sensible default lifecycle phase.

Not able to Upload

Hi,

Am trying to do upload of my proxy to private api governance. But its not uploading. Below is the configuration in the pom.xml:

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swaggerhub-maven-plugin</artifactId>
    <version>1.0.8</version>
    <executions>
        <execution>
            <phase>deploy</phase>
            <goals>
                <goal>upload</goal>
            </goals>
            <configuration>
                <api>demo-apigee</api>
                <owner>Digital-Retail</owner>
                <version>0.2</version>
                <inputFile>sunil/demo-apigee-01.json</inputFile>
                <token>123xyz</token>
                <host>api-governance-corp.falabella.com</host>
                <uploadType>inputFile</uploadType>
                <basepath>v1</basepath>
            </configuration>
        </execution>
    </executions>
</plugin>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.