Skip to content
Snippets Groups Projects
Commit 64458285 authored by Jueun Park's avatar Jueun Park
Browse files

Update attributes

parent 405a0c39
No related branches found
No related tags found
No related merge requests found
Showing
with 491 additions and 421 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
/* This file was generated with JastAdd2 (http://jastadd.org) version 2.3.2 */ /* This file was generated with JastAdd2 (http://jastadd.org) version 2.3.2 */
package de.tudresden.inf.st.openapi.ast; package de.tudresden.inf.st.openapi.ast;
import org.openapi4j.core.exception.ResolutionException; import org.openapi4j.core.exception.ResolutionException;
import org.openapi4j.core.validation.ValidationException; import org.openapi4j.core.validation.ValidationException;
import org.openapi4j.parser.model.v3.*; import org.openapi4j.parser.model.v3.*;
import org.openapi4j.core.model.reference.Reference; import org.openapi4j.core.model.reference.Reference;
import org.openapi4j.core.model.OAIContext; import org.openapi4j.core.model.OAIContext;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.net.URL; import java.net.URL;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import org.openapi4j.core.exception.DecodeException; import org.openapi4j.core.exception.DecodeException;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
...@@ -19,21 +23,22 @@ import java.net.HttpURLConnection; ...@@ -19,21 +23,22 @@ import java.net.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import java.util.Random; import java.util.Random;
import java.util.stream.IntStream; import java.util.stream.IntStream;
/** /**
* @ast node * @ast node
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\OpenAPISpecification.ast:43 * @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\OpenAPISpecification.ast:43
* @astdecl Get : ASTNode ::= OperationObject; * @astdecl Get : ASTNode ::= OperationObject;
* @production Get : {@link ASTNode} ::= <span class="component">{@link OperationObject}</span>; * @production Get : {@link ASTNode} ::= <span class="component">{@link OperationObject}</span>;
*/ */
public class Get extends ASTNode<ASTNode> implements Cloneable { public class Get extends ASTNode<ASTNode> implements Cloneable {
/** /**
* @aspect InferParameter * @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:159 * @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:147
*/ */
public void connectGET(String path) { public void connectGET(String path) {
try{URL url=new URL(path); try {
URL url = new URL(path);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setRequestProperty("User-Agent", "Mozilla/5.0"); // add request header con.setRequestProperty("User-Agent", "Mozilla/5.0"); // add request header
...@@ -51,19 +56,23 @@ public class Get extends ASTNode<ASTNode> implements Cloneable { ...@@ -51,19 +56,23 @@ public class Get extends ASTNode<ASTNode> implements Cloneable {
// print result // print result
System.out.println("Inferred path : " + path); System.out.println("Inferred path : " + path);
System.out.println("HTTP status code (GET) : "+responseCode);}catch(Exception e){ System.out.println("HTTP status code (GET) : " + responseCode);
} catch (Exception e) {
System.out.println(e.toString()); System.out.println(e.toString());
} }
} }
/** /**
* @declaredat ASTNode:1 * @declaredat ASTNode:1
*/ */
public Get() { public Get() {
super(); super();
} }
/** /**
* Initializes the child array to the correct size. * Initializes the child array to the correct size.
* Initializes List and Opt nta children. * Initializes List and Opt nta children.
*
* @apilevel internal * @apilevel internal
* @ast method * @ast method
* @declaredat ASTNode:10 * @declaredat ASTNode:10
...@@ -71,6 +80,7 @@ public class Get extends ASTNode<ASTNode> implements Cloneable { ...@@ -71,6 +80,7 @@ public class Get extends ASTNode<ASTNode> implements Cloneable {
public void init$Children() { public void init$Children() {
children = new ASTNode[1]; children = new ASTNode[1];
} }
/** /**
* @declaredat ASTNode:13 * @declaredat ASTNode:13
*/ */
...@@ -82,12 +92,15 @@ public class Get extends ASTNode<ASTNode> implements Cloneable { ...@@ -82,12 +92,15 @@ public class Get extends ASTNode<ASTNode> implements Cloneable {
public Get(OperationObject p0) { public Get(OperationObject p0) {
setChild(p0, 0); setChild(p0, 0);
} }
/** @apilevel low-level
/**
* @apilevel low-level
* @declaredat ASTNode:22 * @declaredat ASTNode:22
*/ */
protected int numChildren() { protected int numChildren() {
return 1; return 1;
} }
/** /**
* @apilevel internal * @apilevel internal
* @declaredat ASTNode:28 * @declaredat ASTNode:28
...@@ -95,26 +108,34 @@ public class Get extends ASTNode<ASTNode> implements Cloneable { ...@@ -95,26 +108,34 @@ public class Get extends ASTNode<ASTNode> implements Cloneable {
public boolean mayHaveRewrite() { public boolean mayHaveRewrite() {
return false; return false;
} }
/** @apilevel internal
/**
* @apilevel internal
* @declaredat ASTNode:32 * @declaredat ASTNode:32
*/ */
public void flushAttrCache() { public void flushAttrCache() {
super.flushAttrCache(); super.flushAttrCache();
} }
/** @apilevel internal
/**
* @apilevel internal
* @declaredat ASTNode:36 * @declaredat ASTNode:36
*/ */
public void flushCollectionCache() { public void flushCollectionCache() {
super.flushCollectionCache(); super.flushCollectionCache();
} }
/** @apilevel internal
/**
* @apilevel internal
* @declaredat ASTNode:40 * @declaredat ASTNode:40
*/ */
public Get clone() throws CloneNotSupportedException { public Get clone() throws CloneNotSupportedException {
Get node = (Get) super.clone(); Get node = (Get) super.clone();
return node; return node;
} }
/** @apilevel internal
/**
* @apilevel internal
* @declaredat ASTNode:45 * @declaredat ASTNode:45
*/ */
public Get copy() { public Get copy() {
...@@ -129,21 +150,25 @@ public class Get extends ASTNode<ASTNode> implements Cloneable { ...@@ -129,21 +150,25 @@ public class Get extends ASTNode<ASTNode> implements Cloneable {
throw new Error("Error: clone not supported for " + getClass().getName()); throw new Error("Error: clone not supported for " + getClass().getName());
} }
} }
/** /**
* Create a deep copy of the AST subtree at this node. * Create a deep copy of the AST subtree at this node.
* The copy is dangling, i.e. has no parent. * The copy is dangling, i.e. has no parent.
*
* @return dangling copy of the subtree at this node * @return dangling copy of the subtree at this node
* @apilevel low-level * @apilevel low-level
* @deprecated Please use treeCopy or treeCopyNoTransform instead
* @declaredat ASTNode:64 * @declaredat ASTNode:64
* @deprecated Please use treeCopy or treeCopyNoTransform instead
*/ */
@Deprecated @Deprecated
public Get fullCopy() { public Get fullCopy() {
return treeCopyNoTransform(); return treeCopyNoTransform();
} }
/** /**
* Create a deep copy of the AST subtree at this node. * Create a deep copy of the AST subtree at this node.
* The copy is dangling, i.e. has no parent. * The copy is dangling, i.e. has no parent.
*
* @return dangling copy of the subtree at this node * @return dangling copy of the subtree at this node
* @apilevel low-level * @apilevel low-level
* @declaredat ASTNode:74 * @declaredat ASTNode:74
...@@ -161,10 +186,12 @@ public class Get extends ASTNode<ASTNode> implements Cloneable { ...@@ -161,10 +186,12 @@ public class Get extends ASTNode<ASTNode> implements Cloneable {
} }
return tree; return tree;
} }
/** /**
* Create a deep copy of the AST subtree at this node. * Create a deep copy of the AST subtree at this node.
* The subtree of this node is traversed to trigger rewrites before copy. * The subtree of this node is traversed to trigger rewrites before copy.
* The copy is dangling, i.e. has no parent. * The copy is dangling, i.e. has no parent.
*
* @return dangling copy of the subtree at this node * @return dangling copy of the subtree at this node
* @apilevel low-level * @apilevel low-level
* @declaredat ASTNode:94 * @declaredat ASTNode:94
...@@ -182,22 +209,28 @@ public class Get extends ASTNode<ASTNode> implements Cloneable { ...@@ -182,22 +209,28 @@ public class Get extends ASTNode<ASTNode> implements Cloneable {
} }
return tree; return tree;
} }
/** @apilevel internal
/**
* @apilevel internal
* @declaredat ASTNode:108 * @declaredat ASTNode:108
*/ */
protected boolean is$Equal(ASTNode node) { protected boolean is$Equal(ASTNode node) {
return super.is$Equal(node); return super.is$Equal(node);
} }
/** /**
* Replaces the OperationObject child. * Replaces the OperationObject child.
*
* @param node The new node to replace the OperationObject child. * @param node The new node to replace the OperationObject child.
* @apilevel high-level * @apilevel high-level
*/ */
public void setOperationObject(OperationObject node) { public void setOperationObject(OperationObject node) {
setChild(node, 0); setChild(node, 0);
} }
/** /**
* Retrieves the OperationObject child. * Retrieves the OperationObject child.
*
* @return The current node used as the OperationObject child. * @return The current node used as the OperationObject child.
* @apilevel high-level * @apilevel high-level
*/ */
...@@ -205,17 +238,23 @@ public class Get extends ASTNode<ASTNode> implements Cloneable { ...@@ -205,17 +238,23 @@ public class Get extends ASTNode<ASTNode> implements Cloneable {
public OperationObject getOperationObject() { public OperationObject getOperationObject() {
return (OperationObject) getChild(0); return (OperationObject) getChild(0);
} }
/** /**
* Retrieves the OperationObject child. * Retrieves the OperationObject child.
* <p><em>This method does not invoke AST transformations.</em></p> * <p><em>This method does not invoke AST transformations.</em></p>
*
* @return The current node used as the OperationObject child. * @return The current node used as the OperationObject child.
* @apilevel low-level * @apilevel low-level
*/ */
public OperationObject getOperationObjectNoTransform() { public OperationObject getOperationObjectNoTransform() {
return (OperationObject) getChildNoTransform(0); return (OperationObject) getChildNoTransform(0);
} }
/** @apilevel internal */
/**
* @apilevel internal
*/
protected java.util.Set inferRandomUrl_String_OperationObject_visited; protected java.util.Set inferRandomUrl_String_OperationObject_visited;
/** /**
* @attribute syn * @attribute syn
* @aspect InferParameter * @aspect InferParameter
...@@ -227,7 +266,8 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited; ...@@ -227,7 +266,8 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited;
java.util.List _parameters = new java.util.ArrayList(2); java.util.List _parameters = new java.util.ArrayList(2);
_parameters.add(pathRef); _parameters.add(pathRef);
_parameters.add(operationObject); _parameters.add(operationObject);
if (inferRandomUrl_String_OperationObject_visited == null) inferRandomUrl_String_OperationObject_visited = new java.util.HashSet(4); if (inferRandomUrl_String_OperationObject_visited == null)
inferRandomUrl_String_OperationObject_visited = new java.util.HashSet(4);
if (inferRandomUrl_String_OperationObject_visited.contains(_parameters)) { if (inferRandomUrl_String_OperationObject_visited.contains(_parameters)) {
throw new RuntimeException("Circular definition of attribute Get.inferRandomUrl(String,OperationObject)."); throw new RuntimeException("Circular definition of attribute Get.inferRandomUrl(String,OperationObject).");
} }
...@@ -240,47 +280,27 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited; ...@@ -240,47 +280,27 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited;
SchemaObject s = p.getSchemaOb().schemaObject(); SchemaObject s = p.getSchemaOb().schemaObject();
// check if the parameter is in type 'path'. // check if the parameter is in type 'path'.
if(p.getIn().equals("path")){ if (p.getIn().equals("path"))
for(InferredParameter i:root().collectInferredParameters()){ paths = p.addinfPathParameters(pathRef, paths);
// get the field which must be modified // check if the parameter is in type 'query'
String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1); else if (p.getIn().equals("query"))
// case insensitive comparison of parameter name and name of inferred parameters paths = p.addinfQueryParameters(pathRef, paths);
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef.replace(pathPart,i.value()));
}
} // check if the parameter is in type 'query'
else if(p.getIn().equals("query")){
// check if query parameter is in type 'array'
if(s.getType().equals("array")){
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
pathRef=pathRef+"&"+p.getName()+"="+i.value();
}
paths.add(pathRef.replaceFirst("&","?"));
}else{
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef+"?"+p.getName()+"="+i.value());
}
}
}
System.out.println(paths.size() + " Paths are inferred."); System.out.println(paths.size() + " Paths are inferred.");
} }
for (String path : paths) for (String path : paths)
connectGET(path); connectGET(path);
return pathRef; return pathRef;
} } finally {
finally {
inferRandomUrl_String_OperationObject_visited.remove(_parameters); inferRandomUrl_String_OperationObject_visited.remove(_parameters);
} }
} }
/** @apilevel internal */
/**
* @apilevel internal
*/
protected java.util.Set generateRandomUrl_String_visited; protected java.util.Set generateRandomUrl_String_visited;
/** /**
* @attribute syn * @attribute syn
* @aspect RandomRequestGenerator * @aspect RandomRequestGenerator
...@@ -340,16 +360,21 @@ protected java.util.Set generateRandomUrl_String_visited; ...@@ -340,16 +360,21 @@ protected java.util.Set generateRandomUrl_String_visited;
System.out.println(e.toString()); System.out.println(e.toString());
return false; return false;
} }
} } finally {
finally {
generateRandomUrl_String_visited.remove(_parameters); generateRandomUrl_String_visited.remove(_parameters);
} }
} }
/** @apilevel internal */
/**
* @apilevel internal
*/
public ASTNode rewriteTo() { public ASTNode rewriteTo() {
return super.rewriteTo(); return super.rewriteTo();
} }
/** @apilevel internal */
/**
* @apilevel internal
*/
public boolean canRewrite() { public boolean canRewrite() {
return false; return false;
} }
......
...@@ -85,7 +85,7 @@ public class OperationObject extends ASTNode<ASTNode> implements Cloneable { ...@@ -85,7 +85,7 @@ public class OperationObject extends ASTNode<ASTNode> implements Cloneable {
} }
/** /**
* @aspect InferParameter * @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:126 * @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:114
*/ */
public void writeDictionary(SchemaOb schema,String resp)throws Exception{ public void writeDictionary(SchemaOb schema,String resp)throws Exception{
ObjectMapper mapper=new ObjectMapper(); ObjectMapper mapper=new ObjectMapper();
...@@ -111,7 +111,7 @@ public class OperationObject extends ASTNode<ASTNode> implements Cloneable { ...@@ -111,7 +111,7 @@ public class OperationObject extends ASTNode<ASTNode> implements Cloneable {
} }
/** /**
* @aspect InferParameter * @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:149 * @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:137
*/ */
public void writeDictionaryWithArray(SchemaOb schema,String resp)throws Exception{ public void writeDictionaryWithArray(SchemaOb schema,String resp)throws Exception{
ObjectMapper mapper=new ObjectMapper(); ObjectMapper mapper=new ObjectMapper();
......
...@@ -828,6 +828,82 @@ protected java.util.Set composeParameter_ParameterOb_Map_Object__ASTNode__visite ...@@ -828,6 +828,82 @@ protected java.util.Set composeParameter_ParameterOb_Map_Object__ASTNode__visite
} }
} }
/** @apilevel internal */ /** @apilevel internal */
protected java.util.Set addinfPathParameters_String_List_String__visited;
/**
* @attribute syn
* @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:80
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="InferParameter", declaredAt="E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:80")
public List<String> addinfPathParameters(String pathRef, List<String> paths) {
java.util.List _parameters = new java.util.ArrayList(2);
_parameters.add(pathRef);
_parameters.add(paths);
if (addinfPathParameters_String_List_String__visited == null) addinfPathParameters_String_List_String__visited = new java.util.HashSet(4);
if (addinfPathParameters_String_List_String__visited.contains(_parameters)) {
throw new RuntimeException("Circular definition of attribute ParameterObject.addinfPathParameters(String,List_String_).");
}
addinfPathParameters_String_List_String__visited.add(_parameters);
try {
for(InferredParameter i:root().collectInferredParameters()){
// get the field which must be modified
String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1);
// case insensitive comparison of parameter name and name of inferred parameters
if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef.replace(pathPart,i.value()));
}
return paths;
}
finally {
addinfPathParameters_String_List_String__visited.remove(_parameters);
}
}
/** @apilevel internal */
protected java.util.Set addinfQueryParameters_String_List_String__visited;
/**
* @attribute syn
* @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:92
*/
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="InferParameter", declaredAt="E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:92")
public List<String> addinfQueryParameters(String pathRef, List<String> paths) {
java.util.List _parameters = new java.util.ArrayList(2);
_parameters.add(pathRef);
_parameters.add(paths);
if (addinfQueryParameters_String_List_String__visited == null) addinfQueryParameters_String_List_String__visited = new java.util.HashSet(4);
if (addinfQueryParameters_String_List_String__visited.contains(_parameters)) {
throw new RuntimeException("Circular definition of attribute ParameterObject.addinfQueryParameters(String,List_String_).");
}
addinfQueryParameters_String_List_String__visited.add(_parameters);
try {
SchemaObject s=getSchemaOb().schemaObject();
// check if query parameter is in type 'array'
if(s.getType().equals("array")){
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
pathRef=pathRef+"&"+getName()+"="+i.value();
}
paths.add(pathRef.replaceFirst("&","?"));
}else{
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef+"?"+getName()+"="+i.value());
}
}
return paths;
}
finally {
addinfQueryParameters_String_List_String__visited.remove(_parameters);
}
}
/** @apilevel internal */
protected java.util.Set randomPathParameter_String_visited; protected java.util.Set randomPathParameter_String_visited;
/** /**
* @attribute syn * @attribute syn
......
...@@ -29,7 +29,7 @@ import java.util.stream.IntStream; ...@@ -29,7 +29,7 @@ import java.util.stream.IntStream;
public class Post extends ASTNode<ASTNode> implements Cloneable { public class Post extends ASTNode<ASTNode> implements Cloneable {
/** /**
* @aspect InferParameter * @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:184 * @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:172
*/ */
public void connectPOST(String path){ public void connectPOST(String path){
try{URL url=new URL(path); try{URL url=new URL(path);
...@@ -219,10 +219,10 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited; ...@@ -219,10 +219,10 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited;
/** /**
* @attribute syn * @attribute syn
* @aspect InferParameter * @aspect InferParameter
* @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:82 * @declaredat E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:59
*/ */
@ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN)
@ASTNodeAnnotation.Source(aspect="InferParameter", declaredAt="E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:82") @ASTNodeAnnotation.Source(aspect="InferParameter", declaredAt="E:\\bachelor-thesis\\SigTest\\bachelor-thesis-jastadd\\src\\main\\jastadd\\InferParameter.jrag:59")
public String inferRandomUrl(String pathRef, OperationObject operationObject) { public String inferRandomUrl(String pathRef, OperationObject operationObject) {
java.util.List _parameters = new java.util.ArrayList(2); java.util.List _parameters = new java.util.ArrayList(2);
_parameters.add(pathRef); _parameters.add(pathRef);
...@@ -240,35 +240,12 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited; ...@@ -240,35 +240,12 @@ protected java.util.Set inferRandomUrl_String_OperationObject_visited;
SchemaObject s=p.getSchemaOb().schemaObject(); SchemaObject s=p.getSchemaOb().schemaObject();
// check if the parameter is in type 'path'. // check if the parameter is in type 'path'.
if(p.getIn().equals("path")){ if(p.getIn().equals("path"))
for(InferredParameter i:root().collectInferredParameters()){ paths=p.addinfPathParameters(pathRef,paths);
// get the field which must be modified // check if the parameter is in type 'query'
String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1); else if(p.getIn().equals("query"))
// case insensitive comparison of parameter name and name of inferred parameters paths=p.addinfQueryParameters(pathRef,paths);
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef.replace(pathPart,i.value()));
}
} // check if the parameter is in type 'query'
else if(p.getIn().equals("query")){
// check if query parameter is in type 'array'
if(s.getType().equals("array")){
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
pathRef=pathRef+"&"+p.getName()+"="+i.value();
}
paths.add(pathRef.replaceFirst("&","?"));
}else{
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef+"?"+p.getName()+"="+i.value());
}
}
}
System.out.println(paths.size()+" Paths are inferred."); System.out.println(paths.size()+" Paths are inferred.");
} }
for(String path:paths) for(String path:paths)
......
...@@ -10,6 +10,7 @@ aspect InferParameter{ ...@@ -10,6 +10,7 @@ aspect InferParameter{
coll Set<InferredParameter> OpenAPIObject.collectInferredParameters()[new HashSet<InferredParameter>()]; coll Set<InferredParameter> OpenAPIObject.collectInferredParameters()[new HashSet<InferredParameter>()];
InferredParameter contributes this InferredParameter contributes this
to OpenAPIObject.collectInferredParameters(); to OpenAPIObject.collectInferredParameters();
syn String InferredParameter.name()=getParameter().substring(0,getParameter().indexOf("?")); syn String InferredParameter.name()=getParameter().substring(0,getParameter().indexOf("?"));
syn String InferredParameter.value()=getParameter().substring(getParameter().indexOf("?")+1); syn String InferredParameter.value()=getParameter().substring(getParameter().indexOf("?")+1);
...@@ -19,20 +20,20 @@ public void OpenAPIObject.generateRequestsWithInferredParameters()throws Excepti ...@@ -19,20 +20,20 @@ public void OpenAPIObject.generateRequestsWithInferredParameters()throws Excepti
generateRequests(); generateRequests();
for(PathsObject p:getPathsObjects()) for(PathsObject p:getPathsObjects())
p.inferUrl(urls); p.inferUrl();
} }
inh Set<String> PathsObject.inferUrl(Set<String> urls); inh boolean PathsObject.inferUrl();
eq OpenAPIObject.getPathsObject(int i).inferUrl(Set<String> urls){ eq OpenAPIObject.getPathsObject(int i).inferUrl(){
PathItemObject p=getPathsObject(i).getPathItemObject(); PathItemObject p=getPathsObject(i).getPathItemObject();
String path=getServerObject(0).getUrl(); String path=getServerObject(0).getUrl();
if(p.hasGet()) if(p.hasGet())
urls.add(p.getGet().inferRandomUrl(path+getPathsObject(i).getRef(),p.getGet().getOperationObject())); p.getGet().inferRandomUrl(path+getPathsObject(i).getRef(),p.getGet().getOperationObject());
else if(p.hasPost()) else if(p.hasPost())
urls.add(p.getPost().inferRandomUrl(path+getPathsObject(i).getRef(),p.getPost().getOperationObject())); p.getPost().inferRandomUrl(path+getPathsObject(i).getRef(),p.getPost().getOperationObject());
return urls; return true;
} }
syn String Get.inferRandomUrl(String pathRef,OperationObject operationObject){ syn String Get.inferRandomUrl(String pathRef,OperationObject operationObject){
...@@ -43,35 +44,12 @@ public void OpenAPIObject.generateRequestsWithInferredParameters()throws Excepti ...@@ -43,35 +44,12 @@ public void OpenAPIObject.generateRequestsWithInferredParameters()throws Excepti
SchemaObject s=p.getSchemaOb().schemaObject(); SchemaObject s=p.getSchemaOb().schemaObject();
// check if the parameter is in type 'path'. // check if the parameter is in type 'path'.
if(p.getIn().equals("path")){ if(p.getIn().equals("path"))
for(InferredParameter i:root().collectInferredParameters()){ paths=p.addinfPathParameters(pathRef,paths);
// get the field which must be modified // check if the parameter is in type 'query'
String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1); else if(p.getIn().equals("query"))
// case insensitive comparison of parameter name and name of inferred parameters paths=p.addinfQueryParameters(pathRef,paths);
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef.replace(pathPart,i.value()));
}
} // check if the parameter is in type 'query'
else if(p.getIn().equals("query")){
// check if query parameter is in type 'array'
if(s.getType().equals("array")){
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
pathRef=pathRef+"&"+p.getName()+"="+i.value();
}
paths.add(pathRef.replaceFirst("&","?"));
}else{
for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url
paths.add(pathRef+"?"+p.getName()+"="+i.value());
}
}
}
System.out.println(paths.size()+" Paths are inferred."); System.out.println(paths.size()+" Paths are inferred.");
} }
for(String path:paths) for(String path:paths)
...@@ -87,40 +65,51 @@ public void OpenAPIObject.generateRequestsWithInferredParameters()throws Excepti ...@@ -87,40 +65,51 @@ public void OpenAPIObject.generateRequestsWithInferredParameters()throws Excepti
SchemaObject s=p.getSchemaOb().schemaObject(); SchemaObject s=p.getSchemaOb().schemaObject();
// check if the parameter is in type 'path'. // check if the parameter is in type 'path'.
if(p.getIn().equals("path")){ if(p.getIn().equals("path"))
paths=p.addinfPathParameters(pathRef,paths);
// check if the parameter is in type 'query'
else if(p.getIn().equals("query"))
paths=p.addinfQueryParameters(pathRef,paths);
System.out.println(paths.size()+" Paths are inferred.");
}
for(String path:paths)
connectPOST(path);
return pathRef;
}
syn List<String> ParameterObject.addinfPathParameters(String pathRef,List<String> paths){
for(InferredParameter i:root().collectInferredParameters()){ for(InferredParameter i:root().collectInferredParameters()){
// get the field which must be modified // get the field which must be modified
String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1); String pathPart=pathRef.substring(pathRef.indexOf("{"),pathRef.indexOf("}")+1);
// case insensitive comparison of parameter name and name of inferred parameters // case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name())) if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url // add inferred parameter in url
paths.add(pathRef.replace(pathPart,i.value())); paths.add(pathRef.replace(pathPart,i.value()));
} }
} // check if the parameter is in type 'query' return paths;
else if(p.getIn().equals("query")){ }
syn List<String> ParameterObject.addinfQueryParameters(String pathRef,List<String> paths){
SchemaObject s=getSchemaOb().schemaObject();
// check if query parameter is in type 'array' // check if query parameter is in type 'array'
if(s.getType().equals("array")){ if(s.getType().equals("array")){
for(InferredParameter i:root().collectInferredParameters()){ for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters // case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name())) if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url // add inferred parameter in url
pathRef=pathRef+"&"+p.getName()+"="+i.value(); pathRef=pathRef+"&"+getName()+"="+i.value();
} }
paths.add(pathRef.replaceFirst("&","?")); paths.add(pathRef.replaceFirst("&","?"));
}else{ }else{
for(InferredParameter i:root().collectInferredParameters()){ for(InferredParameter i:root().collectInferredParameters()){
// case insensitive comparison of parameter name and name of inferred parameters // case insensitive comparison of parameter name and name of inferred parameters
if(p.getName().equalsIgnoreCase(i.name())) if(getName().equalsIgnoreCase(i.name()))
// add inferred parameter in url // add inferred parameter in url
paths.add(pathRef+"?"+p.getName()+"="+i.value()); paths.add(pathRef+"?"+getName()+"="+i.value());
} }
} }
} return paths;
System.out.println(paths.size()+" Paths are inferred.");
}
for(String path:paths)
connectPOST(path);
return pathRef;
} }
public void OperationObject.writeDictionary(SchemaOb schema,String resp)throws Exception{ public void OperationObject.writeDictionary(SchemaOb schema,String resp)throws Exception{
......
...@@ -50,9 +50,12 @@ aspect RandomRequestGenerator{ ...@@ -50,9 +50,12 @@ aspect RandomRequestGenerator{
return pathRef; return pathRef;
} }
public void OpenAPIObject.generateRequests()throws Exception{ syn boolean OpenAPIObject.generateRequests(){
try{
for(PathsObject p:getPathsObjects()) for(PathsObject p:getPathsObjects())
p.generateUrl(); p.generateUrl();} catch (Exception e) {
return false;
}
} }
inh boolean PathsObject.generateUrl(); inh boolean PathsObject.generateUrl();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment