[perl] Add name mapping features to the Perl client generator (#16510)

* add name mapping features to perl client generator

* update samples
This commit is contained in:
William Cheng 2023-09-05 18:39:38 +08:00 committed by GitHub
parent 29f0d22713
commit a9301a6c16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 20 deletions

View File

@ -4,3 +4,7 @@ inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-e
templateDir: modules/openapi-generator/src/main/resources/perl
additionalProperties:
hideGenerationTimestamp: "true"
nameMappings:
NullableMessage: system_message
modelNameMappings:
DeprecatedObject: DeprecatedModel

View File

@ -317,6 +317,11 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String toVarName(String name) {
// obtain the name from nameMapping directly if provided
if (nameMapping.containsKey(name)) {
return nameMapping.get(name);
}
// return the name in underscore style
// PhoneNumber => phone_number
name = underscore(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
@ -331,12 +336,22 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String toParamName(String name) {
// obtain the name from parameterNameMapping directly if provided
if (parameterNameMapping.containsKey(name)) {
return parameterNameMapping.get(name);
}
// should be the same as variable name
return toVarName(name);
}
@Override
public String toModelName(String name) {
// obtain the name from modelNameMapping directly if provided
if (modelNameMapping.containsKey(name)) {
return modelNameMapping.get(name);
}
// We need to check if schema-mapping has a different model for this class, so we use it
// instead of the auto-generated one.
if (schemaMapping.containsKey(name)) {

View File

@ -16,7 +16,7 @@ docs/Category.md
docs/ClassModel.md
docs/Client.md
docs/DefaultApi.md
docs/DeprecatedObject.md
docs/DeprecatedModel.md
docs/Dog.md
docs/EnumArrays.md
docs/EnumClass.md
@ -76,7 +76,7 @@ lib/WWW/OpenAPIClient/Object/Cat.pm
lib/WWW/OpenAPIClient/Object/Category.pm
lib/WWW/OpenAPIClient/Object/ClassModel.pm
lib/WWW/OpenAPIClient/Object/Client.pm
lib/WWW/OpenAPIClient/Object/DeprecatedObject.pm
lib/WWW/OpenAPIClient/Object/DeprecatedModel.pm
lib/WWW/OpenAPIClient/Object/Dog.pm
lib/WWW/OpenAPIClient/Object/EnumArrays.pm
lib/WWW/OpenAPIClient/Object/EnumClass.pm

View File

@ -254,7 +254,7 @@ use WWW::OpenAPIClient::Object::Cat;
use WWW::OpenAPIClient::Object::Category;
use WWW::OpenAPIClient::Object::ClassModel;
use WWW::OpenAPIClient::Object::Client;
use WWW::OpenAPIClient::Object::DeprecatedObject;
use WWW::OpenAPIClient::Object::DeprecatedModel;
use WWW::OpenAPIClient::Object::Dog;
use WWW::OpenAPIClient::Object::EnumArrays;
use WWW::OpenAPIClient::Object::EnumClass;
@ -321,7 +321,7 @@ use WWW::OpenAPIClient::Object::Cat;
use WWW::OpenAPIClient::Object::Category;
use WWW::OpenAPIClient::Object::ClassModel;
use WWW::OpenAPIClient::Object::Client;
use WWW::OpenAPIClient::Object::DeprecatedObject;
use WWW::OpenAPIClient::Object::DeprecatedModel;
use WWW::OpenAPIClient::Object::Dog;
use WWW::OpenAPIClient::Object::EnumArrays;
use WWW::OpenAPIClient::Object::EnumClass;
@ -439,7 +439,7 @@ Class | Method | HTTP request | Description
- [WWW::OpenAPIClient::Object::Category](docs/Category.md)
- [WWW::OpenAPIClient::Object::ClassModel](docs/ClassModel.md)
- [WWW::OpenAPIClient::Object::Client](docs/Client.md)
- [WWW::OpenAPIClient::Object::DeprecatedObject](docs/DeprecatedObject.md)
- [WWW::OpenAPIClient::Object::DeprecatedModel](docs/DeprecatedModel.md)
- [WWW::OpenAPIClient::Object::Dog](docs/Dog.md)
- [WWW::OpenAPIClient::Object::EnumArrays](docs/EnumArrays.md)
- [WWW::OpenAPIClient::Object::EnumClass](docs/EnumClass.md)

View File

@ -1,8 +1,8 @@
# WWW::OpenAPIClient::Object::DeprecatedObject
# WWW::OpenAPIClient::Object::DeprecatedModel
## Load the model package
```perl
use WWW::OpenAPIClient::Object::DeprecatedObject;
use WWW::OpenAPIClient::Object::DeprecatedModel;
```
## Properties

View File

@ -8,7 +8,7 @@ use WWW::OpenAPIClient::Object::HealthCheckResult;
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**nullable_message** | **string** | | [optional]
**system_message** | **string** | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -10,7 +10,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**uuid** | **string** | | [optional]
**id** | **double** | | [optional]
**deprecated_ref** | [**DeprecatedObject**](DeprecatedObject.md) | | [optional]
**deprecated_ref** | [**DeprecatedModel**](DeprecatedModel.md) | | [optional]
**bars** | **ARRAY[string]** | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -17,7 +17,7 @@ Generated by: https://openapi-generator.tech
# Do not edit the class manually.
# Ref: https://openapi-generator.tech
#
package WWW::OpenAPIClient::Object::DeprecatedObject;
package WWW::OpenAPIClient::Object::DeprecatedModel;
require 5.6.0;
use strict;
@ -214,7 +214,7 @@ sub _deserialize {
__PACKAGE__->class_documentation({description => '',
class => 'DeprecatedObject',
class => 'DeprecatedModel',
required => [], # TODO
} );

View File

@ -219,7 +219,7 @@ __PACKAGE__->class_documentation({description => 'Just a string to inform instan
} );
__PACKAGE__->method_documentation({
'nullable_message' => {
'system_message' => {
datatype => 'string',
base_name => 'NullableMessage',
description => '',
@ -229,11 +229,11 @@ __PACKAGE__->method_documentation({
});
__PACKAGE__->openapi_types( {
'nullable_message' => 'string'
'system_message' => 'string'
} );
__PACKAGE__->attribute_map( {
'nullable_message' => 'NullableMessage'
'system_message' => 'NullableMessage'
} );
__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});

View File

@ -30,7 +30,7 @@ use Log::Any qw($log);
use Date::Parse;
use DateTime;
use WWW::OpenAPIClient::Object::DeprecatedObject;
use WWW::OpenAPIClient::Object::DeprecatedModel;
use base ("Class::Accessor", "Class::Data::Inheritable");
@ -235,7 +235,7 @@ __PACKAGE__->method_documentation({
read_only => '',
},
'deprecated_ref' => {
datatype => 'DeprecatedObject',
datatype => 'DeprecatedModel',
base_name => 'deprecatedRef',
description => '',
format => '',
@ -253,7 +253,7 @@ __PACKAGE__->method_documentation({
__PACKAGE__->openapi_types( {
'uuid' => 'string',
'id' => 'double',
'deprecated_ref' => 'DeprecatedObject',
'deprecated_ref' => 'DeprecatedModel',
'bars' => 'ARRAY[string]'
} );

View File

@ -25,10 +25,10 @@ use strict;
use warnings;
use_ok('WWW::OpenAPIClient::Object::DeprecatedObject');
use_ok('WWW::OpenAPIClient::Object::DeprecatedModel');
# uncomment below and update the test
#my $instance = WWW::OpenAPIClient::Object::DeprecatedObject->new();
#my $instance = WWW::OpenAPIClient::Object::DeprecatedModel->new();
#
#isa_ok($instance, 'WWW::OpenAPIClient::Object::DeprecatedObject');
#isa_ok($instance, 'WWW::OpenAPIClient::Object::DeprecatedModel');