Skip to content

Commit

Permalink
chore: fixed baseName error in PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwarishubham635 committed Jan 8, 2025
1 parent 5e1fcc0 commit 6f35968
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/twilio/oai/TwilioPhpGenerator.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, Mustache.Lambda> addMustacheLambdas() {
ImmutableMap.Builder<String, Mustache.Lambda> lambdaBuilder = super.addMustacheLambdas();
lambdaBuilder.put("customcamelcase", new TitleCamelCaseLambda());
return lambdaBuilder;
}

public TwilioPhpGenerator() {
super();
twilioCodegen = new TwilioCodegenAdapter(this, getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 3 additions & 3 deletions src/main/resources/twilio-php/instance.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}
];
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/twilio-php/models/modelClass.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}

Expand Down

0 comments on commit 6f35968

Please sign in to comment.