Skip to content

Commit 482f05a

Browse files
authored
Merge pull request #1 from totvs/DEAITOOLS-220
Realizar Deploy do comparador de OpenAPI's e commit do projeto no maven
2 parents 2128208 + 48c4676 commit 482f05a

File tree

11 files changed

+602
-20
lines changed

11 files changed

+602
-20
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
eclipse.preferences.version=1
2+
encoding//src/main/java=UTF-8
3+
encoding//src/test/java=UTF-8
4+
encoding/<project>=UTF-8
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.release=disabled
7+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

apicompare/pom.xml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.totvs.ttalk</groupId>
6+
<artifactId>apicompare</artifactId>
7+
<version>2.0.0</version>
8+
<name>apicompare Maven Webapp</name>
9+
<url>http://maven.apache.org</url>
10+
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>2.0.4.RELEASE</version>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-web</artifactId>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-tomcat</artifactId>
26+
<scope>provided</scope>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>com.qdesrame</groupId>
31+
<artifactId>openapi-diff</artifactId>
32+
<version>2.0.4-TOTVS</version>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>com.jayway.jsonpath</groupId>
37+
<artifactId>json-path</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>commons-logging</groupId>
43+
<artifactId>commons-logging</artifactId>
44+
<version>1.2</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>com.google.code.gson</groupId>
49+
<artifactId>gson</artifactId>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>asm</groupId>
54+
<artifactId>asm</artifactId>
55+
<version>3.3.1</version>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.apache.httpcomponents</groupId>
60+
<artifactId>httpclient</artifactId>
61+
<version>4.4.1</version>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.apache.ws.security</groupId>
66+
<artifactId>wss4j</artifactId>
67+
<version>1.6.19</version>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>org.json</groupId>
72+
<artifactId>json</artifactId>
73+
<version>20180130</version>
74+
</dependency>
75+
76+
</dependencies>
77+
78+
<properties>
79+
<java.version>1.8</java.version>
80+
</properties>
81+
82+
83+
<build>
84+
<plugins>
85+
<plugin>
86+
<groupId>org.springframework.boot</groupId>
87+
<artifactId>spring-boot-maven-plugin</artifactId>
88+
<configuration>
89+
<requiresUnpack>
90+
<dependency>
91+
<groupId>org.apache.ws.security</groupId>
92+
<artifactId>wss4j</artifactId>
93+
</dependency>
94+
</requiresUnpack>
95+
</configuration>
96+
</plugin>
97+
</plugins>
98+
</build>
99+
100+
<repositories>
101+
<repository>
102+
<id>spring-releases</id>
103+
<url>https://repo.spring.io/libs-release</url>
104+
</repository>
105+
</repositories>
106+
<pluginRepositories>
107+
<pluginRepository>
108+
<id>spring-releases</id>
109+
<url>https://repo.spring.io/libs-release</url>
110+
</pluginRepository>
111+
</pluginRepositories>
112+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.totvs.ttalk.apicompare;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
6+
7+
@SpringBootApplication
8+
public class ApiCompareApplication extends SpringBootServletInitializer {
9+
10+
public static void main(String[] args) {
11+
SpringApplication.run(ApiCompareApplication.class, args);
12+
}
13+
14+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.totvs.ttalk.apicompare.resources;
2+
3+
import java.io.UnsupportedEncodingException;
4+
5+
import org.json.JSONException;
6+
import org.json.JSONObject;
7+
import org.springframework.web.bind.annotation.RequestBody;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestMethod;
10+
import org.springframework.web.bind.annotation.RequestParam;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
import com.qdesrame.openapi.diff.OpenApiCompare;
14+
import com.qdesrame.openapi.diff.model.ChangedOpenApi;
15+
import com.qdesrame.openapi.diff.output.ConsoleRender;
16+
import com.qdesrame.openapi.diff.output.JSONRender;
17+
18+
@RestController
19+
@RequestMapping("/totvseai/openapicomparator/v1")
20+
public class ApiCompareResource {
21+
22+
@RequestMapping(path = "/console", method = RequestMethod.POST, produces = { "text/plain" })
23+
public String postConsole(@RequestBody String body) throws UnsupportedEncodingException, JSONException {
24+
return console(body);
25+
}
26+
27+
@RequestMapping(path = "/json", method = RequestMethod.POST, produces = { "application/JSON" })
28+
public String postJSON(@RequestParam(value = "hasConsole", defaultValue = "true") Boolean hasConsole,
29+
@RequestBody String body) throws UnsupportedEncodingException, JSONException {
30+
return json(hasConsole, body);
31+
}
32+
33+
@RequestMapping(path = "/console", method = RequestMethod.GET, produces = { "text/plain" })
34+
public String console(@RequestBody String body) throws UnsupportedEncodingException, JSONException {
35+
JSONObject jsonBody = new JSONObject(body);
36+
ChangedOpenApi result = compare(jsonBody.get("olderVersion").toString(),
37+
jsonBody.get("newerVersion").toString());
38+
39+
ConsoleRender consoleRender = new ConsoleRender();
40+
String meuTexto = consoleRender.render(result);
41+
return meuTexto;
42+
}
43+
44+
@RequestMapping(path = "/json", method = RequestMethod.GET, produces = { "application/JSON" })
45+
public String json(@RequestParam(value = "hasConsole", defaultValue = "true") Boolean hasConsole,
46+
@RequestBody String body) throws UnsupportedEncodingException, JSONException {
47+
48+
JSONObject jsonBody = new JSONObject(body);
49+
50+
ChangedOpenApi result = compare(jsonBody.get("olderVersion").toString(),
51+
jsonBody.get("newerVersion").toString());
52+
53+
JSONRender jsonRender = new JSONRender();
54+
55+
String responsejson = jsonRender.render(result, hasConsole);
56+
return responsejson;
57+
}
58+
59+
private ChangedOpenApi compare(String olderVersion, String newerVersion) throws UnsupportedEncodingException {
60+
61+
// converting into UTF-8
62+
String oVersion = new String(olderVersion.getBytes("UTF-8"));
63+
String nVersion = new String(newerVersion.getBytes("UTF-8"));
64+
65+
ChangedOpenApi result = OpenApiCompare.fromContents(oVersion, nVersion);
66+
return result;
67+
}
68+
69+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.totvs.ttalk.apicompare.resources;
2+
3+
import org.springframework.web.bind.annotation.RequestBody;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RequestMethod;
6+
import org.springframework.web.bind.annotation.RequestParam;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
10+
@RestController
11+
@RequestMapping("/teste")
12+
public class teste {
13+
14+
@RequestMapping(path = "/console", method = RequestMethod.GET)
15+
public String console(@RequestBody String body){
16+
17+
String meuTexto = "teste";
18+
return meuTexto;
19+
}
20+
21+
@RequestMapping(path = "/json", method = RequestMethod.GET)
22+
public String json(@RequestParam(value="hasConsole", defaultValue="true") Boolean hasConsole,
23+
@RequestBody String body){
24+
25+
26+
String response = "TESTES";
27+
return response;
28+
}
29+
30+
}

pom.xml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<groupId>com.qdesrame</groupId>
1111
<artifactId>openapi-diff</artifactId>
12-
<version>2.0.0-SNAPSHOT</version>
12+
<version>2.0.4-TOTVS</version>
1313
<packaging>jar</packaging>
1414

1515
<name>openapi-diff</name>
@@ -130,6 +130,11 @@
130130
<artifactId>lombok</artifactId>
131131
<version>1.18.2</version>
132132
</dependency>
133+
<dependency>
134+
<groupId>org.json</groupId>
135+
<artifactId>json</artifactId>
136+
<version>20180130</version>
137+
</dependency>
133138
</dependencies>
134139

135140
<profiles>
@@ -280,30 +285,15 @@
280285
<artifactId>fmt-maven-plugin</artifactId>
281286
<version>2.6.0</version>
282287
<executions>
283-
<execution>
284-
<goals>
285-
<goal>format</goal>
286-
</goals>
287-
</execution>
288+
288289
</executions>
289290
</plugin>
290291
<plugin>
291292
<groupId>io.github.phillipuniverse</groupId>
292293
<artifactId>githook-maven-plugin</artifactId>
293294
<version>1.0.0</version>
294295
<executions>
295-
<execution>
296-
<goals>
297-
<goal>install</goal>
298-
</goals>
299-
<configuration>
300-
<hooks>
301-
<pre-commit>
302-
mvn com.coveo:fmt-maven-plugin:format
303-
</pre-commit>
304-
</hooks>
305-
</configuration>
306-
</execution>
296+
307297
</executions>
308298
</plugin>
309299
</plugins>

src/main/java/com/qdesrame/openapi/diff/Main.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.qdesrame.openapi.diff.model.ChangedOpenApi;
44
import com.qdesrame.openapi.diff.output.ConsoleRender;
55
import com.qdesrame.openapi.diff.output.HtmlRender;
6+
import com.qdesrame.openapi.diff.output.JSONRender;
67
import com.qdesrame.openapi.diff.output.MarkdownRender;
78
import java.io.File;
89
import java.io.IOException;
@@ -143,6 +144,10 @@ public static void main(String... args) {
143144
if (!logLevel.equals("OFF")) {
144145
System.out.println(consoleRender.render(result));
145146
}
147+
148+
JSONRender jsonRender = new JSONRender();
149+
System.out.println(jsonRender.render(result,true));
150+
146151
HtmlRender htmlRender = new HtmlRender();
147152
MarkdownRender mdRender = new MarkdownRender();
148153
String output = null;

0 commit comments

Comments
 (0)