Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fixed baseName error in PHP #629

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading