Skip to content

Commit 40c5236

Browse files
committed
feat: update the api.mustache template and go generator to support JSON media type for the request body
The Go Generator has been updated to add a vendor extension to set `x-is-json` to true when the consume media type is `application/json` and `x-is-form` when the consumes media type is `application/x-www-form-urlencoded` The `x-is-json` vendor extension is used to generate the code to handle calling the new PostJson function or the corresponding HTTP method function on the request handler. This is designed to only work with Post requests at the moment but could be extended in the future if needed. This PR aids in resolving twilio#49 however once this PR is merged twilio/twilio-oai#36 will need to be finished to fully resolve the issue This change relies on twilio/twilio-go#83 and the tests cannot be updated until this PR is merged and released This change also fixes an issue with JSON struct tags for the Params structs being `html-escaped`. I have disabled the escaping by using `{{{}}}` as this was highlighted during linting the Go SDK repo
1 parent e3f6a17 commit 40c5236

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/main/java/com/twilio/oai/TwilioGoGenerator.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.twilio.oai;
22

33
import io.swagger.v3.oas.models.OpenAPI;
4+
import org.openapitools.codegen.CodegenParameter;
5+
import org.openapitools.codegen.CodegenOperation;
6+
import org.openapitools.codegen.SupportingFile;
7+
48
import java.util.Collections;
59
import java.util.List;
610
import java.util.Map;
711
import java.util.Optional;
812

9-
import org.openapitools.codegen.CodegenOperation;
10-
import org.openapitools.codegen.CodegenParameter;
11-
import org.openapitools.codegen.SupportingFile;
12-
1313
public class TwilioGoGenerator extends AbstractTwilioGoGenerator {
1414

1515
@Override
@@ -20,10 +20,23 @@ public void processOpts() {
2020
supportingFiles.add(new SupportingFile("README.mustache", "README.md"));
2121
}
2222

23+
@Override
24+
public String toApiFilename(String name) {
25+
// Drop the "api_" prefix.
26+
return super.toApiFilename(name).replaceAll("^api_", "");
27+
}
28+
29+
@Override
30+
public void postProcessParameter(final CodegenParameter parameter) {
31+
super.postProcessParameter(parameter);
32+
33+
// Make sure required non-path params get into the options block.
34+
parameter.required = parameter.isPathParam;
35+
}
36+
2337
@SuppressWarnings("unchecked")
2438
@Override
25-
public Map<String, Object> postProcessOperationsWithModels(final Map<String, Object> objs,
26-
final List<Object> allModels) {
39+
public Map<String, Object> postProcessOperationsWithModels(final Map<String, Object> objs, final List<Object> allModels) {
2740
final Map<String, Object> results = super.postProcessOperationsWithModels(objs, allModels);
2841

2942
final Map<String, Object> ops = (Map<String, Object>) results.get("operations");
@@ -44,19 +57,6 @@ public Map<String, Object> postProcessOperationsWithModels(final Map<String, Obj
4457
return results;
4558
}
4659

47-
@Override
48-
public String toApiFilename(String name) {
49-
// Drop the "api_" prefix.
50-
return super.toApiFilename(name).replaceAll("^api_", "");
51-
}
52-
53-
@Override
54-
public void postProcessParameter(final CodegenParameter parameter) {
55-
super.postProcessParameter(parameter);
56-
57-
// Make sure required non-path params get into the options block.
58-
parameter.required = parameter.isPathParam;
59-
}
6060

6161
@Override
6262
public void processOpenAPI(final OpenAPI openAPI) {

0 commit comments

Comments
 (0)