Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #34 from SmartBear/2.3.1
Browse files Browse the repository at this point in the history
2.3.1
  • Loading branch information
Ole Lensmar committed Jun 2, 2016
2 parents ab0043b + f2600b7 commit 9a7225d
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 102 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Download and install via the Plugin Manager / Repository Browser from inside Rea

### Release History

* Feb 2016 - Version 2.3.0 - Creates sample messages for POST/PUT requests / responses, dependency updates, bugfixes
* March 2015 - Version 2.1 - Bug-fix release which ties into the updated plugin system in Ready! API and adds dynamic swagger generation for REST Virts
* September 2014 - Version 2.0 - Initial release for Ready! API with Swagger 2.0 support

Expand Down
68 changes: 47 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,31 @@

<groupId>com.smartbear</groupId>
<artifactId>soapui-swagger-plugin</artifactId>
<version>2.1</version>
<version>2.3.1</version>

<name>Ready! API Swagger plugin</name>

<properties>
<jackson-version>2.4.2</jackson-version>
<swagger-version>1.5.8</swagger-version>
<swagger-parser.version>1.0.19</swagger-parser.version>
<swagger-inflector.version>1.0.6</swagger-inflector.version>
</properties>

<repositories>
<repository>
<id>soapUI Repository</id>
<url>http://www.soapui.org/repository/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

Expand All @@ -32,9 +51,15 @@
</dependency>

<dependency>
<groupId>com.smartbear</groupId>
<groupId>com.smartbear</groupId>
<artifactId>swagger4j</artifactId>
<version>1.0-beta5</version>
<version>1.0-beta6</version>
</dependency>

<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-inflector</artifactId>
<version>${swagger-inflector.version}</version>
</dependency>

<dependency>
Expand All @@ -43,35 +68,34 @@
<version>1.5</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.3</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.smartbear</groupId>
<artifactId>ready-api-soapui-pro</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</dependency>

<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-models</artifactId>
<version>${swagger-version}</version>
</dependency>

<dependency>
<groupId>com.wordnik</groupId>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>${swagger-version}</version>
</dependency>

<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-annotations</artifactId>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>${swagger-version}</version>
</dependency>

Expand All @@ -84,7 +108,7 @@
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-parser</artifactId>
<version>1.0.0</version>
<version>${swagger-parser.version}</version>
</dependency>

<dependency>
Expand All @@ -106,6 +130,13 @@
<version>${jackson-version}</version>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.16</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand All @@ -122,6 +153,7 @@
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<configuration>
<source>${project.basedir}/src/main/groovy</source>
<providerSelection>1.8</providerSelection>
</configuration>
<executions>
Expand Down Expand Up @@ -149,10 +181,4 @@
</plugins>

</build>
<name>SoapUI Swagger plugin</name>

<properties>
<jackson-version>2.4.2</jackson-version>
<swagger-version>1.5.1-M1</swagger-version>
</properties>
</project>
6 changes: 3 additions & 3 deletions src/assembly/dist-assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<include>javax.json:javax.json-api</include>
<include>commons-lang:commons-lang</include>
<include>io.swagger:swagger-parser</include>
<include>com.wordnik:swagger-models</include>
<include>com.wordnik:swagger-core</include>
<include>com.wordnik:swagger-annotations</include>
<include>io.swagger:swagger-core</include>
<include>io.swagger:swagger-models</include>
<include>io.swagger:swagger-inflector</include>
<include>com.fasterxml.jackson.core:jackson-annotations</include>
<include>com.fasterxml.jackson.core:jackson-core</include>
<include>com.fasterxml.jackson.core:jackson-databind</include>
Expand Down
11 changes: 9 additions & 2 deletions src/main/groovy/com/smartbear/swagger/AddSwaggerAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void perform(final WsdlProject project, Object param) {
if (dialog == null) {
dialog = ADialogBuilder.buildDialog(Form.class);
dialog.setValue(Form.TYPE, RESOURCE_LISTING_TYPE);
dialog.setValue(Form.DEFAULTMEDIATYPE, SwaggerUtils.DEFAULT_MEDIA_TYPE);
} else {
dialog.setValue(Form.SWAGGERURL, "");
}
Expand All @@ -71,7 +72,11 @@ public void perform(final WsdlProject project, Object param) {
expUrl = new File(expUrl).toURI().toURL().toString();
}

SwaggerImporter importer = SwaggerUtils.importSwaggerFromUrl(project, expUrl, dialog.getValue(Form.TYPE).equals(RESOURCE_LISTING_TYPE));
SwaggerImporter importer = SwaggerUtils.importSwaggerFromUrl(
project,
expUrl,
dialog.getValue(Form.TYPE).equals(RESOURCE_LISTING_TYPE),
dialog.getValue(Form.DEFAULTMEDIATYPE));
Analytics.trackAction("ImportSwagger", "Importer", importer.getClass().getSimpleName());
break;
}
Expand All @@ -81,12 +86,14 @@ public void perform(final WsdlProject project, Object param) {
}
}


