diff --git a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java index 36287c360..8906bd384 100644 --- a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java @@ -4,6 +4,7 @@ import com.twilio.oai.PathUtils; import com.twilio.oai.StringHelper; import com.twilio.oai.common.ApplicationConstants; +import com.twilio.oai.common.EnumConstants; import com.twilio.oai.common.Utility; import com.twilio.oai.resolver.Resolver; import com.twilio.oai.resource.Resource; @@ -347,4 +348,22 @@ protected boolean updateNestedContent(CodegenOperation co) { } return hasNestedRequestBody; } + + // Supported content types for this method are application/json and application/x-www-form-urlencoded. + protected void updateContentType(CodegenOperation co) { + if (co.consumes == null || co.consumes.size() == 0) { + co.vendorExtensions.put("x-www-form-urlencoded", true); + return; + } + for (Map map : co.consumes) { + if (EnumConstants.ContentType.APPLICATION_JSON.getValue().equals(map.get("mediaType"))) { + co.vendorExtensions.put(ApplicationConstants.X_JSON, true); + } else if (EnumConstants.ContentType.APPLICATION_FORM_URLENCODED.getValue().equals(map.get("mediaType"))) { + co.vendorExtensions.put(ApplicationConstants.X_WWW_FORM_URLENCODED, true); + } else { + // TODO: GET does not have body thus does not have content type + co.vendorExtensions.put(ApplicationConstants.X_WWW_FORM_URLENCODED, true); + } + } + } } diff --git a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java index 3e95f1123..a83fb3900 100644 --- a/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/JavaApiResourceBuilder.java @@ -102,6 +102,7 @@ public ApiResourceBuilder updateOperations(Resolver codegenPar JsonRequestBodyResolver jsonRequestBodyResolver = new JsonRequestBodyResolver(this, codegenPropertyIResolver); this.codegenOperationList.forEach(co -> { updateNestedContent(co); + updateContentType(co); updateHttpMethod(co); List filePathArray = new ArrayList<>(Arrays.asList(co.baseName.split(PATH_SEPARATOR_PLACEHOLDER))); String resourceName = filePathArray.remove(filePathArray.size()-1); @@ -667,4 +668,5 @@ private void addUniqueResponseModelEnums(List codegenProperties public JavaApiResources build() { return new JavaApiResources(this); } + } diff --git a/src/main/java/com/twilio/oai/common/ApplicationConstants.java b/src/main/java/com/twilio/oai/common/ApplicationConstants.java index 953d2e03c..f28aae2f6 100644 --- a/src/main/java/com/twilio/oai/common/ApplicationConstants.java +++ b/src/main/java/com/twilio/oai/common/ApplicationConstants.java @@ -55,4 +55,7 @@ public class ApplicationConstants { public static final String PHONE_NUMBER = "phone-number"; public static final Predicate SUCCESS = i -> i != null && i >= 200 && i < 400; + + public static final String X_JSON = "x-is-json"; + public static final String X_WWW_FORM_URLENCODED = "x-www-form-urlencoded"; } diff --git a/src/main/java/com/twilio/oai/common/EnumConstants.java b/src/main/java/com/twilio/oai/common/EnumConstants.java index 45e457ad1..9e4212329 100644 --- a/src/main/java/com/twilio/oai/common/EnumConstants.java +++ b/src/main/java/com/twilio/oai/common/EnumConstants.java @@ -122,4 +122,13 @@ public enum CsharpHttpMethod { private final String value; } + + @Getter + @RequiredArgsConstructor + public enum ContentType { + APPLICATION_JSON("application/json"), + APPLICATION_FORM_URLENCODED("application/x-www-form-urlencoded"); + + private final String value; + } } diff --git a/src/test/java/com/twilio/oai/TwilioGeneratorTest.java b/src/test/java/com/twilio/oai/TwilioGeneratorTest.java index a06c24603..978af9cfc 100644 --- a/src/test/java/com/twilio/oai/TwilioGeneratorTest.java +++ b/src/test/java/com/twilio/oai/TwilioGeneratorTest.java @@ -28,7 +28,14 @@ public class TwilioGeneratorTest { @Parameterized.Parameters public static Collection generators() { - return Arrays.asList(Generator.TWILIO_PYTHON); + return Arrays.asList(Generator.TWILIO_CSHARP, + Generator.TWILIO_GO, + Generator.TWILIO_JAVA, + Generator.TWILIO_NODE, + Generator.TWILIO_PHP, + Generator.TWILIO_PYTHON, + Generator.TWILIO_RUBY, + Generator.TWILIO_TERRAFORM); } private final Generator generator; @@ -41,6 +48,7 @@ public static void setUp() { @Test public void launchGenerator() { final String pathname = "examples/spec/twilio_api_v2010.yaml"; +// final String pathname = "examples/twilio_messaging_bulk_v1.yaml"; File filesList[] ; File directoryPath = new File(pathname); if (directoryPath.isDirectory()) {