|
3 | 3 | import static com.retailsvc.http.openapi.SpecificationLoader.parseSpecification; |
4 | 4 |
|
5 | 5 | import com.google.gson.Gson; |
| 6 | +import com.google.gson.GsonBuilder; |
6 | 7 | import com.retailsvc.http.ExceptionHandler; |
7 | 8 | import com.retailsvc.http.Handlers; |
8 | 9 | import com.retailsvc.http.OpenApiServer; |
|
13 | 14 | import java.util.HashMap; |
14 | 15 | import java.util.List; |
15 | 16 | import java.util.Map; |
| 17 | +import java.util.function.Function; |
16 | 18 | import org.slf4j.Logger; |
17 | 19 | import org.slf4j.LoggerFactory; |
18 | 20 |
|
19 | 21 | public class ServerLauncher { |
20 | 22 |
|
21 | 23 | private static final Logger LOG = LoggerFactory.getLogger(ServerLauncher.class); |
22 | 24 |
|
23 | | - public static void main(String[] args) throws Exception { |
| 25 | + static void main() throws Exception { |
24 | 26 | new ServerLauncher(); |
25 | 27 | } |
26 | 28 |
|
27 | 29 | public ServerLauncher() throws IOException { |
28 | 30 | long t0 = System.currentTimeMillis(); |
29 | 31 |
|
30 | | - final Gson gson = new Gson(); |
| 32 | + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
31 | 33 |
|
32 | | - var specification = parseSpecification("openapi.json", s -> gson.fromJson(s, OpenApi.class)); |
| 34 | + Function<String, OpenApi> jsonToSpec = contents -> gson.fromJson(contents, OpenApi.class); |
| 35 | + Function<Object, String> toJson = gson::toJson; |
| 36 | + |
| 37 | + var specification = parseSpecification("openapi.yaml", jsonToSpec, toJson); |
33 | 38 |
|
34 | 39 | Map<String, HttpHandler> handlers = new HashMap<>(); |
35 | 40 | handlers.put("get-data", new GetDataHandler()); |
|
0 commit comments