@AForm(name = "Add Swagger Definition", description = "Creates a REST API from the specified Swagger definition")
public interface Form {
@AField(name = "Swagger Definition", description = "Location or URL of Swagger definition", type = AFieldType.FILE)
public final static String SWAGGERURL = "Swagger Definition";

@AField(name = "Default Media Type", description = "Default Media Type of the responses", type = AFieldType.STRING)
public final static String DEFAULTMEDIATYPE = "Default Media Type";

@AField(name = "Definition Type", description = "Resource Listing or API Declaration",
type = AFieldType.RADIOGROUP, values = {RESOURCE_LISTING_TYPE, API_DECLARATION_TYPE})
public final static String TYPE = "Definition Type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void perform(WorkspaceImpl workspace, Object param) {
if (dialog == null) {
dialog = ADialogBuilder.buildDialog(Form.class);
dialog.setValue(Form.TYPE, RESOURCE_LISTING_TYPE);
dialog.setValue(Form.DEFAULTMEDIATYPE, SwaggerUtils.DEFAULT_MEDIA_TYPE);
dialog.getFormField(Form.SWAGGERURL).addFormFieldListener(new XFormFieldListener() {
@Override
public void valueChanged(XFormField sourceField, String newValue, String oldValue) {
Expand Down Expand Up @@ -85,7 +86,11 @@ public void valueChanged(XFormField sourceField, String newValue, String oldValu
expUrl = new File(expUrl).toURI().toURL().toString();
}

SwaggerImporter importer = SwaggerUtils.importSwaggerFromUrl(project, expUrl, dialog.getValue(Form.TYPE).equals(RESOURCE_LISTING_TYPE));
SwaggerImporter importer = SwaggerUtils.importSwaggerFromUrl(
project,
expUrl,
dialog.getValue(Form.TYPE).equals(RESOURCE_LISTING_TYPE),
dialog.getValue(Form.DEFAULTMEDIATYPE));
Analytics.trackAction("CreateSwaggerProject", "Importer", importer.getClass().getSimpleName());

break;
Expand Down Expand Up @@ -126,6 +131,9 @@ public interface Form {
@AField(name = "Swagger Definition", description = "Location or URL of Swagger definition", type = AFieldType.FILE)
public final static String SWAGGERURL = "Swagger Definition";

@AField(name = "Default Media Type", description = "Default Media Type of the responses", type = AFieldType.STRING)
public final static String DEFAULTMEDIATYPE = "Default Media Type";

@AField(name = "Definition Type", description = "Resource Listing or API Declaration",
type = AFieldType.RADIOGROUP, values = {RESOURCE_LISTING_TYPE, API_DECLARATION_TYPE})
public final static String TYPE = "Definition Type";
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/com/smartbear/swagger/PluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Created by ole on 08/06/14.
*/

@PluginConfiguration(groupId = "com.smartbear.soapui.plugins", name = "Swagger Plugin", version = "2.1",
@PluginConfiguration(groupId = "com.smartbear.soapui.plugins", name = "Swagger Plugin", version = "2.3.1",
autoDetect = true, description = "Provides Swagger 1.X/2.0 import/export functionality for REST APIs",
infoUrl = "https://github.com/olensmar/soapui-swagger-plugin")
public class PluginConfig extends PluginAdapter {
Expand Down
49 changes: 46 additions & 3 deletions src/main/groovy/com/smartbear/swagger/Swagger1XImporter.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ package com.smartbear.swagger

import com.eviware.soapui.SoapUI
import com.eviware.soapui.impl.rest.RestMethod
import com.eviware.soapui.impl.rest.RestRepresentation
import com.eviware.soapui.impl.rest.RestRequestInterface
import com.eviware.soapui.impl.rest.RestResource
import com.eviware.soapui.impl.rest.RestService
import com.eviware.soapui.impl.rest.RestServiceFactory
import com.eviware.soapui.impl.rest.support.RestParameter
import com.eviware.soapui.impl.rest.support.RestParamsPropertyHolder.ParameterStyle
import com.eviware.soapui.impl.wsdl.InterfaceFactoryRegistry
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.smartbear.swagger4j.ApiDeclaration
import com.smartbear.swagger4j.Parameter
Expand All @@ -42,9 +44,21 @@ import com.smartbear.swagger4j.Swagger
class Swagger1XImporter implements SwaggerImporter {

private final WsdlProject project
private final String defaultMediaType;
private final boolean forRefactoring

public Swagger1XImporter(WsdlProject project) {
public Swagger1XImporter(WsdlProject project, String defaultMediaType) {
this(project, defaultMediaType, false)
}

public Swagger1XImporter(WsdlProject project, String defaultMediaType, boolean forRefactoring) {
this.project = project
this.defaultMediaType = defaultMediaType
this.forRefactoring = forRefactoring;
}

public Swagger1XImporter(WsdlProject project) {
this(project, "application/json")
}

public RestService[] importSwagger(String url) {
Expand Down Expand Up @@ -124,8 +138,15 @@ class Swagger1XImporter implements SwaggerImporter {
// loop all operations - import as methods
it.operations.each {
it
def operation = it

RestMethod method = resource.addNewMethod(it.nickName)
def methodName = it.nickName
def cnt = 0
while (resource.getRestMethodByName(methodName) != null) {
methodName = it.nickName + " " + (++cnt)
}

RestMethod method = resource.addNewMethod(methodName)
method.method = RestRequestInterface.HttpMethod.valueOf(it.method.name().toUpperCase())
method.description = it.summary

Expand All @@ -150,10 +171,30 @@ class Swagger1XImporter implements SwaggerImporter {
SoapUI.logError(e);
}

p.description = it.description
p.required = it.required
}
}

it.responseMessages?.each {
def response = it

if (operation.produces == null || operation.produces.empty) {
def representation = method.addNewRepresentation(RestRepresentation.Type.RESPONSE)

representation.status = [response.code]
representation.mediaType = defaultMediaType
representation.sampleContent = response.message
} else {
operation.produces?.each {
def representation = method.addNewRepresentation(RestRepresentation.Type.RESPONSE)
representation.mediaType = it
representation.status = [response.code]
representation.sampleContent = response.message
}
}
}

// add a default request for the generated method
method.addNewRequest("Request 1")
}
Expand All @@ -163,7 +204,9 @@ class Swagger1XImporter implements SwaggerImporter {
}

private RestService createRestService(String path, String name) {
RestService restService = project.addNewInterface(name, RestServiceFactory.REST_TYPE)
RestService restService = forRefactoring ?
InterfaceFactoryRegistry.createNew(project, RestServiceFactory.REST_TYPE, name) :
project.addNewInterface(name, RestServiceFactory.REST_TYPE)

if (path != null) {
try {
Expand Down
28 changes: 16 additions & 12 deletions src/main/groovy/com/smartbear/swagger/Swagger2Exporter.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ import com.eviware.soapui.impl.rest.support.RestParamsPropertyHolder
import com.eviware.soapui.impl.rest.support.RestParamsPropertyHolder.ParameterStyle
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.fasterxml.jackson.databind.ObjectMapper
import com.wordnik.swagger.models.Info
import com.wordnik.swagger.models.Operation
import com.wordnik.swagger.models.Path
import com.wordnik.swagger.models.Response
import com.wordnik.swagger.models.Swagger
import com.wordnik.swagger.models.parameters.BodyParameter
import com.wordnik.swagger.models.parameters.HeaderParameter
import com.wordnik.swagger.models.parameters.Parameter
import com.wordnik.swagger.models.parameters.PathParameter
import com.wordnik.swagger.models.parameters.QueryParameter
import com.wordnik.swagger.util.Json
import com.wordnik.swagger.util.Yaml
import io.swagger.models.Info
import io.swagger.models.Operation
import io.swagger.models.Path
import io.swagger.models.Response
import io.swagger.models.Swagger
import io.swagger.models.parameters.BodyParameter
import io.swagger.models.parameters.HeaderParameter
import io.swagger.models.parameters.Parameter
import io.swagger.models.parameters.PathParameter
import io.swagger.models.parameters.QueryParameter
import io.swagger.util.Json
import io.swagger.util.Yaml

/**
* A simple Swagger exporter - now uses swagger4j library
Expand Down Expand Up @@ -74,6 +74,10 @@ class Swagger2Exporter implements SwaggerExporter {
operation.addConsumes(it.mediaType)
}

if (operation.responses.isEmpty()) {
operation.addResponse(200, new Response())
}

p.set(it.method.name().toLowerCase(), operation)

addParametersToOperation(it.params, operation)
Expand Down
Loading

0 comments on commit 9a7225d

Please sign in to comment.