1
1
package io .squark .swaggercombine ;
2
2
3
+ import java .io .File ;
4
+ import java .io .FileInputStream ;
5
+ import java .util .ArrayList ;
6
+ import java .util .List ;
7
+ import java .util .Map ;
8
+ import java .util .Properties ;
9
+
10
+ import org .apache .commons .io .IOUtils ;
11
+
3
12
import com .fasterxml .jackson .annotation .JsonInclude ;
4
13
import com .fasterxml .jackson .core .util .DefaultPrettyPrinter ;
5
14
import com .fasterxml .jackson .databind .DeserializationFeature ;
6
15
import com .fasterxml .jackson .databind .Module ;
7
16
import com .fasterxml .jackson .databind .ObjectMapper ;
8
17
import com .fasterxml .jackson .databind .SerializationFeature ;
9
- import com .sun .org .apache .xpath .internal .operations .Bool ;
10
- import io .swagger .models .ExternalDocs ;
18
+
11
19
import io .swagger .models .Model ;
12
- import io .swagger .models .Operation ;
13
20
import io .swagger .models .Path ;
14
21
import io .swagger .models .Response ;
15
22
import io .swagger .models .Scheme ;
19
26
import io .swagger .models .auth .SecuritySchemeDefinition ;
20
27
import io .swagger .models .parameters .Parameter ;
21
28
import io .swagger .parser .SwaggerParser ;
22
- import io .swagger .parser .util .SwaggerDeserializer ;
23
29
import io .swagger .util .DeserializationModule ;
24
30
import io .swagger .util .Json ;
25
- import io .swagger .util .ObjectMapperFactory ;
26
- import org .apache .commons .io .IOUtils ;
27
-
28
- import java .io .File ;
29
- import java .io .FileInputStream ;
30
- import java .util .ArrayList ;
31
- import java .util .Arrays ;
32
- import java .util .List ;
33
- import java .util .Map ;
34
- import java .util .Properties ;
35
31
36
32
/**
37
33
* Created by erik on 2017-01-05.
@@ -64,7 +60,7 @@ public SwaggerCombine(List<String> files, Properties properties) throws Exceptio
64
60
public Swagger combine () {
65
61
66
62
boolean stripBasePath = (properties != null &&
67
- Boolean .parseBoolean (properties .getProperty ("--stripBasePath" , "false" )));
63
+ Boolean .parseBoolean (properties .getProperty ("--stripBasePath" , "false" )));
68
64
for (Swagger swagger : swaggers ) {
69
65
if (swagger .getTags () != null ) {
70
66
for (Tag tag : swagger .getTags ()) {
@@ -96,8 +92,9 @@ public Swagger combine() {
96
92
if (stripBasePath ) {
97
93
String replacedPath = path .getKey ();
98
94
if (path .getKey ().startsWith (firstSwagger .getBasePath ()) || path .getKey ().startsWith ("/" + firstSwagger .getBasePath ())) {
99
- replacedPath = path .getKey ().replace (firstSwagger .getBasePath (), "" )
100
- .replaceAll ("//" , "/" );
95
+ replacedPath = path .getKey ()
96
+ .replace (firstSwagger .getBasePath (), "" )
97
+ .replaceAll ("//" , "/" );
101
98
}
102
99
firstSwagger .path (replacedPath , path .getValue ());
103
100
} else {
@@ -154,7 +151,6 @@ public static void main(String[] args) throws Exception {
154
151
SwaggerCombine swaggerCombine = new SwaggerCombine (arguments , properties );
155
152
Swagger combined = swaggerCombine .combine ();
156
153
157
-
158
154
ObjectMapper mapper = Json .mapper ();
159
155
160
156
Module deserializerModule = new DeserializationModule (true , true );
@@ -163,11 +159,15 @@ public static void main(String[] args) throws Exception {
163
159
mapper .configure (SerializationFeature .FAIL_ON_EMPTY_BEANS , false );
164
160
mapper .configure (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS , false );
165
161
mapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
166
- File output = new File ("result.json" );
162
+
163
+ String outputFile = properties .getProperty ("--outputFile" );
164
+ if (outputFile == null ) {
165
+ outputFile = "result.json" ;
166
+ }
167
+ File output = new File (outputFile );
167
168
mapper .writer (new DefaultPrettyPrinter ()).writeValue (output , combined );
168
169
169
170
System .out .println ("Done." );
170
171
}
171
172
172
-
173
173
}
0 commit comments