Skip to content

Commit f42ae16

Browse files
committed
Add support for command line call
1 parent 493bf70 commit f42ae16

File tree

7 files changed

+621
-79
lines changed

7 files changed

+621
-79
lines changed

README.md

Lines changed: 167 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,41 @@ Compare two OpenAPI specifications(3.x) and render the difference to html file o
2424

2525
# Usage
2626
OpenDiff can read swagger api spec from json file or http.
27+
28+
## Command Line
29+
30+
```bash
31+
$ openapi-diff --help
32+
usage: openapi-diff <old> <new>
33+
--debug Print debugging information
34+
--error Print error information
35+
-h,--help print this message
36+
--header <property=value> use given header for authorisation
37+
--html <file> export diff as html in given file
38+
--info Print additional information
39+
-l,--log <level> use given level for log (TRACE, DEBUG,
40+
INFO, WARN, ERROR, OFF). Default: ERROR
41+
--markdown <file> export diff as markdown in given file
42+
-o,--output <format=file> use given format (html, markdown) for
43+
output in file
44+
--off No information printed
45+
--query <property=value> use query param for authorisation
46+
--trace be extra verbose
47+
--version print the version information and exit
48+
--warn Print warning information
49+
```
50+
51+
## Direct Invocation
52+
2753
```java
2854
final String OPENAPI_V3_DOC1 = "petstore_v3_1.json";
2955
final String OPENAPI_V3_DOC2 = "http://petstore.swagger.io/v2/swagger.json";
3056

3157
SwaggerDiff diff = OpenApiDiff.compare(SWAGGER_V3_DOC1, SWAGGER_V3_DOC2);
3258
```
3359

34-
# Render difference
60+
### Render difference
61+
---
3562
#### HTML
3663
```java
3764
String html = new HtmlRender("Changelog",
@@ -62,58 +89,177 @@ try {
6289
e.printStackTrace();
6390
}
6491
```
92+
93+
# Example
94+
### CLI Output
95+
96+
```text
97+
==========================================================================
98+
== API CHANGE LOG ==
99+
==========================================================================
100+
Swagger Petstore
101+
--------------------------------------------------------------------------
102+
-- What's New --
103+
--------------------------------------------------------------------------
104+
- GET /pet/{petId}
105+
106+
--------------------------------------------------------------------------
107+
-- What's Deleted --
108+
--------------------------------------------------------------------------
109+
- POST /pet/{petId}
110+
111+
--------------------------------------------------------------------------
112+
-- What's Deprecated --
113+
--------------------------------------------------------------------------
114+
- GET /user/logout
115+
116+
--------------------------------------------------------------------------
117+
-- What's Changed --
118+
--------------------------------------------------------------------------
119+
- PUT /pet
120+
Request:
121+
- Deleted application/xml
122+
- Changed application/json
123+
Schema: Backward compatible
124+
- POST /pet
125+
Parameter:
126+
- Add tags in query
127+
Request:
128+
- Changed application/xml
129+
Schema: Backward compatible
130+
- Changed application/json
131+
Schema: Backward compatible
132+
- GET /pet/findByStatus
133+
Parameter:
134+
- Deprecated status in query
135+
Return Type:
136+
- Changed 200 OK
137+
Media types:
138+
- Changed application/xml
139+
Schema: Broken compatibility
140+
- Changed application/json
141+
Schema: Broken compatibility
142+
- GET /pet/findByTags
143+
Return Type:
144+
- Changed 200 OK
145+
Media types:
146+
- Changed application/xml
147+
Schema: Broken compatibility
148+
- Changed application/json
149+
Schema: Broken compatibility
150+
- DELETE /pet/{petId}
151+
Parameter:
152+
- Add newHeaderParam in header
153+
- POST /pet/{petId}/uploadImage
154+
Parameter:
155+
- Changed petId in path
156+
- POST /user
157+
Request:
158+
- Changed application/json
159+
Schema: Backward compatible
160+
- POST /user/createWithArray
161+
Request:
162+
- Changed application/json
163+
Schema: Backward compatible
164+
- POST /user/createWithList
165+
Request:
166+
- Changed application/json
167+
Schema: Backward compatible
168+
- GET /user/login
169+
Parameter:
170+
- Delete password in query
171+
- GET /user/logout
172+
- GET /user/{username}
173+
Return Type:
174+
- Changed 200 OK
175+
Media types:
176+
- Changed application/xml
177+
Schema: Broken compatibility
178+
- Changed application/json
179+
Schema: Broken compatibility
180+
- PUT /user/{username}
181+
Request:
182+
- Changed application/json
183+
Schema: Backward compatible
184+
--------------------------------------------------------------------------
185+
-- Result --
186+
--------------------------------------------------------------------------
187+
API changes broke backward compatibility
188+
--------------------------------------------------------------------------
189+
```
190+
191+
### Markdown
65192
```markdown
66193
### What's New
67194
---
68195
* `GET` /pet/{petId} Find pet by ID
69196

70-
### What's Deprecated
197+
### What's Deleted
71198
---
72199
* `POST` /pet/{petId} Updates a pet in the store with form data
73200

201+
### What's Deprecated
202+
---
203+
* `GET` /user/logout Logs out current logged in user session
204+
74205
### What's Changed
75206
---
76207
* `PUT` /pet Update an existing pet
77-
Parameter
208+
Request
78209

79-
Add body.newField //a field demo
80-
Add body.category.newCatField
81-
Delete body.category.name
210+
Deleted request body : [application/xml]
211+
Changed response : [application/json]
82212
* `POST` /pet Add a new pet to the store
83213
Parameter
84214

85215
Add tags //add new query param demo
86-
Add body.newField //a field demo
87-
Add body.category.newCatField
88-
Delete body.category.name
216+
Request
217+
218+
Changed response : [application/xml]
219+
Changed response : [application/json]
220+
* `GET` /pet/findByStatus Finds Pets by status
221+
Parameter
222+
223+
Return Type
224+
225+
Changed response : [200] //successful operation
226+
* `GET` /pet/findByTags Finds Pets by tags
227+
Return Type
228+
229+
Changed response : [200] //successful operation
89230
* `DELETE` /pet/{petId} Deletes a pet
90231
Parameter
91232

92233
Add newHeaderParam
93234
* `POST` /pet/{petId}/uploadImage uploads an image for pet
94235
Parameter
95236

96-
petId change into not required Notes ID of pet to update change into ID of pet to update, default false
237+
petId Notes ID of pet to update change into ID of pet to update, default false
97238
* `POST` /user Create user
98-
Parameter
239+
Request
99240

100-
Add body.newUserFeild //a new user feild demo
101-
Delete body.phone
241+
Changed response : [application/json]
242+
* `POST` /user/createWithArray Creates list of users with given input array
243+
Request
244+
245+
Changed response : [application/json]
246+
* `POST` /user/createWithList Creates list of users with given input array
247+
Request
248+
249+
Changed response : [application/json]
102250
* `GET` /user/login Logs user into the system
103251
Parameter
104252

105253
Delete password //The password for login in clear text
106-
* `GET` /user/{username} Get user by user name
107-
Return Type
108-
109-
Add newUserFeild //a new user feild demo
110-
Delete phone
254+
* `GET` /user/logout Logs out current logged in user session
111255
* `PUT` /user/{username} Updated user
112-
Parameter
256+
Request
113257

114-
Add body.newUserFeild //a new user feild demo
115-
Delete body.phone
258+
Changed response : [application/json]
259+
* `GET` /user/{username} Get user by user name
260+
Return Type
116261

262+
Changed response : [200] //successful operation
117263
```
118264

