Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wsdl2apigee 69550284 v1 #16

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a86951c
Enhanced the tool to define JSON entities local to the corresponding …
Abdul-Kinadiyil May 22, 2018
15238c0
Implemented following changes
Abdul-Kinadiyil May 28, 2018
83dd355
Implemented changes for mapping XML schema restriction element to JSO…
Abdul-Kinadiyil May 29, 2018
50c9001
Fixed OAS JSON entity mapping for array of elements with XML schema r…
Abdul-Kinadiyil May 30, 2018
62ea817
Addressed Following issues
Abdul-Kinadiyil Jun 1, 2018
63b2678
Addressed Following issues
Abdul-Kinadiyil Jun 1, 2018
0e29f68
Update GenerateProxy.java
anilpaduchuri Jun 4, 2018
7da5ef2
Update OASUtils.java
anilpaduchuri Jun 4, 2018
b0bf203
Update GenerateProxy.java
anilpaduchuri Jun 5, 2018
cf97085
Add files via upload
anilpaduchuri Jun 5, 2018
bb5a231
Update targetDefault.xml
anilpaduchuri Jun 5, 2018
95de204
Update GenerateProxy.java
anilpaduchuri Jun 6, 2018
51f7686
Update GenerateProxyTest.java
anilpaduchuri Jun 7, 2018
5f55775
Update GenerateProxyTest.java
anilpaduchuri Jun 7, 2018
ed158f7
Update GenerateProxyTest.java
anilpaduchuri Jun 8, 2018
fa80461
Update pom.xml
anilpaduchuri Jun 8, 2018
b25b5b1
Update GenerateProxy.java
anilpaduchuri Jun 10, 2018
097cf19
Update GenerateProxy.java
anilpaduchuri Jun 11, 2018
dd6a67e
Update OASUtils.java
anilpaduchuri Jun 11, 2018
a40a209
Update GenerateProxy.java
anilpaduchuri Jun 11, 2018
535a494
Update GenerateProxy.java
anilpaduchuri Jun 11, 2018
b439b06
Update OASUtils.java
anilpaduchuri Jun 11, 2018
2e762fd
Update GenerateProxy.java
anilpaduchuri Jun 14, 2018
ac1c03c
Update GenerateProxy.java
anilpaduchuri Jun 18, 2018
ba57aa4
Update README.MD
anilpaduchuri Jun 18, 2018
94bc596
Modified the README file with details on additional options to run th…
Abdul-Kinadiyil Jul 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ java -jar wsdl2apigee-1.0.0-jar-with-dependencies.jar -wsdl=<wsdl URL or Path>

