diff --git a/src/main/java/com/twilio/oai/TwilioPhpGenerator.java b/src/main/java/com/twilio/oai/TwilioPhpGenerator.java index 98883f61a..201c45c09 100644 --- a/src/main/java/com/twilio/oai/TwilioPhpGenerator.java +++ b/src/main/java/com/twilio/oai/TwilioPhpGenerator.java @@ -1,5 +1,7 @@ package com.twilio.oai; +import com.google.common.collect.ImmutableMap; +import com.samskivert.mustache.Mustache; import com.twilio.oai.api.PhpApiResourceBuilder; import com.twilio.oai.api.PhpApiResources; import com.twilio.oai.api.PhpDomainBuilder; @@ -11,6 +13,7 @@ import com.twilio.oai.resolver.php.*; import com.twilio.oai.resource.ResourceMap; import com.twilio.oai.template.PhpApiActionTemplate; +import com.twilio.oai.templating.mustache.TitleCamelCaseLambda; import io.swagger.v3.oas.models.OpenAPI; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; @@ -39,6 +42,13 @@ public class TwilioPhpGenerator extends PhpClientCodegen { private final IConventionMapper conventionMapper = new LanguageConventionResolver(PHP_CONVENTIONAL_MAP_PATH); private final PhpApiActionTemplate phpApiActionTemplate = new PhpApiActionTemplate(this); + @Override + protected ImmutableMap.Builder addMustacheLambdas() { + ImmutableMap.Builder lambdaBuilder = super.addMustacheLambdas(); + lambdaBuilder.put("customcamelcase", new TitleCamelCaseLambda()); + return lambdaBuilder; + } + public TwilioPhpGenerator() { super(); twilioCodegen = new TwilioCodegenAdapter(this, getName()); diff --git a/src/main/java/com/twilio/oai/resolver/php/PhpPropertyResolver.java b/src/main/java/com/twilio/oai/resolver/php/PhpPropertyResolver.java index 428b0b252..add3914f6 100644 --- a/src/main/java/com/twilio/oai/resolver/php/PhpPropertyResolver.java +++ b/src/main/java/com/twilio/oai/resolver/php/PhpPropertyResolver.java @@ -21,9 +21,6 @@ public PhpPropertyResolver(IConventionMapper mapper) { @Override public CodegenProperty resolve(final CodegenProperty codegenProperty, ApiResourceBuilder apiResourceBuilder) { super.resolve(codegenProperty, apiResourceBuilder); - - codegenProperty.baseName = StringHelper.camelize(codegenProperty.baseName, true); - return codegenProperty; } diff --git a/src/main/java/com/twilio/oai/templating/mustache/TitleCamelCaseLambda.java b/src/main/java/com/twilio/oai/templating/mustache/TitleCamelCaseLambda.java new file mode 100644 index 000000000..fab6d282f --- /dev/null +++ b/src/main/java/com/twilio/oai/templating/mustache/TitleCamelCaseLambda.java @@ -0,0 +1,24 @@ +package com.twilio.oai.templating.mustache; + +import com.samskivert.mustache.Mustache; +import com.samskivert.mustache.Template; +import com.twilio.oai.StringHelper; +import lombok.RequiredArgsConstructor; + +import java.io.IOException; +import java.io.Writer; + +@RequiredArgsConstructor +public class TitleCamelCaseLambda implements Mustache.Lambda { + private final String delimiter; + + public TitleCamelCaseLambda() { + this(" "); + } + + @Override + public void execute(Template.Fragment fragment, Writer writer) throws IOException { + final String text = StringHelper.camelize(fragment.execute(), true); + writer.write(text); + } +} diff --git a/src/main/resources/twilio-php/instance.mustache b/src/main/resources/twilio-php/instance.mustache index 569039250..f507b36d3 100644 --- a/src/main/resources/twilio-php/instance.mustache +++ b/src/main/resources/twilio-php/instance.mustache @@ -10,7 +10,7 @@ namespace Twilio\Rest\{{domainName}}\{{version}}{{namespaceSubPart}}; {{#responseModels.0}} /** {{#responseModels}} - * @property {{{dataType}}} ${{baseName}} + * @property {{{dataType}}} ${{#lambda.customcamelcase}}{{baseName}}{{/lambda.customcamelcase}} {{/responseModels}} */ {{/responseModels.0}} @@ -40,10 +40,10 @@ class {{apiName}}Instance extends InstanceResource $this->properties = [ {{#responseModels}} {{^vendorExtensions.x-deserialize}} - '{{baseName}}' => Values::array_get($payload, '{{name}}'), + '{{#lambda.customcamelcase}}{{baseName}}{{/lambda.customcamelcase}}' => Values::array_get($payload, '{{name}}'), {{/vendorExtensions.x-deserialize}} {{#vendorExtensions.x-deserialize}} - '{{baseName}}' => {{.}}(Values::array_get($payload, '{{name}}')), + '{{#lambda.customcamelcase}}{{baseName}}{{/lambda.customcamelcase}}' => {{.}}(Values::array_get($payload, '{{name}}')), {{/vendorExtensions.x-deserialize}} {{/responseModels}} ]; diff --git a/src/main/resources/twilio-php/models/modelClass.mustache b/src/main/resources/twilio-php/models/modelClass.mustache index 4bdb0ca43..3ad079aaa 100644 --- a/src/main/resources/twilio-php/models/modelClass.mustache +++ b/src/main/resources/twilio-php/models/modelClass.mustache @@ -10,7 +10,7 @@ class {{classname}} implements \JsonSerializable {{/vars}} public function __construct(array $payload = []) { {{#vars}} - $this->{{#lambda.camelcase}}{{baseName}}{{/lambda.camelcase}} = Values::array_get($payload, '{{name}}'); + $this->{{#lambda.camelcase}}{{baseName}}{{/lambda.camelcase}} = Values::array_get($payload, '{{baseName}}'); {{/vars}} }