swagger-api / swaggerhub-maven-plugin Goto Github PK
View Code? Open in Web Editor NEWA simple maven plugin to access SwaggerHub hosting of OpenAPI/Swagger from a maven build process.
License: Apache License 2.0
A simple maven plugin to access SwaggerHub hosting of OpenAPI/Swagger from a maven build process.
License: Apache License 2.0
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.
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.
Plugin generates an incomplete JSON schema, more details as follows
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?
There's a formatting issue with the API definition string being saved to SwaggerHub in the upload
goal which prevents definition from being rendered correctly in the front-end, e.g. this definition was uploaded via this plugin and isn't rendering https://app.swaggerhub.com/apis/john-french/HackathonTest/1.0.1-SNAPSHOT.
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
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
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
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
We have wrapped swaggerhub-maven-plugin to provide the following goals for our organization:
This gives us 2 benefits for us;
Point 1 is not interesting to contribute back, but is there any interest in a contribution of syncFile and syncDirectory?
Customized version of the swaggerhub-maven-plugin.
Customizations include
<plugin>
<groupId>XX.ORGANISATION.maven</groupId>
<artifactId>ORGANISATION-swaggerhub-maven-plugin</artifactId>
<version>3.0.0</version>
</plugin>
The get
goal can be used to retrieve an API specification from swaggerhub and store it locally for further processing.
<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>
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
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
!
<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>
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
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.
<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>
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
-
-
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:
paths
specified in the specication => Domainpaths
specified in the specication => APIThese 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 |
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 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 ?
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.
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>
I've started using domains in my APIs but this tool cannot upload or download them
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.