### Other Options
```
java -jar wsdl2apigee-1.0.0-jar-with-dependencies.jar -wsdl=<wsdl URL or Path> -passthru=<true|false> -desc=<description> -allpost=<true|false> -opsmap=<opsmapping.xml> -service=<service name> -port=<port name> -debug=<true|false> -oauth=<true|false> -vhosts=comma separated values for virtuals hosts> -build=<build folder name> -cors=<true|false> -apikey=<true|false> -quota=<true|false> -basepath=<specify base path>
java -jar wsdl2apigee-1.0.0-jar-with-dependencies.jar -wsdl=<wsdl URL or Path> -passthru=<true|false> -desc=<description> -allpost=<true|false> -opsmap=<opsmapping.xml> -service=<service name> -port=<port name> -debug=<true|false> -oauth=<true|false> -vhosts=comma separated values for virtuals hosts> -build=<build folder name> -cors=<true|false> -apikey=<true|false> -quota=<true|false> -basepath=<specify base path> -enableEmptyNodes=<true|false> -enableSoapHeaders=<true|false> -enableRespRootElement=<true|false> -preserveArray=<true|false>

Defaults:
passthru=false Do not convert to API/JSON. Treat as SOAP
Expand All @@ -34,6 +34,10 @@ quota=false Works only if apikey or oauth is set
basepath=Uses the basepath from the wsdl
cors=false Don't enable CORS; Works only for SOAP to REST
build=specify build folder default is temp folder; ensure user has access to read/write to temp folder
enableEmptyNodes=<true|false> default is false; Set to true if empty root element needs to be passed to target service as SOAP operation.
enableSoapHeaders=<true|false> default is false; Set to true if SOAP headers need to be passed to target service.
enableRespRootElement=<true|false> default is false; Set to true if XML root element from backend service needs to be mapped and sent as part of the JSON response.
preserveArray=<true|false> default is false; Set to true if XML arrays in the WSDL needs to be mapped as JSON arrays in the response and OAS specification. This will set "TreatAsArray" option for the array Xpath in XML to JSON policy within the proxy.
opsmap=specify operations map
```
## Output
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,10 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
</project>
</project>
160 changes: 157 additions & 3 deletions src/main/java/com/apigee/oas/OASUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ public static JsonArray getQueryParameters(ArrayList<String> queryParams) {
JsonObject parameter = null;
for (String queryParam : queryParams) {
parameter = new JsonObject();
parameter.addProperty("name", queryParam);
String paramSplit[] = queryParam.split("_");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the query param name itself has an underscore in it? where is this behavior documented?

parameter.addProperty("name", paramSplit[0]);
parameter.addProperty("in", "query");
parameter.addProperty("required", false);
if(paramSplit.length>1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistent spacing please
if (paramSplit.length > 1) {
etc

same comment throughout this PR.

parameter.addProperty("required", Boolean.valueOf(paramSplit[1]));
}else {
parameter.addProperty("required",false);
}

parameter.addProperty("type", "string");
parameters.add(parameter);
}
Expand Down Expand Up @@ -104,6 +110,90 @@ public static void addObject(JsonObject parent, String parentName, String object
properties.add(objectName, object);
}

public static void addObject(JsonObject parent, String parentName, String objectName,boolean isChildComplexType, String qNameLocal) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param parentName is unused? can you give a more descriptive name for qNameLocal?

JsonObject properties = parent.getAsJsonObject("properties");
JsonObject object = new JsonObject();
if(isChildComplexType)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this logic correct? if !isChildComplexType, we're just adding an empty jsonObject to parent's properties?

{
object.addProperty("$ref", "#/definitions/"+qNameLocal);
}
properties.add(objectName, object);

}

/*
* inorder to retrieve inner properties attribute to assign output elements
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is hard to understand. also it looks like you've copy&pasted this comment to several functions, please dedupe.

*
*/
public static void addObjectOutputRes(JsonObject parent, String parentName, String objectName,boolean isChildComplexType, String qNameLocal) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function looks pretty close to the previous one, can we dedupe these and just have the caller pass in the appropriate parent to handle both cases?

JsonObject properties = parent.getAsJsonObject("properties").getAsJsonObject(parentName).getAsJsonObject("properties");
JsonObject object = new JsonObject();
if(isChildComplexType)
{
object.addProperty("$ref", "#/definitions/"+qNameLocal);
}
properties.add(objectName, object);


}

/*
* inorder to retrieve inner properties attribute to assign output elements
*
*/
public static void addObjectOutputArrayProp(JsonObject parent, String parentName, String objectName,
boolean isChildComplexType, String qNameLocal, String subArrayElement) {

if(null != parent.getAsJsonObject("properties").getAsJsonObject(parentName)) {

JsonObject properties = parent.getAsJsonObject("properties").getAsJsonObject(parentName).getAsJsonObject("properties");
JsonObject innerProp = new JsonObject();
JsonObject subArrayJson = new JsonObject();
innerProp.add(subArrayElement, subArrayJson);

JsonObject jsoonOuterProp = new JsonObject();
jsoonOuterProp.add("properties", innerProp);
jsoonOuterProp.addProperty("type", "object");
properties.add(objectName, jsoonOuterProp);
}else {
JsonObject properties = parent.getAsJsonObject("properties");
JsonObject innerProp = new JsonObject();
JsonObject subArrayJson = new JsonObject();
innerProp.add(subArrayElement, subArrayJson);

JsonObject jsoonOuterProp = new JsonObject();
jsoonOuterProp.add("properties", innerProp);
jsoonOuterProp.addProperty("type", "object");
properties.add(objectName, jsoonOuterProp);
}
}

