mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-29 04:00:51 +00:00
add camelCase support for php variable naming
This commit is contained in:
parent
3f8dbf416d
commit
a43d2163a0
@ -24,6 +24,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
protected String packagePath = "SwaggerClient-php";
|
protected String packagePath = "SwaggerClient-php";
|
||||||
protected String artifactVersion = "1.0.0";
|
protected String artifactVersion = "1.0.0";
|
||||||
protected String srcBasePath = "lib";
|
protected String srcBasePath = "lib";
|
||||||
|
protected String variableNamingConvention= "snake_case";
|
||||||
|
|
||||||
public PhpClientCodegen() {
|
public PhpClientCodegen() {
|
||||||
super();
|
super();
|
||||||
@ -84,6 +85,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
typeMapping.put("object", "object");
|
typeMapping.put("object", "object");
|
||||||
typeMapping.put("DateTime", "\\DateTime");
|
typeMapping.put("DateTime", "\\DateTime");
|
||||||
|
|
||||||
|
cliOptions.add(new CliOption("variableNamingConvention", "naming convention of variable name, e.g. camelCase. Default: snake_case"));
|
||||||
cliOptions.add(new CliOption("invokerPackage", "The main namespace to use for all classes. e.g. Yay\\Pets"));
|
cliOptions.add(new CliOption("invokerPackage", "The main namespace to use for all classes. e.g. Yay\\Pets"));
|
||||||
cliOptions.add(new CliOption("packagePath", "The main package name for classes. e.g. GeneratedPetstore"));
|
cliOptions.add(new CliOption("packagePath", "The main package name for classes. e.g. GeneratedPetstore"));
|
||||||
cliOptions.add(new CliOption("srcBasePath", "The directory under packagePath to serve as source root."));
|
cliOptions.add(new CliOption("srcBasePath", "The directory under packagePath to serve as source root."));
|
||||||
@ -279,6 +281,10 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
this.srcBasePath = srcBasePath;
|
this.srcBasePath = srcBasePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setParameterNamingConvention(String variableNamingConvention) {
|
||||||
|
this.variableNamingConvention = variableNamingConvention;
|
||||||
|
}
|
||||||
|
|
||||||
private void setComposerVendorName(String composerVendorName) {
|
private void setComposerVendorName(String composerVendorName) {
|
||||||
this.composerVendorName = composerVendorName;
|
this.composerVendorName = composerVendorName;
|
||||||
}
|
}
|
||||||
@ -289,9 +295,19 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toVarName(String name) {
|
public String toVarName(String name) {
|
||||||
|
if (additionalProperties.containsKey("variableNamingConvention")) {
|
||||||
|
this.setParameterNamingConvention((String) additionalProperties.get("variableNamingConvention"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("camelCase".equals(variableNamingConvention)) {
|
||||||
|
// return the name in camelCase style
|
||||||
|
// phone_number => phoneNumber
|
||||||
|
name = camelize(name, true);
|
||||||
|
} else { // default to snake case
|
||||||
// return the name in underscore style
|
// return the name in underscore style
|
||||||
// PhoneNumber => phone_number
|
// PhoneNumber => phone_number
|
||||||
name = underscore(name);
|
name = underscore(name);
|
||||||
|
}
|
||||||
|
|
||||||
// parameter name starting with number won't compile
|
// parameter name starting with number won't compile
|
||||||
// need to escape it by appending _ at the beginning
|
// need to escape it by appending _ at the beginning
|
||||||
|
Loading…
x
Reference in New Issue
Block a user