forked from loafle/openapi-generator-original
Merge pull request #536 from wing328/android_better_naming
better naming convention for android-java codegen
This commit is contained in:
commit
0cf1c3c74a
@ -118,4 +118,49 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
|||||||
type = swaggerType;
|
type = swaggerType;
|
||||||
return toModelName(type);
|
return toModelName(type);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public String toVarName(String name) {
|
||||||
|
// replace - with _ e.g. created-at => created_at
|
||||||
|
name = name.replaceAll("-", "_");
|
||||||
|
|
||||||
|
// if it's all uppper case, do nothing
|
||||||
|
if (name.matches("^[A-Z_]*$"))
|
||||||
|
return name;
|
||||||
|
|
||||||
|
// camelize (lower first character) the variable name
|
||||||
|
// pet_id => petId
|
||||||
|
name = camelize(name, true);
|
||||||
|
|
||||||
|
// for reserved word or word starting with number, append _
|
||||||
|
if(reservedWords.contains(name) || name.matches("^\\d.*"))
|
||||||
|
name = escapeReservedWord(name);
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toParamName(String name) {
|
||||||
|
// should be the same as variable name
|
||||||
|
return toVarName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelName(String name) {
|
||||||
|
// model name cannot use reserved keyword, e.g. return
|
||||||
|
if(reservedWords.contains(name))
|
||||||
|
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||||
|
|
||||||
|
// camelize the model name
|
||||||
|
// phone_number => PhoneNumber
|
||||||
|
return camelize(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelFilename(String name) {
|
||||||
|
// should be the same as the model name
|
||||||
|
return toModelName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
|||||||
* maximum: {{maximum}}{{/maximum}}
|
* maximum: {{maximum}}{{/maximum}}
|
||||||
**/
|
**/
|
||||||
@ApiModelProperty(required = {{required}}, value = "{{{description}}}")
|
@ApiModelProperty(required = {{required}}, value = "{{{description}}}")
|
||||||
@JsonProperty("{{name}}")
|
@JsonProperty("{{baseName}}")
|
||||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||||
return {{name}};
|
return {{name}};
|
||||||
}
|
}
|
||||||
|
@ -383,7 +383,7 @@ public class PetApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void deletePet (String api_key, Long petId) throws ApiException {
|
public void deletePet (String apiKey, Long petId) throws ApiException {
|
||||||
Object postBody = null;
|
Object postBody = null;
|
||||||
|
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ public class PetApi {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
headerParams.put("api_key", ApiInvoker.parameterToString(api_key));
|
headerParams.put("api_key", ApiInvoker.parameterToString(apiKey));
|
||||||
|
|
||||||
|
|
||||||
String[] contentTypes = {
|
String[] contentTypes = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user