119265
# License

pom.xml

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@
7979
<artifactId>commons-collections4</artifactId>
8080
<version>4.0</version>
8181
</dependency>
82+
<dependency>
83+
<groupId>commons-cli</groupId>
84+
<artifactId>commons-cli</artifactId>
85+
<version>1.4</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.slf4j</groupId>
89+
<artifactId>slf4j-api</artifactId>
90+
<version>1.7.25</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.slf4j</groupId>
94+
<artifactId>slf4j-log4j12</artifactId>
95+
<version>1.7.25</version>
96+
</dependency>
97+
<dependency>
98+
<groupId>commons-httpclient</groupId>
99+
<artifactId>commons-httpclient</artifactId>
100+
<version>3.1</version>
101+
</dependency>
82102
</dependencies>
83103

84104
<profiles>
@@ -99,7 +119,7 @@
99119
<plugin>
100120
<groupId>org.apache.maven.plugins</groupId>
101121
<artifactId>maven-source-plugin</artifactId>
102-
<version>2.2.1</version>
122+
<version>3.0.1</version>
103123
<executions>
104124
<execution>
105125
<phase>package</phase>
@@ -113,7 +133,7 @@
113133
<plugin>
114134
<groupId>org.apache.maven.plugins</groupId>
115135
<artifactId>maven-javadoc-plugin</artifactId>
116-
<version>2.9.1</version>
136+
<version>3.0.0</version>
117137
<configuration>
118138
<quiet>true</quiet>
119139
<nonavbar>true</nonavbar>
@@ -130,20 +150,6 @@
130150
</execution>
131151
</executions>
132152
</plugin>
133-
<!-- GPG -->
134-
<plugin>
135-
<groupId>org.apache.maven.plugins</groupId>
136-
<artifactId>maven-gpg-plugin</artifactId>
137-
<version>1.5</version>
138-
<executions>
139-
<execution>
140-
<phase>verify</phase>
141-
<goals>
142-
<goal>sign</goal>
143-
</goals>
144-
</execution>
145-
</executions>
146-
</plugin>
147153
</plugins>
148154
</build>
149155
<distributionManagement>
@@ -169,6 +175,19 @@
169175
</configuration>
170176
<version>3.2</version>
171177
</plugin>
178+
<plugin>
179+
<artifactId>maven-assembly-plugin</artifactId>
180+
<configuration>
181+
<archive>
182+
<manifest>
183+
<mainClass>com.qdesrame.openapi.diff.Main</mainClass>
184+
</manifest>
185+
</archive>
186+
<descriptorRefs>
187+
<descriptorRef>jar-with-dependencies</descriptorRef>
188+
</descriptorRefs>
189+
</configuration>
190+
</plugin>
172191
</plugins>
173192
</build>
174193
</project>

0 commit comments

Comments
 (0)