|
3 | 3 | import com.algolia.codegen.cts.manager.CTSManager; |
4 | 4 | import com.algolia.codegen.exceptions.CTSException; |
5 | 5 | import com.algolia.codegen.utils.*; |
| 6 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 7 | +import com.fasterxml.jackson.databind.JsonMappingException; |
6 | 8 | import io.swagger.v3.core.util.Json; |
7 | 9 | import java.io.File; |
8 | 10 | import java.nio.file.Files; |
@@ -98,4 +100,33 @@ private String injectVariables(String json) { |
98 | 100 | .replace("${{clientPascalCase}}", Helpers.capitalize(Helpers.camelize(client))) |
99 | 101 | .replace("\"${{nowRounded}}\"", String.valueOf(Math.round(System.currentTimeMillis() / threeDays) * threeDays)); |
100 | 102 | } |
| 103 | + |
| 104 | + protected void addRequestOptions(ParametersWithDataType paramsType, RequestOptions req, Map<String, Object> output) |
| 105 | + throws JsonMappingException, JsonProcessingException { |
| 106 | + if (req != null) { |
| 107 | + output.put("hasRequestOptions", true); |
| 108 | + Map<String, Object> requestOptions = new HashMap<>(); |
| 109 | + if (req.queryParameters != null) { |
| 110 | + Map<String, Object> queryParameters = new HashMap<>(); |
| 111 | + paramsType.enhanceParameters(req.queryParameters, queryParameters); |
| 112 | + requestOptions.put("queryParameters", queryParameters); |
| 113 | + } |
| 114 | + if (req.headers != null) { |
| 115 | + Map<String, Object> headers = new HashMap<>(); |
| 116 | + // convert the headers to an acceptable type |
| 117 | + paramsType.enhanceParameters(new HashMap<String, Object>(req.headers), headers); |
| 118 | + requestOptions.put("headers", headers); |
| 119 | + } |
| 120 | + Map<String, Object> timeouts = null; |
| 121 | + if (req.readTimeout != null || req.writeTimeout != null || req.connectTimeout != null) { |
| 122 | + timeouts = new HashMap<>(); |
| 123 | + if (req.readTimeout != null) timeouts.put("read", req.readTimeout); |
| 124 | + if (req.writeTimeout != null) timeouts.put("write", req.writeTimeout); |
| 125 | + if (req.connectTimeout != null) timeouts.put("connect", req.connectTimeout); |
| 126 | + paramsType.enhanceParameters(timeouts, timeouts); |
| 127 | + } |
| 128 | + requestOptions.put("timeouts", timeouts); |
| 129 | + output.put("requestOptions", requestOptions); |
| 130 | + } |
| 131 | + } |
101 | 132 | } |
0 commit comments