|
4 | 4 | import io.swagger.models.ModelImpl;
|
5 | 5 | import io.swagger.models.properties.*;
|
6 | 6 | import io.swagger.util.Json;
|
| 7 | +import org.json.JSONObject; |
7 | 8 | import org.slf4j.Logger;
|
8 | 9 | import org.slf4j.LoggerFactory;
|
9 | 10 |
|
@@ -46,7 +47,15 @@ public List<Map<String, String>> generate(Map<String, Object> examples, List<Str
|
46 | 47 | Map<String, String> kv = new HashMap<>();
|
47 | 48 | kv.put(CONTENT_TYPE, mediaType);
|
48 | 49 | if (property != null && mediaType.startsWith(MIME_TYPE_JSON)) {
|
49 |
| - String example = Json.pretty(resolvePropertyToExample("", mediaType, property, processedModels)); |
| 50 | + /* |
| 51 | + org.json is used to pretty print example, because of an issue with |
| 52 | + Jackson pretty printing for large specs, where for some reason |
| 53 | + memory usage goes up to OOM errors. |
| 54 | + TODO if bug (?) is fixed in Jackson pretty printing, remove the dep and use jackson instead |
| 55 | + */ |
| 56 | + //String example = Json.pretty(resolvePropertyToExample("", mediaType, property, processedModels)); |
| 57 | + String example = new JSONObject(resolvePropertyToExample("", mediaType, property, processedModels)).toString(2); |
| 58 | + |
50 | 59 |
|
51 | 60 | if (example != null) {
|
52 | 61 | kv.put(EXAMPLE, example);
|
@@ -91,7 +100,14 @@ public List<Map<String, String>> generate(Map<String, Object> examples, List<Str
|
91 | 100 | final Model model = this.examples.get(modelName);
|
92 | 101 | if (model != null) {
|
93 | 102 |
|
94 |
| - String example = Json.pretty(resolveModelToExample(modelName, mediaType, model, processedModels)); |
| 103 | + /* |
| 104 | + org.json is used to pretty print example, because of an issue with |
| 105 | + Jackson pretty printing for large specs, where for some reason |
| 106 | + memory usage goes up to OOM errors. |
| 107 | + TODO if bug (?) is fixed in Jackson pretty printing, remove the dep and use jackson instead |
| 108 | + */ |
| 109 | + // String example = Json.pretty(resolveModelToExample(modelName, mediaType, model, processedModels)); |
| 110 | + String example = new JSONObject(resolveModelToExample(modelName, mediaType, model, processedModels)).toString(2); |
95 | 111 |
|
96 | 112 | if (example != null) {
|
97 | 113 | kv.put(EXAMPLE, example);
|
@@ -216,7 +232,7 @@ private Object resolvePropertyToExample(String propertyName, String mediaType, P
|
216 | 232 | }
|
217 | 233 | logger.warn("Ref property with empty model.");
|
218 | 234 | } else if (property instanceof UUIDProperty) {
|
219 |
| - return "046b6c7f-0b8a-43b9-b35d-6489e6daee91"; |
| 235 | + return "046b6c7f-0b8a-43b9-b35d-6489e6daee91"; |
220 | 236 | }
|
221 | 237 |
|
222 | 238 | return "";
|
|
0 commit comments