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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
RAGO - RAG OpenAPI Framework
Commits
c5afb7dd
Commit
c5afb7dd
authored
3 years ago
by
Jueun Park
Browse files
Options
Downloads
Patches
Plain Diff
wrote first test
parent
049296ec
Branches
Branches containing commit
No related tags found
1 merge request
!1
Tests/openapi generator
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/jastadd/ReverseParser.jrag
+59
-59
59 additions, 59 deletions
src/main/jastadd/ReverseParser.jrag
src/test/java/openapi/OpenAPIMain_test.java
+5
-1
5 additions, 1 deletion
src/test/java/openapi/OpenAPIMain_test.java
with
64 additions
and
60 deletions
src/main/jastadd/ReverseParser.jrag
+
59
−
59
View file @
c5afb7dd
...
...
@@ -5,7 +5,7 @@ aspect ReverseParser{
public static OpenAPI OpenAPIObject.reverseOpenAPI(OpenAPIObject openapi){
OpenAPI api = new OpenAPI();
if (
!
openapi.getOpenAPI()
.isEmpty()
)
if (openapi.getOpenAPI()
!= null
)
api.setOpenapi(openapi.getOpenAPI());
if (openapi.getI() != null)
api.setInfo(InfoObject.reverseInfo(openapi.getI()));
...
...
@@ -56,13 +56,13 @@ aspect ReverseParser{
public static io.swagger.v3.oas.models.info.Info InfoObject.reverseInfo(InfoObject infoObject){
io.swagger.v3.oas.models.info.Info info = new io.swagger.v3.oas.models.info.Info();
if (
!
infoObject.getTitle()
.isEmpty()
)
if (infoObject.getTitle()
!= null
)
info.setTitle(infoObject.getTitle());
if (
!
infoObject.getVersion()
.isEmpty()
)
if (infoObject.getVersion()
!= null
)
info.setVersion(infoObject.getVersion());
if (
!
infoObject.getDescription()
.isEmpty()
)
if (infoObject.getDescription()
!= null
)
info.setDescription(infoObject.getDescription());
if (
!
infoObject.getTermsOfService()
.isEmpty()
)
if (infoObject.getTermsOfService()
!= null
)
info.setTermsOfService(infoObject.getTermsOfService());
if (infoObject.hasC())
info.setContact(ContactObject.reverseContact(infoObject.getC()));
...
...
@@ -81,11 +81,11 @@ aspect ReverseParser{
public static io.swagger.v3.oas.models.info.Contact ContactObject.reverseContact(ContactObject contactObject){
io.swagger.v3.oas.models.info.Contact contact = new io.swagger.v3.oas.models.info.Contact();
if (
!
contactObject.getName()
.isEmpty()
)
if (contactObject.getName()
!= null
)
contact.setName(contactObject.getName());
if (
!
contactObject.getUrl()
.isEmpty()
)
if (contactObject.getUrl()
!= null
)
contact.setUrl(contactObject.getUrl());
if (
!
contactObject.getEmail()
.isEmpty()
)
if (contactObject.getEmail()
!= null
)
contact.setEmail(contactObject.getEmail());
if (contactObject.getNumEx() != 0) {
Map<String, Object> extensions = new HashMap<>();
...
...
@@ -100,9 +100,9 @@ aspect ReverseParser{
public static io.swagger.v3.oas.models.info.License LicenseObject.reverseLicense(LicenseObject licenseObject){
io.swagger.v3.oas.models.info.License license = new io.swagger.v3.oas.models.info.License();
if (
!
licenseObject.getName()
.isEmpty()
)
if (licenseObject.getName()
!= null
)
license.setName(licenseObject.getName());
if (
!
licenseObject.getUrl()
.isEmpty()
)
if (licenseObject.getUrl()
!= null
)
license.setUrl(licenseObject.getUrl());
if (licenseObject.getNumEx() != 0) {
Map<String, Object> extensions = new HashMap<>();
...
...
@@ -117,9 +117,9 @@ aspect ReverseParser{
public static Server ServerObject.reverseServer(ServerObject serverObject){
Server server = new Server();
if (
!
serverObject.getUrl()
.isEmpty()
)
if (serverObject.getUrl()
!= null
)
server.setUrl(serverObject.getUrl());
if (
!
serverObject.getDescription()
.isEmpty()
)
if (serverObject.getDescription()
!= null
)
server.setDescription(serverObject.getDescription());
if (serverObject.getNumSt() != 0) {
ServerVariables serverVariables = new ServerVariables();
...
...
@@ -140,9 +140,9 @@ aspect ReverseParser{
public static ServerVariable ServerVariableObject.reverseServerVariable(ServerVariableObject serverVariableObject){
ServerVariable serverVariable = new ServerVariable();
if (
!
serverVariableObject.getDefault()
.isEmpty()
)
if (serverVariableObject.getDefault()
!= null
)
serverVariable.setDefault(serverVariableObject.getDefault());
if (
!
serverVariableObject.getDescription()
.isEmpty()
)
if (serverVariableObject.getDescription()
!= null
)
serverVariable.setDescription(serverVariableObject.getDescription());
if (serverVariableObject.getNumE() != 0) {
List<String> enums = new ArrayList<>();
...
...
@@ -270,9 +270,9 @@ aspect ReverseParser{
PathItem path = new PathItem();
PathItemObject p = (PathItemObject) pathItemOb;
if (
!
p.getSummary()
.isEmpty()
)
if (p.getSummary()
!= null
)
path.setSummary(p.getSummary());
if (
!
p.getDescription()
.isEmpty()
)
if (p.getDescription()
!= null
)
path.setDescription(p.getDescription());
if (p.hasG())
path.setGet(OperationObject.reverseOperation(p.getG().getO()));
...
...
@@ -313,13 +313,13 @@ aspect ReverseParser{
for (de.tudresden.inf.st.openapi.ast.Tag t : operationObject.getTList())
operation.addTagsItem(t.getTag());
}
if (
!
operationObject.getSummary()
.isEmpty()
)
if (operationObject.getSummary()
!= null
)
operation.setSummary(operationObject.getSummary());
if (
!
operationObject.getDescription()
.isEmpty()
)
if (operationObject.getDescription()
!= null
)
operation.setDescription(operationObject.getDescription());
if (operationObject.hasEd())
operation.setExternalDocs(ExternalDocObject.reverseExternalDocs(operationObject.getEd()));
if (
!
operationObject.getOperationID()
.isEmpty()
)
if (operationObject.getOperationID()
!= null
)
operation.setOperationId(operationObject.getOperationID());
if (operationObject.getNumP() != 0) {
for (ParameterOb p : operationObject.getPList())
...
...
@@ -362,9 +362,9 @@ aspect ReverseParser{
public static io.swagger.v3.oas.models.ExternalDocumentation ExternalDocObject.reverseExternalDocs(ExternalDocObject externalDocObject){
ExternalDocumentation externalDocs = new ExternalDocumentation();
if (
!
externalDocObject.getDescription()
.isEmpty()
)
if (externalDocObject.getDescription()
!= null
)
externalDocs.setDescription(externalDocObject.getDescription());
if (
!
externalDocObject.getUrl()
.isEmpty()
)
if (externalDocObject.getUrl()
!= null
)
externalDocs.setUrl(externalDocObject.getUrl());
if (externalDocObject.getNumEx() != 0) {
Map<String, Object> extensionMap = new HashMap<>();
...
...
@@ -381,7 +381,7 @@ aspect ReverseParser{
io.swagger.v3.oas.models.parameters.Parameter parameter = new io.swagger.v3.oas.models.parameters.Parameter();
ParameterReference p = (ParameterReference) parameterOb;
if (
!
p.getRef()
.isEmpty()
) {
if (p.getRef()
!= null
) {
parameter.set$ref(p.getRef());
}
...
...
@@ -391,13 +391,13 @@ aspect ReverseParser{
io.swagger.v3.oas.models.parameters.Parameter parameter = new io.swagger.v3.oas.models.parameters.Parameter();
ParameterObject p = (ParameterObject) parameterOb;
if (
!
p.getName()
.isEmpty()
)
if (p.getName()
!= null
)
parameter.setName(p.getName());
if (
!
p.getIn()
.isEmpty()
)
if (p.getIn()
!= null
)
parameter.setIn(p.getIn());
if (p.getRequired() != null)
parameter.setRequired(p.getRequired());
if (
!
p.getDescription()
.isEmpty()
)
if (p.getDescription()
!= null
)
parameter.setDescription(p.getDescription());
if (p.getDeprecatedBoolean() != null)
parameter.setDeprecated(p.getDeprecatedBoolean());
...
...
@@ -461,7 +461,7 @@ aspect ReverseParser{
RequestBody requestBody = new RequestBody();
RequestBodyReference r = (RequestBodyReference) requestBodyOb;
if (
!
r.getRef()
.isEmpty()
) {
if (r.getRef()
!= null
) {
requestBody.set$ref(r.getRef());
}
...
...
@@ -477,7 +477,7 @@ aspect ReverseParser{
contents.put(t.getKey(), MediaTypeObject.reverseMediaType(t.getM()));
requestBody.setContent(contents);
}
if (
!
r.getDescription()
.isEmpty()
)
if (r.getDescription()
!= null
)
requestBody.setDescription(r.getDescription());
if (r.getRequired() != null)
requestBody.setRequired(r.getRequired());
...
...
@@ -515,7 +515,7 @@ aspect ReverseParser{
io.swagger.v3.oas.models.media.Encoding encodingProperty = new io.swagger.v3.oas.models.media.Encoding();
HeaderOb h;
if (
!
encodingObject.getContentType()
.isEmpty()
)
if (encodingObject.getContentType()
!= null
)
encodingProperty.setContentType(encodingObject.getContentType());
if (encodingObject.getNumH() != 0) {
Map<String, Header> headers = new HashMap<>();
...
...
@@ -544,7 +544,7 @@ aspect ReverseParser{
ApiResponse response = new ApiResponse();
ResponseReference r = (ResponseReference) responseOb;
if (
!
r.getRef()
.isEmpty()
) {
if (r.getRef()
!= null
) {
response.set$ref(r.getRef());
}
...
...
@@ -554,7 +554,7 @@ aspect ReverseParser{
ApiResponse response = new ApiResponse();
ResponseObject r = (ResponseObject) responseOb;
if (
!
r.getDescription()
.isEmpty()
)
if (r.getDescription()
!= null
)
response.setDescription(r.getDescription());
if (r.getNumH() != 0) {
Map<String, Header> headers = new HashMap<>();
...
...
@@ -583,7 +583,7 @@ aspect ReverseParser{
io.swagger.v3.oas.models.callbacks.Callback callback = new io.swagger.v3.oas.models.callbacks.Callback();
CallbackReference c = (CallbackReference) callbackOb;
if (
!
c.getRef()
.isEmpty()
) {
if (c.getRef()
!= null
) {
callback.set$ref(c.getRef());
}
...
...
@@ -606,13 +606,13 @@ aspect ReverseParser{
public static Example ExampleObject.reverseExample(ExampleObject exampleObject){
Example example = new Example();
if (
!
exampleObject.getSummary()
.isEmpty()
)
if (exampleObject.getSummary()
!= null
)
example.setSummary(exampleObject.getSummary());
if (
!
exampleObject.getDescription()
.isEmpty()
)
if (exampleObject.getDescription()
!= null
)
example.setDescription(exampleObject.getDescription());
if (exampleObject.getValue() != null)
example.setValue(exampleObject.getValue());
if (
!
exampleObject.getExternalValue()
.isEmpty()
)
if (exampleObject.getExternalValue()
!= null
)
example.setExternalValue(exampleObject.getExternalValue());
if (exampleObject.getNumEx() != 0) {
Map<String, Object> extension = new HashMap<>();
...
...
@@ -629,7 +629,7 @@ aspect ReverseParser{
io.swagger.v3.oas.models.links.Link link = new io.swagger.v3.oas.models.links.Link();
LinkReference l = (LinkReference) linkOb;
if (
!
l.getRef()
.isEmpty()
)
if (l.getRef()
!= null
)
link.set$ref(l.getRef());
return link;
...
...
@@ -638,9 +638,9 @@ aspect ReverseParser{
io.swagger.v3.oas.models.links.Link link = new io.swagger.v3.oas.models.links.Link();
LinkObject l = (LinkObject) linkOb;
if (
!
l.getOperationRef()
.isEmpty()
)
if (l.getOperationRef()
!= null
)
link.setOperationRef(l.getOperationRef());
if (
!
l.getOperationID()
.isEmpty()
)
if (l.getOperationID()
!= null
)
link.setOperationId(l.getOperationID());
if (l.getNumL() != 0) {
Map<String, String> parameters = new HashMap<>();
...
...
@@ -648,7 +648,7 @@ aspect ReverseParser{
parameters.put(t.getKey(), t.getValue());
link.setParameters(parameters);
}
if (
!
l.getDescription()
.isEmpty()
)
if (l.getDescription()
!= null
)
link.setDescription(l.getDescription());
if (l.hasS())
link.setServer(ServerObject.reverseServer(l.getS()));
...
...
@@ -665,7 +665,7 @@ aspect ReverseParser{
io.swagger.v3.oas.models.headers.Header header = new io.swagger.v3.oas.models.headers.Header();
HeaderReference h = (HeaderReference) headerOb;
if (
!
h.getRef()
.isEmpty()
) {
if (h.getRef()
!= null
) {
header.set$ref(h.getRef());
}
...
...
@@ -677,7 +677,7 @@ aspect ReverseParser{
if (h.getRequired() != null)
header.setRequired(h.getRequired());
if (
!
h.getDescription()
.isEmpty()
)
if (h.getDescription()
!= null
)
header.setDescription(h.getDescription());
switch (h.getStyle()) {
case "simple":
...
...
@@ -713,7 +713,7 @@ aspect ReverseParser{
tag.setName(tagObject.getName());
if (
!
tagObject.getDescription()
.isEmpty()
)
if (tagObject.getDescription()
!= null
)
tag.setDescription(tagObject.getDescription());
if (tagObject.hasE())
tag.setExternalDocs(ExternalDocObject.reverseExternalDocs(tagObject.getE()));
...
...
@@ -733,7 +733,7 @@ aspect ReverseParser{
io.swagger.v3.oas.models.media.Schema schema = new io.swagger.v3.oas.models.media.Schema();
SchemaReference s = (SchemaReference) schemaOb;
if (
!
s.getRef()
.isEmpty()
) {
if (s.getRef()
!= null
) {
schema.set$ref(s.getRef());
}
...
...
@@ -767,7 +767,7 @@ aspect ReverseParser{
schema.setAdditionalProperties(s.getAdditionalProperties());
if (s.getDefaultValue() != null)
schema.setDefault(s.getDefaultValue());
if (
!
s.getDescription()
.isEmpty()
)
if (s.getDescription()
!= null
)
schema.setDescription(s.getDescription());
if (s.getDeprecatedBoolean() != null)
schema.setDeprecated(s.getDeprecatedBoolean());
...
...
@@ -786,7 +786,7 @@ aspect ReverseParser{
schema.setExclusiveMinimum(s.getExclusiveMinimum());
if (s.hasExt())
schema.setExternalDocs(ExternalDocObject.reverseExternalDocs(s.getExt()));
if (
!
s.getFormat()
.isEmpty()
)
if (s.getFormat()
!= null
)
schema.setFormat(s.getFormat());
if (s.getMaximum() != null)
schema.setMaximum(s.getMaximum());
...
...
@@ -811,7 +811,7 @@ aspect ReverseParser{
// Nullable will be excluded in version 3.1.0
if (s.getNullable() != null)
schema.setNullable(s.getNullable());
if (
!
s.getPattern()
.isEmpty()
)
if (s.getPattern()
!= null
)
schema.setPattern(s.getPattern());
if (s.getNumP() != 0) {
Map<String, io.swagger.v3.oas.models.media.Schema> properties = new HashMap<>();
...
...
@@ -827,9 +827,9 @@ aspect ReverseParser{
schema.setReadOnly(s.getReadOnly());
if (s.getWriteOnly() != null)
schema.setWriteOnly(s.getWriteOnly());
if (
!
s.getType()
.isEmpty()
)
if (s.getType()
!= null
)
schema.setType(s.getType());
if (
!
s.getTitle()
.isEmpty()
)
if (s.getTitle()
!= null
)
schema.setTitle(s.getTitle());
if (s.getUniqueItems() != null)
schema.setUniqueItems(s.getUniqueItems());
...
...
@@ -848,7 +848,7 @@ aspect ReverseParser{
public static io.swagger.v3.oas.models.media.Discriminator DiscriminatorObject.reverseDiscriminator(DiscriminatorObject discriminatorObject){
io.swagger.v3.oas.models.media.Discriminator discriminator = new io.swagger.v3.oas.models.media.Discriminator();
if (
!
discriminatorObject.getPropertyName()
.isEmpty()
)
if (discriminatorObject.getPropertyName()
!= null
)
discriminator.setPropertyName(discriminatorObject.getPropertyName());
if (discriminatorObject.getNumM() != 0) {
Map<String, String> mapping = new HashMap<>();
...
...
@@ -863,11 +863,11 @@ aspect ReverseParser{
public static io.swagger.v3.oas.models.media.XML XmlObject.reverseXml(XmlObject xmlObject){
io.swagger.v3.oas.models.media.XML xml = new io.swagger.v3.oas.models.media.XML();
if (
!
xmlObject.getName()
.isEmpty()
)
if (xmlObject.getName()
!= null
)
xml.setName(xmlObject.getName());
if (
!
xmlObject.getNamespace()
.isEmpty()
)
if (xmlObject.getNamespace()
!= null
)
xml.setNamespace(xmlObject.getNamespace());
if (
!
xmlObject.getPrefix()
.isEmpty()
)
if (xmlObject.getPrefix()
!= null
)
xml.setPrefix(xmlObject.getPrefix());
if (xmlObject.getAttribute() != null)
xml.setAttribute(xmlObject.getAttribute());
...
...
@@ -882,7 +882,7 @@ aspect ReverseParser{
io.swagger.v3.oas.models.security.SecurityScheme securityScheme = new io.swagger.v3.oas.models.security.SecurityScheme();
SecuritySchemeReference s = (SecuritySchemeReference) securitySchemeOb;
if (
!
s.getRef()
.isEmpty()
) {
if (s.getRef()
!= null
) {
securityScheme.set$ref(s.getRef());
}
...
...
@@ -906,7 +906,7 @@ aspect ReverseParser{
securityScheme.setType(SecurityScheme.Type.OPENIDCONNECT);
break;
}
if (
!
s.getName()
.isEmpty()
)
if (s.getName()
!= null
)
securityScheme.setName(s.getName());
switch (s.getIn()) {
case "cookie":
...
...
@@ -919,15 +919,15 @@ aspect ReverseParser{
securityScheme.setIn(SecurityScheme.In.QUERY);
break;
}
if (
!
s.getScheme()
.isEmpty()
)
if (s.getScheme()
!= null
)
securityScheme.setScheme(s.getScheme());
if (
!
s.getOpenIdConnectUrl()
.isEmpty()
)
if (s.getOpenIdConnectUrl()
!= null
)
securityScheme.setOpenIdConnectUrl(s.getOpenIdConnectUrl());
if (s.getO() != null)
securityScheme.setFlows(OAuthFlowsObject.reverseOAuthFlows(s.getO()));
if (
!
s.getDescription()
.isEmpty()
)
if (s.getDescription()
!= null
)
securityScheme.setDescription(s.getDescription());
if (
!
s.getBearerFormat()
.isEmpty()
)
if (s.getBearerFormat()
!= null
)
securityScheme.setBearerFormat(s.getBearerFormat());
if (s.getNumEx() != 0) {
Map<String, Object> extensionMap = new HashMap<>();
...
...
This diff is collapsed.
Click to expand it.
src/test/java/openapi/OpenAPIMain_test.java
+
5
−
1
View file @
c5afb7dd
...
...
@@ -100,15 +100,17 @@ public class OpenAPIMain_test {
actualWriter
.
close
();
// compare if api (source object) is equivalent to api3 (generated object)
//
compareJson(expectedNode, actualNode, Paths.get(file));
compareJson
(
expectedNode
,
actualNode
,
Paths
.
get
(
file
));
}
// clean all generated jsons
/*
contents = genDirectory.listFiles();
if (contents != null) {
for (File file : contents)
file.delete();
}
*/
}
protected
void
compareJson
(
JsonNode
expectedNode
,
JsonNode
actualNode
,
Path
path
)
throws
IOException
{
...
...
@@ -128,6 +130,8 @@ public class OpenAPIMain_test {
// check, if this node exists or has an empty value.
System
.
out
.
println
(
"1"
);
System
.
out
.
println
(
pathNode
);
if
(
JsonPath
.
parse
(
actualNode
.
toString
()).
read
(
pathNode
,
String
.
class
)
==
null
||
JsonPath
.
parse
(
actualNode
.
toString
()).
read
(
pathNode
,
String
.
class
).
isEmpty
())
((
ArrayNode
)
diff
).
remove
(
i
);
else
if
(!
JsonPath
.
parse
(
actualNode
.
toString
()).
read
(
pathNode
.
substring
(
0
,
pathNode
.
lastIndexOf
(
"."
)).
concat
(
".$ref"
),
String
.
class
).
isEmpty
())
...
...
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