mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Merge pull request #2261 from wing328/php_model_name_improve
[PHP][Python][Perl] add prefix/suffix support to model name
This commit is contained in:
commit
8a68a64609
4
.gitignore
vendored
4
.gitignore
vendored
@ -79,3 +79,7 @@ samples/client/petstore/swift/SwaggerClientTests/Pods/Pods.xcodeproj/xcshareddat
|
||||
samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/
|
||||
samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/
|
||||
**/.gradle/
|
||||
|
||||
samples/client/petstore/python/dev-requirements.txt.log
|
||||
samples/client/petstore/python/swagger_client.egg-info/SOURCES.txt
|
||||
samples/client/petstore/python/.coverage
|
||||
|
@ -187,7 +187,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
return type;
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -220,9 +220,13 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword
|
||||
if (isReservedWord(name)) {
|
||||
escapeReservedWord(name); // e.g. return => _return
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
|
||||
name = "object_" + name;
|
||||
}
|
||||
|
||||
// add prefix/suffic to model name
|
||||
name = modelNamePrefix + name + modelNameSuffix;
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
|
@ -370,6 +370,11 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
// add prefix and/or suffic only if name does not start wth \ (e.g. \DateTime)
|
||||
if (!name.matches("^\\\\.*")) {
|
||||
name = modelNamePrefix + name + modelNameSuffix;
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
|
@ -212,7 +212,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
name = sanitizeName(modelNamePrefix + name + modelNameSuffix); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
@ -236,6 +236,14 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
name = name + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
// underscore the model file name
|
||||
// PhoneNumber => phone_number
|
||||
return underscore(dropDots(name));
|
||||
|
@ -38,7 +38,8 @@ public class PhpModelTest {
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 3);
|
||||
Assert.assertEquals(cm.imports.size(), 1);
|
||||
// {{imports}} is not used in template
|
||||
//Assert.assertEquals(cm.imports.size(), 1);
|
||||
|
||||
final CodegenProperty property1 = cm.vars.get(0);
|
||||
Assert.assertEquals(property1.baseName, "id");
|
||||
@ -198,7 +199,8 @@ public class PhpModelTest {
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 1);
|
||||
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
|
||||
// {{imports}} is not used in template
|
||||
//Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
|
||||
|
||||
final CodegenProperty property1 = cm.vars.get(0);
|
||||
Assert.assertEquals(property1.baseName, "children");
|
||||
@ -239,8 +241,9 @@ public class PhpModelTest {
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a map model");
|
||||
Assert.assertEquals(cm.vars.size(), 0);
|
||||
Assert.assertEquals(cm.imports.size(), 2);
|
||||
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
|
||||
// {{imports}} is not used in template
|
||||
//Assert.assertEquals(cm.imports.size(), 2);
|
||||
//Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
|
||||
}
|
||||
|
||||
@DataProvider(name = "modelNames")
|
||||
|
@ -8,7 +8,7 @@ WWW::SwaggerClient::Role - a Moose role for the Swagger Petstore
|
||||
|
||||
Automatically generated by the Perl Swagger Codegen project:
|
||||
|
||||
- Build date: 2016-02-24T21:56:00.847+08:00
|
||||
- Build date: 2016-02-27T21:43:00.005+08:00
|
||||
- Build package: class io.swagger.codegen.languages.PerlClientCodegen
|
||||
- Codegen version:
|
||||
|
||||
|
@ -574,7 +574,7 @@ sub delete_pet {
|
||||
#
|
||||
# @param int $pet_id ID of pet to update (required)
|
||||
# @param string $additional_metadata Additional data to pass to server (optional)
|
||||
# @param file $file file to upload (optional)
|
||||
# @param File $file file to upload (optional)
|
||||
{
|
||||
my $params = {
|
||||
'pet_id' => {
|
||||
@ -588,7 +588,7 @@ sub delete_pet {
|
||||
required => '0',
|
||||
},
|
||||
'file' => {
|
||||
data_type => 'file',
|
||||
data_type => 'File',
|
||||
description => 'file to upload',
|
||||
required => '0',
|
||||
},
|
||||
@ -667,10 +667,10 @@ sub upload_file {
|
||||
#
|
||||
# Fake endpoint to test byte array return by 'Find pet by ID'
|
||||
#
|
||||
# @param int $package ID of pet that needs to be fetched (required)
|
||||
# @param int $pet_id ID of pet that needs to be fetched (required)
|
||||
{
|
||||
my $params = {
|
||||
'package' => {
|
||||
'pet_id' => {
|
||||
data_type => 'int',
|
||||
description => 'ID of pet that needs to be fetched',
|
||||
required => '1',
|
||||
@ -688,9 +688,9 @@ sub pet_pet_idtesting_byte_arraytrue_get {
|
||||
my ($self, %args) = @_;
|
||||
|
||||
|
||||
# verify the required parameter 'package' is set
|
||||
unless (exists $args{'package'}) {
|
||||
croak("Missing the required parameter 'package' when calling pet_pet_idtesting_byte_arraytrue_get");
|
||||
# verify the required parameter 'pet_id' is set
|
||||
unless (exists $args{'pet_id'}) {
|
||||
croak("Missing the required parameter 'pet_id' when calling pet_pet_idtesting_byte_arraytrue_get");
|
||||
}
|
||||
|
||||
|
||||
@ -713,9 +713,9 @@ sub pet_pet_idtesting_byte_arraytrue_get {
|
||||
|
||||
|
||||
# path params
|
||||
if ( exists $args{'package'}) {
|
||||
my $_base_variable = "{" . "package" . "}";
|
||||
my $_base_value = $self->{api_client}->to_path_value($args{'package'});
|
||||
if ( exists $args{'pet_id'}) {
|
||||
my $_base_variable = "{" . "petId" . "}";
|
||||
my $_base_value = $self->{api_client}->to_path_value($args{'pet_id'});
|
||||
$_resource_path =~ s/$_base_variable/$_base_value/g;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ has version_info => ( is => 'ro',
|
||||
default => sub { {
|
||||
app_name => 'Swagger Petstore',
|
||||
app_version => '1.0.0',
|
||||
generated_date => '2016-02-24T21:56:00.847+08:00',
|
||||
generated_date => '2016-02-27T21:43:00.005+08:00',
|
||||
generator_class => 'class io.swagger.codegen.languages.PerlClientCodegen',
|
||||
} },
|
||||
documentation => 'Information about the application version and the codegen codebase version'
|
||||
@ -103,7 +103,7 @@ Automatically generated by the Perl Swagger Codegen project:
|
||||
|
||||
=over 4
|
||||
|
||||
=item Build date: 2016-02-24T21:56:00.847+08:00
|
||||
=item Build date: 2016-02-27T21:43:00.005+08:00
|
||||
|
||||
=item Build package: class io.swagger.codegen.languages.PerlClientCodegen
|
||||
|
||||
|
@ -102,8 +102,8 @@ isa_ok($api, 'WWW::SwaggerClient::PetApi');
|
||||
# pet_pet_idtesting_byte_arraytrue_get test
|
||||
#
|
||||
{
|
||||
my $package = undef; # replace NULL with a proper value
|
||||
my $result = $api->pet_pet_idtesting_byte_arraytrue_get(package => $package);
|
||||
my $pet_id = undef; # replace NULL with a proper value
|
||||
my $result = $api->pet_pet_idtesting_byte_arraytrue_get(pet_id => $pet_id);
|
||||
}
|
||||
|
||||
#
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,4 +0,0 @@
|
||||
nose
|
||||
tox
|
||||
coverage
|
||||
randomize
|
@ -1,22 +0,0 @@
|
||||
Collecting nose (from -r dev-requirements.txt (line 1))
|
||||
Using cached nose-1.3.7-py2-none-any.whl
|
||||
Collecting tox (from -r dev-requirements.txt (line 2))
|
||||
Using cached tox-2.3.1-py2.py3-none-any.whl
|
||||
Collecting coverage (from -r dev-requirements.txt (line 3))
|
||||
Collecting randomize (from -r dev-requirements.txt (line 4))
|
||||
Using cached randomize-0.13-py2.py3-none-any.whl
|
||||
Collecting virtualenv>=1.11.2 (from tox->-r dev-requirements.txt (line 2))
|
||||
Downloading virtualenv-14.0.6-py2.py3-none-any.whl (1.8MB)
|
||||
Collecting py>=1.4.17 (from tox->-r dev-requirements.txt (line 2))
|
||||
Using cached py-1.4.31-py2.py3-none-any.whl
|
||||
Collecting pluggy<0.4.0,>=0.3.0 (from tox->-r dev-requirements.txt (line 2))
|
||||
Using cached pluggy-0.3.1-py2.py3-none-any.whl
|
||||
Installing collected packages: nose, virtualenv, py, pluggy, tox, coverage, randomize
|
||||
Successfully installed coverage-4.0.3 nose-1.3.7 pluggy-0.3.1 py-1.4.31 randomize-0.13 tox-2.3.1 virtualenv-14.0.6
|
||||
Requirement already satisfied (use --upgrade to upgrade): nose in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 1))
|
||||
Requirement already satisfied (use --upgrade to upgrade): tox in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 2))
|
||||
Requirement already satisfied (use --upgrade to upgrade): coverage in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 3))
|
||||
Requirement already satisfied (use --upgrade to upgrade): randomize in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 4))
|
||||
Requirement already satisfied (use --upgrade to upgrade): virtualenv>=1.11.2 in ./venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
|
||||
Requirement already satisfied (use --upgrade to upgrade): py>=1.4.17 in ./venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
|
||||
Requirement already satisfied (use --upgrade to upgrade): pluggy<0.4.0,>=0.3.0 in ./venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
|
@ -1,29 +0,0 @@
|
||||
setup.cfg
|
||||
setup.py
|
||||
swagger_client/__init__.py
|
||||
swagger_client/api_client.py
|
||||
swagger_client/configuration.py
|
||||
swagger_client/rest.py
|
||||
swagger_client.egg-info/PKG-INFO
|
||||
swagger_client.egg-info/SOURCES.txt
|
||||
swagger_client.egg-info/dependency_links.txt
|
||||
swagger_client.egg-info/requires.txt
|
||||
swagger_client.egg-info/top_level.txt
|
||||
swagger_client/apis/__init__.py
|
||||
swagger_client/apis/pet_api.py
|
||||
swagger_client/apis/store_api.py
|
||||
swagger_client/apis/user_api.py
|
||||
swagger_client/models/__init__.py
|
||||
swagger_client/models/category.py
|
||||
swagger_client/models/order.py
|
||||
swagger_client/models/pet.py
|
||||
swagger_client/models/tag.py
|
||||
swagger_client/models/user.py
|
||||
tests/__init__.py
|
||||
tests/test_api_client.py
|
||||
tests/test_api_exception.py
|
||||
tests/test_deserialization.py
|
||||
tests/test_order_model.py
|
||||
tests/test_pet_api.py
|
||||
tests/test_pet_model.py
|
||||
tests/test_store_api.py
|
Loading…
Reference in New Issue
Block a user