Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
RAGO - RAG OpenAPI Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
RAGO - RAG OpenAPI Framework
Commits
a64b569e
Commit
a64b569e
authored
3 years ago
by
Jueun Park
Browse files
Options
Downloads
Patches
Plain Diff
Added javadoc in JastAdd-Grammar partially
parent
0ea31623
Branches
Branches containing commit
No related tags found
1 merge request
!6
Resolve "check and fix random request generator"
Pipeline
#13302
passed
3 years ago
Stage: build
Stage: test
Stage: ragdoc
Stage: publish
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/jastadd/InferParameter.jrag
+13
-0
13 additions, 0 deletions
src/main/jastadd/InferParameter.jrag
src/main/jastadd/RandomRequestGenerator.jrag
+59
-40
59 additions, 40 deletions
src/main/jastadd/RandomRequestGenerator.jrag
with
72 additions
and
40 deletions
src/main/jastadd/InferParameter.jrag
+
13
−
0
View file @
a64b569e
...
...
@@ -4,7 +4,20 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
aspect InferParameter{
/**
* Saves response data names generated by random requests.
* <p>This is an auxiliary method to distinguish saved dictionary values.</p>
* <p>(Future work: translate this to Map or Tuple).</p>
* @return first String part divided by <code>?</code>.
*/
syn String ParameterObject.dictName(String dict) = dict.substring(0, dict.indexOf("?"));
/**
* Saves response data values generated by random requests.
* <p>This is an auxiliary method to distinguish saved dictionary values.</p>
* <p>(Future work: translate this to Map or Tuple).</p>
* @return second String part divided by <code>?</code>.
*/
syn String ParameterObject.dictValue(String dict) = dict.substring(dict.indexOf("?")+1);
inh List<String> PathsObject.inferUrl(List<String> dict);
...
...
This diff is collapsed.
Click to expand it.
src/main/jastadd/RandomRequestGenerator.jrag
+
59
−
40
View file @
a64b569e
aspect RandomRequestGenerator{
syn String ParameterObject.randomPathParameter(String pathRef){
SchemaObject s = getSchema().schemaObject();
String pathPart = pathRef.substring(pathRef.indexOf("{"), pathRef.indexOf("}") + 1);
if (s.getType().equals("string"))
pathRef = pathRef.replace(pathPart, generateRandomString(s.getEList()));
else if (s.getType().equals("integer"))
pathRef = pathRef.replace(pathPart, generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10 // s.getMaximum() != null ? s.getMaximum().intValue() : -1
));
return pathRef;
}
syn String ParameterObject.randomQueryParameter(String pathRef){
SchemaObject s = getSchema().schemaObject();
if (s.getType().equals("string"))
pathRef = pathRef + "?" + getName() + "=" + generateRandomString(s.getEList());
else if (s.getType().equals("integer"))
pathRef = pathRef + "?" + getName() + "=" + generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10); // s.getMaximum() != null ? s.getMaximum().intValue() : -1
else if (s.getType().equals("array")) {
if (s.getI().getSchema().schemaObject().getType().equals("string")) {
for (EnumObj e : s.getI().getSchema().schemaObject().getEList())
pathRef = pathWithEnum(e, pathRef);
} else if (s.getI().getSchema().schemaObject().getType().equals("integer")) {
for (int i = 0; i < 5; i++)
pathRef = pathRef + "&" + getName() + "=" + generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10); // s.getMaximum() != null ? s.getMaximum().intValue() : -1
}
pathRef = pathRef.replaceFirst("&", "?");
}
return pathRef;
}
syn List<String> OpenAPIObject.generateRequests(){
/**
* Calls <code>generateUrl()</code> for all paths.
* @return The list of String representing the generated URLs.
*/ syn List<String> OpenAPIObject.generateRequests(){
List<String> urls = new ArrayList<>();
try {
for (PathsObject p : getPList())
...
...
@@ -50,6 +15,11 @@ aspect RandomRequestGenerator{
return urls;
}
/**
* Checks if a path has the request types <code>GET</code> and/or <code>POST</code>, and calls <code>generateRandomUrl(String pathRef)</code>.
* <p>Afterwards, generated URLs are saved in a list.</p>
* @return The list of String representing the generated URLs.
*/
inh List<String> PathsObject.generateUrl();
eq OpenAPIObject.getP(int i).generateUrl(){
List<String> urls = new ArrayList<>();
...
...
@@ -59,7 +29,7 @@ aspect RandomRequestGenerator{
if (p.hasG())
urls.add(p.getG().generateRandomUrl(path + getP(i).getRef()));
else
if (p.hasPostOb())
if (p.hasPostOb())
urls.add(p.getPostOb().generateRandomUrl(path + getP(i).getRef()));
return urls;
...
...
@@ -69,6 +39,11 @@ aspect RandomRequestGenerator{
}
}
/**
* Checks which parameter types the targeted GET request has (Path or Query) and calls corresponding random parameter generator.
* <p>Afterwards, generated parameters are written in the url.</p>
* @return An URL with the generated parameters in String.
*/
syn String Get.generateRandomUrl(String pathRef){
try {
for (ParameterOb o : getO().getPList()) {
...
...
@@ -85,6 +60,12 @@ aspect RandomRequestGenerator{
return null;
}
}
/**
* Checks which parameter types the targeted POST request has (Path or Query) and calls corresponding random parameter generator.
* <p>Afterwards, generated parameters are written in the url.</p>
* @return An URL with the generated parameters in String.
*/
syn String Post.generateRandomUrl(String pathRef){
try {
for (ParameterOb o : getO().getPList()) {
...
...
@@ -102,6 +83,44 @@ aspect RandomRequestGenerator{
}
}
syn String ParameterObject.randomPathParameter(String pathRef){
SchemaObject s = getSchema().schemaObject();
String pathPart = pathRef.substring(pathRef.indexOf("{"), pathRef.indexOf("}") + 1);
if (s.getType().equals("string"))
pathRef = pathRef.replace(pathPart, generateRandomString(s.getEList()));
else if (s.getType().equals("integer"))
pathRef = pathRef.replace(pathPart, generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10 // s.getMaximum() != null ? s.getMaximum().intValue() : -1
));
return pathRef;
}
syn String ParameterObject.randomQueryParameter(String pathRef){
SchemaObject s = getSchema().schemaObject();
if (s.getType().equals("string"))
pathRef = pathRef + "?" + getName() + "=" + generateRandomString(s.getEList());
else if (s.getType().equals("integer"))
pathRef = pathRef + "?" + getName() + "=" + generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10); // s.getMaximum() != null ? s.getMaximum().intValue() : -1
else if (s.getType().equals("array")) {
if (s.getI().getSchema().schemaObject().getType().equals("string")) {
for (EnumObj e : s.getI().getSchema().schemaObject().getEList())
pathRef = pathWithEnum(e, pathRef);
} else if (s.getI().getSchema().schemaObject().getType().equals("integer")) {
for (int i = 0; i < 5; i++)
pathRef = pathRef + "&" + getName() + "=" + generateRandomInt(
-1, // s.getMinimum() != null ? s.getMinimum().intValue() : -1,
10); // s.getMaximum() != null ? s.getMaximum().intValue() : -1
}
pathRef = pathRef.replaceFirst("&", "?");
}
return pathRef;
}
public String ParameterObject.generateRandomString(JastAddList<EnumObj> objs){
Random rand = new Random();
if (objs.getNumChild() != 0)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment