Skip to content

Commit 06fdc92

Browse files
yue9944882wing328
authored andcommitted
Bugfix(Perl): Support nested primitive types in ARRARY or HASH for basic object (#2713)
* support nested primitive types in ARRARY or HASH for basic object * run bin/perl-petstore.sh and bin/openapi3/{LANG}-petstore.sh
1 parent a4be2c0 commit 06fdc92

File tree

106 files changed

+4906
-550
lines changed

Some content is hidden

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

106 files changed

+4906
-550
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,20 @@ sub from_hash {
7474
# loop through attributes and use openapi_types to deserialize the data
7575
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
7676
my $_json_attribute = $self->attribute_map->{$_key};
77-
if ($_type =~ /^array\[/i) { # array
78-
my $_subclass = substr($_type, 6, -1);
77+
if ($_type =~ /^array\[(.+)\]$/i) { # array
78+
my $_subclass = $1;
7979
my @_array = ();
8080
foreach my $_element (@{$hash->{$_json_attribute}}) {
8181
push @_array, $self->_deserialize($_subclass, $_element);
8282
}
8383
$self->{$_key} = \@_array;
84+
} elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
85+
my $_subclass = $1;
86+
my %_hash = ();
87+
while (my($_key, $_element) = each %{$hash->{$_json_attribute}}) {
88+
$_hash{$_key} = $self->_deserialize($_subclass, $_element);
89+
}
90+
$self->{$_key} = \%_hash;
8491
} elsif (exists $hash->{$_json_attribute}) { #hash(model), primitive, datetime
8592
$self->{$_key} = $self->_deserialize($_type, $hash->{$_json_attribute});
8693
} else {
@@ -100,7 +107,7 @@ sub from_hash {
100107
sub _deserialize {
101108
my ($self, $type, $data) = @_;
102109
$log->debugf("deserializing %s with %s",Dumper($data), $type);
103-
110+
104111
if ($type eq 'DateTime') {
105112
return DateTime->from_epoch(epoch => str2time($data));
106113
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {

samples/client/petstore/perl/README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ Each of these calls returns a hashref with various useful pieces of information.
222222
To load the API packages:
223223
```perl
224224
use WWW::OpenAPIClient::AnotherFakeApi;
225+
use WWW::OpenAPIClient::DefaultApi;
225226
use WWW::OpenAPIClient::FakeApi;
226227
use WWW::OpenAPIClient::FakeClassnameTags123Api;
227228
use WWW::OpenAPIClient::PetApi;
@@ -249,18 +250,31 @@ use WWW::OpenAPIClient::Object::EnumClass;
249250
use WWW::OpenAPIClient::Object::EnumTest;
250251
use WWW::OpenAPIClient::Object::File;
251252
use WWW::OpenAPIClient::Object::FileSchemaTestClass;
253+
use WWW::OpenAPIClient::Object::Foo;
252254
use WWW::OpenAPIClient::Object::FormatTest;
253255
use WWW::OpenAPIClient::Object::HasOnlyReadOnly;
256+
use WWW::OpenAPIClient::Object::HealthCheckResult;
257+
use WWW::OpenAPIClient::Object::InlineObject;
258+
use WWW::OpenAPIClient::Object::InlineObject1;
259+
use WWW::OpenAPIClient::Object::InlineObject2;
260+
use WWW::OpenAPIClient::Object::InlineObject3;
261+
use WWW::OpenAPIClient::Object::InlineObject4;
262+
use WWW::OpenAPIClient::Object::InlineObject5;
263+
use WWW::OpenAPIClient::Object::InlineResponseDefault;
254264
use WWW::OpenAPIClient::Object::List;
255265
use WWW::OpenAPIClient::Object::MapTest;
256266
use WWW::OpenAPIClient::Object::MixedPropertiesAndAdditionalPropertiesClass;
257267
use WWW::OpenAPIClient::Object::Model200Response;
258268
use WWW::OpenAPIClient::Object::ModelReturn;
259269
use WWW::OpenAPIClient::Object::Name;
270+
use WWW::OpenAPIClient::Object::NullableClass;
260271
use WWW::OpenAPIClient::Object::NumberOnly;
261272
use WWW::OpenAPIClient::Object::Order;
262273
use WWW::OpenAPIClient::Object::OuterComposite;
263274
use WWW::OpenAPIClient::Object::OuterEnum;
275+
use WWW::OpenAPIClient::Object::OuterEnumDefaultValue;
276+
use WWW::OpenAPIClient::Object::OuterEnumInteger;
277+
use WWW::OpenAPIClient::Object::OuterEnumIntegerDefaultValue;
264278
use WWW::OpenAPIClient::Object::Pet;
265279
use WWW::OpenAPIClient::Object::ReadOnlyFirst;
266280
use WWW::OpenAPIClient::Object::SpecialModelName;
@@ -278,6 +292,7 @@ use strict;
278292
use warnings;
279293
# load the API package
280294
use WWW::OpenAPIClient::AnotherFakeApi;
295+
use WWW::OpenAPIClient::DefaultApi;
281296
use WWW::OpenAPIClient::FakeApi;
282297
use WWW::OpenAPIClient::FakeClassnameTags123Api;
283298
use WWW::OpenAPIClient::PetApi;
@@ -302,18 +317,31 @@ use WWW::OpenAPIClient::Object::EnumClass;
302317
use WWW::OpenAPIClient::Object::EnumTest;
303318
use WWW::OpenAPIClient::Object::File;
304319
use WWW::OpenAPIClient::Object::FileSchemaTestClass;
320+
use WWW::OpenAPIClient::Object::Foo;
305321
use WWW::OpenAPIClient::Object::FormatTest;
306322
use WWW::OpenAPIClient::Object::HasOnlyReadOnly;
323+
use WWW::OpenAPIClient::Object::HealthCheckResult;
324+
use WWW::OpenAPIClient::Object::InlineObject;
325+
use WWW::OpenAPIClient::Object::InlineObject1;
326+
use WWW::OpenAPIClient::Object::InlineObject2;
327+
use WWW::OpenAPIClient::Object::InlineObject3;
328+
use WWW::OpenAPIClient::Object::InlineObject4;
329+
use WWW::OpenAPIClient::Object::InlineObject5;
330+
use WWW::OpenAPIClient::Object::InlineResponseDefault;
307331
use WWW::OpenAPIClient::Object::List;
308332
use WWW::OpenAPIClient::Object::MapTest;
309333
use WWW::OpenAPIClient::Object::MixedPropertiesAndAdditionalPropertiesClass;
310334
use WWW::OpenAPIClient::Object::Model200Response;
311335
use WWW::OpenAPIClient::Object::ModelReturn;
312336
use WWW::OpenAPIClient::Object::Name;
337+
use WWW::OpenAPIClient::Object::NullableClass;
313338
use WWW::OpenAPIClient::Object::NumberOnly;
314339
use WWW::OpenAPIClient::Object::Order;
315340
use WWW::OpenAPIClient::Object::OuterComposite;
316341
use WWW::OpenAPIClient::Object::OuterEnum;
342+
use WWW::OpenAPIClient::Object::OuterEnumDefaultValue;
343+
use WWW::OpenAPIClient::Object::OuterEnumInteger;
344+
use WWW::OpenAPIClient::Object::OuterEnumIntegerDefaultValue;
317345
use WWW::OpenAPIClient::Object::Pet;
318346
use WWW::OpenAPIClient::Object::ReadOnlyFirst;
319347
use WWW::OpenAPIClient::Object::SpecialModelName;
@@ -327,10 +355,10 @@ use WWW::OpenAPIClient::;
327355
my $api_instance = WWW::OpenAPIClient::->new(
328356
);
329357
330-
my $body = WWW::OpenAPIClient::Object::Client->new(); # Client | client model
358+
my $client = WWW::OpenAPIClient::Object::Client->new(); # Client | client model
331359
332360
eval {
333-
my $result = $api_instance->call_123_test_special_tags(body => $body);
361+
my $result = $api_instance->call_123_test_special_tags(client => $client);
334362
print Dumper($result);
335363
};
336364
if ($@) {
@@ -346,6 +374,8 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
346374
Class | Method | HTTP request | Description
347375
------------ | ------------- | ------------- | -------------
348376
*AnotherFakeApi* | [**call_123_test_special_tags**](docs/AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
377+
*DefaultApi* | [**foo_get**](docs/DefaultApi.md#foo_get) | **GET** /foo |
378+
*FakeApi* | [**fake_health_get**](docs/FakeApi.md#fake_health_get) | **GET** /fake/health | Health check endpoint
349379
*FakeApi* | [**fake_outer_boolean_serialize**](docs/FakeApi.md#fake_outer_boolean_serialize) | **POST** /fake/outer/boolean |
350380
*FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
351381
*FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |
@@ -400,18 +430,31 @@ Class | Method | HTTP request | Description
400430
- [WWW::OpenAPIClient::Object::EnumTest](docs/EnumTest.md)
401431
- [WWW::OpenAPIClient::Object::File](docs/File.md)
402432
- [WWW::OpenAPIClient::Object::FileSchemaTestClass](docs/FileSchemaTestClass.md)
433+
- [WWW::OpenAPIClient::Object::Foo](docs/Foo.md)
403434
- [WWW::OpenAPIClient::Object::FormatTest](docs/FormatTest.md)
404435
- [WWW::OpenAPIClient::Object::HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
436+
- [WWW::OpenAPIClient::Object::HealthCheckResult](docs/HealthCheckResult.md)
437+
- [WWW::OpenAPIClient::Object::InlineObject](docs/InlineObject.md)
438+
- [WWW::OpenAPIClient::Object::InlineObject1](docs/InlineObject1.md)
439+
- [WWW::OpenAPIClient::Object::InlineObject2](docs/InlineObject2.md)
440+
- [WWW::OpenAPIClient::Object::InlineObject3](docs/InlineObject3.md)
441+
- [WWW::OpenAPIClient::Object::InlineObject4](docs/InlineObject4.md)
442+
- [WWW::OpenAPIClient::Object::InlineObject5](docs/InlineObject5.md)
443+
- [WWW::OpenAPIClient::Object::InlineResponseDefault](docs/InlineResponseDefault.md)
405444
- [WWW::OpenAPIClient::Object::List](docs/List.md)
406445
- [WWW::OpenAPIClient::Object::MapTest](docs/MapTest.md)
407446
- [WWW::OpenAPIClient::Object::MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
408447
- [WWW::OpenAPIClient::Object::Model200Response](docs/Model200Response.md)
409448
- [WWW::OpenAPIClient::Object::ModelReturn](docs/ModelReturn.md)
410449
- [WWW::OpenAPIClient::Object::Name](docs/Name.md)
450+
- [WWW::OpenAPIClient::Object::NullableClass](docs/NullableClass.md)
411451
- [WWW::OpenAPIClient::Object::NumberOnly](docs/NumberOnly.md)
412452
- [WWW::OpenAPIClient::Object::Order](docs/Order.md)
413453
- [WWW::OpenAPIClient::Object::OuterComposite](docs/OuterComposite.md)
414454
- [WWW::OpenAPIClient::Object::OuterEnum](docs/OuterEnum.md)
455+
- [WWW::OpenAPIClient::Object::OuterEnumDefaultValue](docs/OuterEnumDefaultValue.md)
456+
- [WWW::OpenAPIClient::Object::OuterEnumInteger](docs/OuterEnumInteger.md)
457+
- [WWW::OpenAPIClient::Object::OuterEnumIntegerDefaultValue](docs/OuterEnumIntegerDefaultValue.md)
415458
- [WWW::OpenAPIClient::Object::Pet](docs/Pet.md)
416459
- [WWW::OpenAPIClient::Object::ReadOnlyFirst](docs/ReadOnlyFirst.md)
417460
- [WWW::OpenAPIClient::Object::SpecialModelName](docs/SpecialModelName.md)
@@ -433,6 +476,10 @@ Class | Method | HTTP request | Description
433476
- **API key parameter name**: api_key_query
434477
- **Location**: URL query string
435478

479+
## bearer_test
480+
481+
- **Type**: HTTP basic authentication
482+
436483
## http_basic_test
437484

438485
- **Type**: HTTP basic authentication
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WWW::OpenAPIClient::Object::AdditionalPropertiesAnyType
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::AdditionalPropertiesAnyType;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**name** | **string** | | [optional]
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WWW::OpenAPIClient::Object::AdditionalPropertiesArray
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::AdditionalPropertiesArray;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**name** | **string** | | [optional]
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WWW::OpenAPIClient::Object::AdditionalPropertiesBoolean
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::AdditionalPropertiesBoolean;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**name** | **string** | | [optional]
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WWW::OpenAPIClient::Object::AdditionalPropertiesInteger
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::AdditionalPropertiesInteger;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**name** | **string** | | [optional]
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WWW::OpenAPIClient::Object::AdditionalPropertiesNumber
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::AdditionalPropertiesNumber;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**name** | **string** | | [optional]
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WWW::OpenAPIClient::Object::AdditionalPropertiesObject
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::AdditionalPropertiesObject;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**name** | **string** | | [optional]
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WWW::OpenAPIClient::Object::AdditionalPropertiesString
2+
3+
## Load the model package
4+
```perl
5+
use WWW::OpenAPIClient::Object::AdditionalPropertiesString;
6+
```
7+
8+
## Properties
9+
Name | Type | Description | Notes
10+
------------ | ------------- | ------------- | -------------
11+
**name** | **string** | | [optional]
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+

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Method | HTTP request | Description
1313

1414

1515
# **call_123_test_special_tags**
16-
> Client call_123_test_special_tags(body => $body)
16+
> Client call_123_test_special_tags(client => $client)
1717
1818
To test special tags
1919

@@ -26,10 +26,10 @@ use WWW::OpenAPIClient::AnotherFakeApi;
2626
my $api_instance = WWW::OpenAPIClient::AnotherFakeApi->new(
2727
);
2828

29-
my $body = WWW::OpenAPIClient::Object::Client->new(); # Client | client model
29+
my $client = WWW::OpenAPIClient::Object::Client->new(); # Client | client model
3030

3131
eval {
32-
my $result = $api_instance->call_123_test_special_tags(body => $body);
32+
my $result = $api_instance->call_123_test_special_tags(client => $client);
3333
print Dumper($result);
3434
};
3535
if ($@) {
@@ -41,7 +41,7 @@ if ($@) {
4141

4242
Name | Type | Description | Notes
4343
------------- | ------------- | ------------- | -------------
44-
**body** | [**Client**](Client.md)| client model |
44+
**client** | [**Client**](Client.md)| client model |
4545

4646
### Return type
4747

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Name | Type | Description | Notes
1313
**enum_integer** | **int** | | [optional]
1414
**enum_number** | **double** | | [optional]
1515
**outer_enum** | [**OuterEnum**](OuterEnum.md) | | [optional]
16+
**outer_enum_integer** | [**OuterEnumInteger**](OuterEnumInteger.md) | | [optional]
17+
**outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional]
18+
**outer_enum_integer_default_value** | [**OuterEnumIntegerDefaultValue**](OuterEnumIntegerDefaultValue.md) | | [optional]
1619

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

0 commit comments

Comments
 (0)