Skip to content

Commit a152609

Browse files
authored
Add multiple inheritance support to Perl client (OpenAPITools#1681)
* add multiple inheritance support to perl client * remove allof test from fake petstore
1 parent ff716dd commit a152609

File tree

98 files changed

+8207
-5101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+8207
-5101
lines changed

bin/openapi3/perl-petstore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ fi
2828
# if you've executed sbt assembly previously it will use that instead.
2929
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
3030
# complex module name used for testing
31-
ags="generate -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g perl -o samples/client/petstore/perl -DhideGenerationTimestamp=true $@"
31+
ags="generate -t modules/openapi-generator/src/main/resources/perl -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g perl -o samples/client/petstore/perl -DhideGenerationTimestamp=true $@"
3232

3333
java $JAVA_OPTS -jar $executable $ags

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
5353
public PerlClientCodegen() {
5454
super();
5555

56+
// add multiple inheritance support (beta)
57+
supportsMultipleInheritance = true;
58+
5659
// clear import mapping (from default generator) as perl does not use it
5760
// at the moment
5861
importMapping.clear();

modules/openapi-generator/src/main/resources/perl/BaseObject.mustache

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,44 @@ __PACKAGE__->mk_classdata('openapi_types' => {});
99
__PACKAGE__->mk_classdata('method_documentation' => {});
1010
__PACKAGE__->mk_classdata('class_documentation' => {});
1111

12-
# new object
12+
# new plain object
1313
sub new {
1414
my ($class, %args) = @_;
1515
1616
my $self = bless {}, $class;
17+
18+
$self->init(%args);
1719

18-
foreach my $attribute (keys %{$class->attribute_map}) {
19-
my $args_key = $class->attribute_map->{$attribute};
20+
return $self;
21+
}
22+
23+
# initialize the object
24+
sub init
25+
{
26+
my ($self, %args) = @_;
27+
28+
foreach my $attribute (keys %{$self->attribute_map}) {
29+
my $args_key = $self->attribute_map->{$attribute};
2030
$self->$attribute( $args{ $args_key } );
2131
}
22-
23-
return $self;
24-
}
32+
{{#allParents}}
33+
34+
# initialize parent object {{{.}}}
35+
$self->{{moduleName}}::Object::{{{.}}}::init(%args);
36+
{{/allParents}}
37+
}
2538

2639
# return perl hash
2740
sub to_hash {
28-
return decode_json(JSON->new->convert_blessed->encode( shift ));
41+
my $self = shift;
42+
my $_hash = decode_json(JSON->new->convert_blessed->encode($self));
43+
{{#allParents}}
44+
45+
# call {{{.}}} to_hash and then combine hash
46+
$_hash = { %$_hash, %$self->{{moduleName}}::Object::{{{.}}}::to_hash };
47+
{{/allParents}}
48+
49+
return $_hash;
2950
}
3051

3152
# used by JSON for serialization
@@ -37,6 +58,12 @@ sub TO_JSON {
3758
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
3859
}
3960
}
61+
{{#allParents}}
62+
63+
# combine parent ({{{.}}}) TO_JSON
64+
$_data = { %$_data, %$self->{{moduleName}}::Object::{{{.}}}::TO_JSON };
65+
{{/allParents}}
66+
4067
return $_data;
4168
}
4269

@@ -60,6 +87,11 @@ sub from_hash {
6087
$log->debugf("Warning: %s (%s) does not exist in input hash\n", $_key, $_json_attribute);
6188
}
6289
}
90+
{{#allParents}}
91+
92+
# call parent ({{{.}}}) from_hash
93+
$self->{{moduleName}}::Object::{{{.}}}::from_hash($hash);
94+
{{/allParents}}
6395

6496
return $self;
6597
}

modules/openapi-generator/src/main/resources/perl/object.mustache

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use DateTime;
2323
use {{moduleName}}::Object::{{.}};
2424
{{/imports}}
2525

26-
use base ("Class::Accessor", "Class::Data::Inheritable");
27-
26+
use base ("Class::Accessor", "Class::Data::Inheritable"{{#allParents}}, "{{moduleName}}::Object::{{{.}}}"{{/allParents}});
2827

2928
#
3029
#{{description}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.3.0-SNAPSHOT
1+
4.0.0-SNAPSHOT

samples/client/petstore/perl/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ To load the models:
234234
```perl
235235
use WWW::OpenAPIClient::Object::AdditionalPropertiesClass;
236236
use WWW::OpenAPIClient::Object::Animal;
237-
use WWW::OpenAPIClient::Object::AnimalFarm;
238237
use WWW::OpenAPIClient::Object::ApiResponse;
239238
use WWW::OpenAPIClient::Object::ArrayOfArrayOfNumberOnly;
240239
use WWW::OpenAPIClient::Object::ArrayOfNumberOnly;
@@ -265,7 +264,6 @@ use WWW::OpenAPIClient::Object::OuterEnum;
265264
use WWW::OpenAPIClient::Object::Pet;
266265
use WWW::OpenAPIClient::Object::ReadOnlyFirst;
267266
use WWW::OpenAPIClient::Object::SpecialModelName;
268-
use WWW::OpenAPIClient::Object::StringBooleanMap;
269267
use WWW::OpenAPIClient::Object::Tag;
270268
use WWW::OpenAPIClient::Object::User;
271269

@@ -289,7 +287,6 @@ use WWW::OpenAPIClient::UserApi;
289287
# load the models
290288
use WWW::OpenAPIClient::Object::AdditionalPropertiesClass;
291289
use WWW::OpenAPIClient::Object::Animal;
292-
use WWW::OpenAPIClient::Object::AnimalFarm;
293290
use WWW::OpenAPIClient::Object::ApiResponse;
294291
use WWW::OpenAPIClient::Object::ArrayOfArrayOfNumberOnly;
295292
use WWW::OpenAPIClient::Object::ArrayOfNumberOnly;
@@ -320,7 +317,6 @@ use WWW::OpenAPIClient::Object::OuterEnum;
320317
use WWW::OpenAPIClient::Object::Pet;
321318
use WWW::OpenAPIClient::Object::ReadOnlyFirst;
322319
use WWW::OpenAPIClient::Object::SpecialModelName;
323-
use WWW::OpenAPIClient::Object::StringBooleanMap;
324320
use WWW::OpenAPIClient::Object::Tag;
325321
use WWW::OpenAPIClient::Object::User;
326322
@@ -359,6 +355,7 @@ Class | Method | HTTP request | Description
359355
*FakeApi* | [**test_client_model**](docs/FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
360356
*FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
361357
*FakeApi* | [**test_enum_parameters**](docs/FakeApi.md#test_enum_parameters) | **GET** /fake | To test enum parameters
358+
*FakeApi* | [**test_group_parameters**](docs/FakeApi.md#test_group_parameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
362359
*FakeApi* | [**test_inline_additional_properties**](docs/FakeApi.md#test_inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
363360
*FakeApi* | [**test_json_form_data**](docs/FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data
364361
*FakeClassnameTags123Api* | [**test_classname**](docs/FakeClassnameTags123Api.md#test_classname) | **PATCH** /fake_classname_test | To test class name in snake case
@@ -388,7 +385,6 @@ Class | Method | HTTP request | Description
388385
# DOCUMENTATION FOR MODELS
389386
- [WWW::OpenAPIClient::Object::AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
390387
- [WWW::OpenAPIClient::Object::Animal](docs/Animal.md)
391-
- [WWW::OpenAPIClient::Object::AnimalFarm](docs/AnimalFarm.md)
392388
- [WWW::OpenAPIClient::Object::ApiResponse](docs/ApiResponse.md)
393389
- [WWW::OpenAPIClient::Object::ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
394390
- [WWW::OpenAPIClient::Object::ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
@@ -419,7 +415,6 @@ Class | Method | HTTP request | Description
419415
- [WWW::OpenAPIClient::Object::Pet](docs/Pet.md)
420416
- [WWW::OpenAPIClient::Object::ReadOnlyFirst](docs/ReadOnlyFirst.md)
421417
- [WWW::OpenAPIClient::Object::SpecialModelName](docs/SpecialModelName.md)
422-
- [WWW::OpenAPIClient::Object::StringBooleanMap](docs/StringBooleanMap.md)
423418
- [WWW::OpenAPIClient::Object::Tag](docs/Tag.md)
424419
- [WWW::OpenAPIClient::Object::User](docs/User.md)
425420

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# WWW::OpenAPIClient::Object::Adult
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::Adult;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**duplicated_optional** | **int** | | [optional]
12+
**duplicated_required** | **int** | |
13+
**children** | [**ARRAY[Child]**](Child.md) | | [optional]
14+
**adult_required** | **boolean** | | [optional]
15+
16+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
17+
18+

samples/client/petstore/perl/docs/Cat.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use WWW::OpenAPIClient::Object::Cat;
88
## Properties
99
Name | Type | Description | Notes
1010
------------ | ------------- | ------------- | -------------
11-
**class_name** | **string** | |
12-
**color** | **string** | | [optional] [default to 'red']
1311
**declawed** | **boolean** | | [optional]
1412

1513
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

samples/client/petstore/perl/docs/Category.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use WWW::OpenAPIClient::Object::Category;
99
Name | Type | Description | Notes
1010
------------ | ------------- | ------------- | -------------
1111
**id** | **int** | | [optional]
12-
**name** | **string** | | [optional]
12+
**name** | **string** | | [default to 'default-name']
1313

1414
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1515

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# WWW::OpenAPIClient::Object::Child
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::Child;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**age** | **int** | | [optional]
12+
**first_name** | **string** | | [optional]
13+
14+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
15+
16+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# WWW::OpenAPIClient::DefaultApi
2+
3+
## Load the API package
4+
```perl
5+
use WWW::OpenAPIClient::Object::DefaultApi;
6+
```
7+
8+
All URIs are relative to *http://petstore.swagger.io:80/v2*
9+
10+
Method | HTTP request | Description
11+
------------- | ------------- | -------------
12+
[**foo_get**](DefaultApi.md#foo_get) | **GET** /foo |
13+
14+
15+
# **foo_get**
16+
> InlineResponseDefault foo_get()
17+
18+
19+
20+
### Example
21+
```perl
22+
use Data::Dumper;
23+
use WWW::OpenAPIClient::DefaultApi;
24+
my $api_instance = WWW::OpenAPIClient::DefaultApi->new(
25+
);
26+
27+
28+
eval {
29+
my $result = $api_instance->foo_get();
30+
print Dumper($result);
31+
};
32+
if ($@) {
33+
warn "Exception when calling DefaultApi->foo_get: $@\n";
34+
}
35+
```
36+
37+
### Parameters
38+
This endpoint does not need any parameter.
39+
40+
### Return type
41+
42+
[**InlineResponseDefault**](InlineResponseDefault.md)
43+
44+
### Authorization
45+
46+
No authorization required
47+
48+
### HTTP request headers
49+
50+
- **Content-Type**: Not defined
51+
- **Accept**: application/json
52+
53+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
54+

samples/client/petstore/perl/docs/Dog.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use WWW::OpenAPIClient::Object::Dog;
88
## Properties
99
Name | Type | Description | Notes
1010
------------ | ------------- | ------------- | -------------
11-
**class_name** | **string** | |
12-
**color** | **string** | | [optional] [default to 'red']
1311
**breed** | **string** | | [optional]
1412

1513
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

samples/client/petstore/perl/docs/FakeApi.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Method | HTTP request | Description
1818
[**test_client_model**](FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
1919
[**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
2020
[**test_enum_parameters**](FakeApi.md#test_enum_parameters) | **GET** /fake | To test enum parameters
21+
[**test_group_parameters**](FakeApi.md#test_group_parameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
2122
[**test_inline_additional_properties**](FakeApi.md#test_inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
2223
[**test_json_form_data**](FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data
2324

@@ -476,6 +477,61 @@ No authorization required
476477

477478
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
478479

480+
# **test_group_parameters**
481+
> test_group_parameters(required_string_group => $required_string_group, required_boolean_group => $required_boolean_group, required_int64_group => $required_int64_group, string_group => $string_group, boolean_group => $boolean_group, int64_group => $int64_group)
482+
483+
Fake endpoint to test group parameters (optional)
484+
485+
Fake endpoint to test group parameters (optional)
486+
487+
### Example
488+
```perl
489+
use Data::Dumper;
490+
use WWW::OpenAPIClient::FakeApi;
491+
my $api_instance = WWW::OpenAPIClient::FakeApi->new(
492+
);
493+
494+
my $required_string_group = 56; # int | Required String in group parameters
495+
my $required_boolean_group = null; # boolean | Required Boolean in group parameters
496+
my $required_int64_group = 789; # int | Required Integer in group parameters
497+
my $string_group = 56; # int | String in group parameters
498+
my $boolean_group = null; # boolean | Boolean in group parameters
499+
my $int64_group = 789; # int | Integer in group parameters
500+
501+
eval {
502+
$api_instance->test_group_parameters(required_string_group => $required_string_group, required_boolean_group => $required_boolean_group, required_int64_group => $required_int64_group, string_group => $string_group, boolean_group => $boolean_group, int64_group => $int64_group);
503+
};
504+
if ($@) {
505+
warn "Exception when calling FakeApi->test_group_parameters: $@\n";
506+
}
507+
```
508+
509+
### Parameters
510+
511+
Name | Type | Description | Notes
512+
------------- | ------------- | ------------- | -------------
513+
**required_string_group** | **int**| Required String in group parameters |
514+
**required_boolean_group** | **boolean**| Required Boolean in group parameters |
515+
**required_int64_group** | **int**| Required Integer in group parameters |
516+
**string_group** | **int**| String in group parameters | [optional]
517+
**boolean_group** | **boolean**| Boolean in group parameters | [optional]
518+
**int64_group** | **int**| Integer in group parameters | [optional]
519+
520+
### Return type
521+
522+
void (empty response body)
523+
524+
### Authorization
525+
526+
No authorization required
527+
528+
### HTTP request headers
529+
530+
- **Content-Type**: Not defined
531+
- **Accept**: Not defined
532+
533+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
534+
479535
# **test_inline_additional_properties**
480536
> test_inline_additional_properties(request_body => $request_body)
481537
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WWW::OpenAPIClient::Object::Foo
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::Foo;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**bar** | **string** | | [optional] [default to 'bar']
12+
13+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
14+
15+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# WWW::OpenAPIClient::Object::Human
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::Human;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**___type** | **string** | | [optional]
12+
**body** | **string** | |
13+
14+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
15+
16+

0 commit comments

Comments
 (0)