/*
* inorder to retrieve inner properties attribute to assign output elements
*
*/
public static void addObjectOutputForArray(JsonObject parent, String parentName, String objectName,
boolean isChildComplexType, String qNameLocal, String subArrayElement) {

if(null != parent.getAsJsonObject("properties").getAsJsonObject(parentName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the if and else blocks here look identical except for the rep line, can you consolidate this code more?

JsonObject rep = parent.getAsJsonObject("properties").getAsJsonObject(parentName).getAsJsonObject("properties").
getAsJsonObject(objectName).getAsJsonObject("properties").getAsJsonObject(subArrayElement);
JsonObject items = new JsonObject();

items.addProperty("$ref", "#/definitions/"+subArrayElement);
rep.add("items", items);
rep.addProperty("type", "array");
}else {
JsonObject rep = parent.getAsJsonObject("properties").getAsJsonObject(objectName).getAsJsonObject("properties").
getAsJsonObject(subArrayElement);
JsonObject items = new JsonObject();

items.addProperty("$ref", "#/definitions/"+subArrayElement);
rep.add("items", items);
rep.addProperty("type", "array");
}
}

public static JsonObject createComplexType(String name, String min, String max) {
JsonObject complexType = new JsonObject();
JsonObject properties = new JsonObject();
Expand All @@ -122,7 +212,7 @@ public static JsonObject createComplexType(String name, String min, String max)
Integer minimum = Integer.parseInt(min);

complexType.add("properties", properties);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit unneeded whitespace

if (maximum == -1 || maximum > 1) {
complexType.addProperty("type", "array");
//in json schemas, if the elements are unbounded, don't set maxItems
Expand All @@ -134,6 +224,55 @@ public static JsonObject createComplexType(String name, String min, String max)
}
return complexType;
}

public static JsonObject createComplexTypeRep(String name, String min, String max) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused params

JsonObject complexType = new JsonObject();
JsonObject properties = new JsonObject();
complexType.add("properties", properties);

complexType.addProperty("type", "object");
return complexType;
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit consistent newlines please, one blank newline between functions, here and elsewhere

public static JsonObject createExtension(String baseName) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function appears to do the exact same thing as the previous function, plus param is unused

JsonObject extension = new JsonObject();
JsonObject properties = new JsonObject();
extension.addProperty("type", "object");
extension.add("properties", properties);

return extension;
}
public static JsonObject createRestriction(String type, String min, String max) {
JsonObject restriction = createSimpleType(type,min,max);
JsonArray enumArray = new JsonArray();
if(restriction.get("items") != null)
{
JsonObject items = (JsonObject)restriction.get("items");
items.add("enum", enumArray);
}
else
{
restriction.add("enum", enumArray);
}

return restriction;
}

/*
* Method used to create inner properties for each response attribute under #definitions of OAS
*
*/
public static JsonObject createComplexTypeOP(String name, JsonObject jsonObj) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid abbreviations in names, they can be confusing.

JsonObject properties = jsonObj.getAsJsonObject("properties");
JsonObject innerProp = new JsonObject();
JsonObject jsoonOuterProp = new JsonObject();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit spelling jsonOuterProp

jsoonOuterProp.add("properties", innerProp);
properties.add(name, jsoonOuterProp);

return properties;
}


public static JsonObject createSimpleType(String type, String min, String max) {
JsonObject simpleType = new JsonObject();
Expand Down Expand Up @@ -199,5 +338,20 @@ public static JsonObject createSimpleType(String type, String min, String max) {
return simpleType;
}

public static String manipulateQueryParams(String name, String min, String max) {

String queryParamStr = "";
String required = "false";
if (max.equalsIgnoreCase("unbounded")) {
max = "-1";
}
if(Integer.parseInt(min) ==1 && Integer.parseInt(max) ==1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic seems wrong, shouldn't we still consider the param required if min > 1?

required = "true";
}

queryParamStr = queryParamStr.concat(name+"_"+required);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why concat, can we just set queryParamStr's initial value here, or even just return name + "_" + required;

return queryParamStr;
}


}
Loading