Skip to content

Commit

Permalink
Add perltidy to format Perl code (OpenAPITools#970)
Browse files Browse the repository at this point in the history
* add perl tidy without updating petstore samples

* incldue pl file, update samples

* use no backup option, perltidy on test.pl
  • Loading branch information
wing328 authored Sep 6, 2018
1 parent 13329eb commit f464fac
Show file tree
Hide file tree
Showing 62 changed files with 6,044 additions and 4,288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.regex.Matcher;

import org.apache.commons.lang3.StringUtils;

import org.apache.commons.io.FilenameUtils;

public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(PerlClientCodegen.class);
Expand Down Expand Up @@ -133,6 +133,10 @@ public PerlClientCodegen() {
public void processOpts() {
super.processOpts();

if (StringUtils.isEmpty(System.getenv("PERLTIDY_PATH"))) {
LOGGER.info("Environment variable PERLTIDY_PATH not defined so the Perl code may not be properly formatted. To define it, try 'export PERLTIDY_PATH=/usr/local/bin/perltidy' (Linux/Mac)");
}

if (additionalProperties.containsKey(MODULE_VERSION)) {
setModuleVersion((String) additionalProperties.get(MODULE_VERSION));
} else {
Expand Down Expand Up @@ -560,4 +564,33 @@ public String escapeUnsafeCharacters(String input) {
// remove =end, =cut to avoid code injection
return input.replace("=begin", "=_begin").replace("=end", "=_end").replace("=cut", "=_cut").replace("=pod", "=_pod");
}

@Override
public void postProcessFile(File file, String fileType) {
if (file == null) {
return;
}

String perlTidyPath = System.getenv("PERLTIDY_PATH");
if (StringUtils.isEmpty(perlTidyPath)) {
return; // skip if PERLTIDY_PATH env variable is not defined
}

// only process files with .t, .pm extension
if ("t".equals(FilenameUtils.getExtension(file.toString())) ||
"pm".equals(FilenameUtils.getExtension(file.toString())) ||
"pl".equals(FilenameUtils.getExtension(file.toString()))) {
String command = perlTidyPath + " -b -bext='/' " + file.toString();
try {
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
if (p.exitValue() != 0) {
LOGGER.error("Error running the command ({}): {}", command, p.exitValue());
}
} catch (Exception e) {
LOGGER.error("Error running the command ({}): {}", command, e.getMessage());
}
LOGGER.info("Successfully executed: " + command);
}
}
}
2 changes: 1 addition & 1 deletion samples/client/petstore/perl/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0-SNAPSHOT
3.3.0-SNAPSHOT
17 changes: 14 additions & 3 deletions samples/client/petstore/perl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ use WWW::OpenAPIClient::Object::Dog;
use WWW::OpenAPIClient::Object::EnumArrays;
use WWW::OpenAPIClient::Object::EnumClass;
use WWW::OpenAPIClient::Object::EnumTest;
use WWW::OpenAPIClient::Object::File;
use WWW::OpenAPIClient::Object::FileSchemaTestClass;
use WWW::OpenAPIClient::Object::FormatTest;
use WWW::OpenAPIClient::Object::HasOnlyReadOnly;
use WWW::OpenAPIClient::Object::List;
Expand All @@ -263,6 +265,7 @@ use WWW::OpenAPIClient::Object::OuterEnum;
use WWW::OpenAPIClient::Object::Pet;
use WWW::OpenAPIClient::Object::ReadOnlyFirst;
use WWW::OpenAPIClient::Object::SpecialModelName;
use WWW::OpenAPIClient::Object::StringBooleanMap;
use WWW::OpenAPIClient::Object::Tag;
use WWW::OpenAPIClient::Object::User;

Expand Down Expand Up @@ -300,6 +303,8 @@ use WWW::OpenAPIClient::Object::Dog;
use WWW::OpenAPIClient::Object::EnumArrays;
use WWW::OpenAPIClient::Object::EnumClass;
use WWW::OpenAPIClient::Object::EnumTest;
use WWW::OpenAPIClient::Object::File;
use WWW::OpenAPIClient::Object::FileSchemaTestClass;
use WWW::OpenAPIClient::Object::FormatTest;
use WWW::OpenAPIClient::Object::HasOnlyReadOnly;
use WWW::OpenAPIClient::Object::List;
Expand All @@ -315,6 +320,7 @@ use WWW::OpenAPIClient::Object::OuterEnum;
use WWW::OpenAPIClient::Object::Pet;
use WWW::OpenAPIClient::Object::ReadOnlyFirst;
use WWW::OpenAPIClient::Object::SpecialModelName;
use WWW::OpenAPIClient::Object::StringBooleanMap;
use WWW::OpenAPIClient::Object::Tag;
use WWW::OpenAPIClient::Object::User;
Expand All @@ -328,11 +334,11 @@ my $api_instance = WWW::OpenAPIClient::->new(
my $client = WWW::OpenAPIClient::Object::Client->new(); # Client | client model
eval {
my $result = $api_instance->test_special_tags(client => $client);
my $result = $api_instance->call_123_test_special_tags(client => $client);
print Dumper($result);
};
if ($@) {
warn "Exception when calling AnotherFakeApi->test_special_tags: $@\n";
warn "Exception when calling AnotherFakeApi->call_123_test_special_tags: $@\n";
}
```
Expand All @@ -343,11 +349,12 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AnotherFakeApi* | [**test_special_tags**](docs/AnotherFakeApi.md#test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
*AnotherFakeApi* | [**call_123_test_special_tags**](docs/AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
*FakeApi* | [**fake_outer_boolean_serialize**](docs/FakeApi.md#fake_outer_boolean_serialize) | **POST** /fake/outer/boolean |
*FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
*FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |
*FakeApi* | [**fake_outer_string_serialize**](docs/FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string |
*FakeApi* | [**test_body_with_file_schema**](docs/FakeApi.md#test_body_with_file_schema) | **PUT** /fake/body-with-file-schema |
*FakeApi* | [**test_body_with_query_params**](docs/FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params |
*FakeApi* | [**test_client_model**](docs/FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
*FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
Expand All @@ -363,6 +370,7 @@ Class | Method | HTTP request | Description
*PetApi* | [**update_pet**](docs/PetApi.md#update_pet) | **PUT** /pet | Update an existing pet
*PetApi* | [**update_pet_with_form**](docs/PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**upload_file**](docs/PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image
*PetApi* | [**upload_file_with_required_file**](docs/PetApi.md#upload_file_with_required_file) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required)
*StoreApi* | [**delete_order**](docs/StoreApi.md#delete_order) | **DELETE** /store/order/{order_id} | Delete purchase order by ID
*StoreApi* | [**get_inventory**](docs/StoreApi.md#get_inventory) | **GET** /store/inventory | Returns pet inventories by status
*StoreApi* | [**get_order_by_id**](docs/StoreApi.md#get_order_by_id) | **GET** /store/order/{order_id} | Find purchase order by ID
Expand Down Expand Up @@ -394,6 +402,8 @@ Class | Method | HTTP request | Description
- [WWW::OpenAPIClient::Object::EnumArrays](docs/EnumArrays.md)
- [WWW::OpenAPIClient::Object::EnumClass](docs/EnumClass.md)
- [WWW::OpenAPIClient::Object::EnumTest](docs/EnumTest.md)
- [WWW::OpenAPIClient::Object::File](docs/File.md)
- [WWW::OpenAPIClient::Object::FileSchemaTestClass](docs/FileSchemaTestClass.md)
- [WWW::OpenAPIClient::Object::FormatTest](docs/FormatTest.md)
- [WWW::OpenAPIClient::Object::HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
- [WWW::OpenAPIClient::Object::List](docs/List.md)
Expand All @@ -409,6 +419,7 @@ Class | Method | HTTP request | Description
- [WWW::OpenAPIClient::Object::Pet](docs/Pet.md)
- [WWW::OpenAPIClient::Object::ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [WWW::OpenAPIClient::Object::SpecialModelName](docs/SpecialModelName.md)
- [WWW::OpenAPIClient::Object::StringBooleanMap](docs/StringBooleanMap.md)
- [WWW::OpenAPIClient::Object::Tag](docs/Tag.md)
- [WWW::OpenAPIClient::Object::User](docs/User.md)

Expand Down
12 changes: 6 additions & 6 deletions samples/client/petstore/perl/docs/AnotherfakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**test_special_tags**](AnotherFakeApi.md#test_special_tags) | **PATCH** /another-fake/dummy | To test special tags
[**call_123_test_special_tags**](AnotherFakeApi.md#call_123_test_special_tags) | **PATCH** /another-fake/dummy | To test special tags


# **test_special_tags**
> Client test_special_tags(client => $client)
# **call_123_test_special_tags**
> Client call_123_test_special_tags(client => $client)
To test special tags

To test special tags
To test special tags and operation ID starting with number

### Example
```perl
Expand All @@ -29,11 +29,11 @@ my $api_instance = WWW::OpenAPIClient::AnotherFakeApi->new(
my $client = WWW::OpenAPIClient::Object::Client->new(); # Client | client model

eval {
my $result = $api_instance->test_special_tags(client => $client);
my $result = $api_instance->call_123_test_special_tags(client => $client);
print Dumper($result);
};
if ($@) {
warn "Exception when calling AnotherFakeApi->test_special_tags: $@\n";
warn "Exception when calling AnotherFakeApi->call_123_test_special_tags: $@\n";
}
```

Expand Down
48 changes: 47 additions & 1 deletion samples/client/petstore/perl/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Method | HTTP request | Description
[**fake_outer_composite_serialize**](FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
[**fake_outer_number_serialize**](FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |
[**fake_outer_string_serialize**](FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string |
[**test_body_with_file_schema**](FakeApi.md#test_body_with_file_schema) | **PUT** /fake/body-with-file-schema |
[**test_body_with_query_params**](FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params |
[**test_client_model**](FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
[**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
Expand Down Expand Up @@ -205,6 +206,51 @@ No authorization required

[[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)

# **test_body_with_file_schema**
> test_body_with_file_schema(file_schema_test_class => $file_schema_test_class)


For this test, the body for this request much reference a schema named `File`.

### Example
```perl
use Data::Dumper;
use WWW::OpenAPIClient::FakeApi;
my $api_instance = WWW::OpenAPIClient::FakeApi->new(
);

my $file_schema_test_class = WWW::OpenAPIClient::Object::FileSchemaTestClass->new(); # FileSchemaTestClass |

eval {
$api_instance->test_body_with_file_schema(file_schema_test_class => $file_schema_test_class);
};
if ($@) {
warn "Exception when calling FakeApi->test_body_with_file_schema: $@\n";
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**file_schema_test_class** | [**FileSchemaTestClass**](FileSchemaTestClass.md)| |

### Return type

void (empty response body)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: Not defined

[[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)

# **test_body_with_query_params**
> test_body_with_query_params(query => $query, user => $user)
Expand Down Expand Up @@ -412,7 +458,7 @@ Name | Type | Description | Notes
**enum_query_string** | **string**| Query parameter enum test (string) | [optional] [default to '-efg']
**enum_query_integer** | **int**| Query parameter enum test (double) | [optional]
**enum_query_double** | **double**| Query parameter enum test (double) | [optional]
**enum_form_string_array** | **ARRAY[string]**| Form parameter enum test (string array) | [optional] [default to '$']
**enum_form_string_array** | [**ARRAY[string]**](string.md)| Form parameter enum test (string array) | [optional] [default to '$']
**enum_form_string** | **string**| Form parameter enum test (string) | [optional] [default to '-efg']

### Return type
Expand Down
15 changes: 15 additions & 0 deletions samples/client/petstore/perl/docs/File.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# WWW::OpenAPIClient::Object::File

## Load the model package
```perl
use WWW::OpenAPIClient::Object::File;
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**source_uri** | **string** | Test capitalization | [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)


16 changes: 16 additions & 0 deletions samples/client/petstore/perl/docs/FileSchemaTestClass.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# WWW::OpenAPIClient::Object::FileSchemaTestClass

## Load the model package
```perl
use WWW::OpenAPIClient::Object::FileSchemaTestClass;
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**file** | [**File**](File.md) | | [optional]
**files** | [**ARRAY[File]**](File.md) | | [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)


2 changes: 2 additions & 0 deletions samples/client/petstore/perl/docs/MapTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**map_map_of_string** | **HASH[string,HASH[string,string]]** | | [optional]
**map_of_enum_string** | **HASH[string,string]** | | [optional]
**direct_map** | **HASH[string,boolean]** | | [optional]
**indirect_map** | [**StringBooleanMap**](StringBooleanMap.md) | | [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)

Expand Down
52 changes: 52 additions & 0 deletions samples/client/petstore/perl/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Method | HTTP request | Description
[**update_pet**](PetApi.md#update_pet) | **PUT** /pet | Update an existing pet
[**update_pet_with_form**](PetApi.md#update_pet_with_form) | **POST** /pet/{petId} | Updates a pet in the store with form data
[**upload_file**](PetApi.md#upload_file) | **POST** /pet/{petId}/uploadImage | uploads an image
[**upload_file_with_required_file**](PetApi.md#upload_file_with_required_file) | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required)


# **add_pet**
Expand Down Expand Up @@ -409,3 +410,54 @@ Name | Type | Description | Notes

[[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)

# **upload_file_with_required_file**
> ApiResponse upload_file_with_required_file(pet_id => $pet_id, required_file => $required_file, additional_metadata => $additional_metadata)
uploads an image (required)

### Example
```perl
use Data::Dumper;
use WWW::OpenAPIClient::PetApi;
my $api_instance = WWW::OpenAPIClient::PetApi->new(

# Configure OAuth2 access token for authorization: petstore_auth
access_token => 'YOUR_ACCESS_TOKEN',
);

my $pet_id = 789; # int | ID of pet to update
my $required_file = "/path/to/file"; # string | file to upload
my $additional_metadata = "additional_metadata_example"; # string | Additional data to pass to server

eval {
my $result = $api_instance->upload_file_with_required_file(pet_id => $pet_id, required_file => $required_file, additional_metadata => $additional_metadata);
print Dumper($result);
};
if ($@) {
warn "Exception when calling PetApi->upload_file_with_required_file: $@\n";
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pet_id** | **int**| ID of pet to update |
**required_file** | **string****string**| file to upload |
**additional_metadata** | **string**| Additional data to pass to server | [optional]

### Return type

[**ApiResponse**](ApiResponse.md)

### Authorization

[petstore_auth](../README.md#petstore_auth)

### HTTP request headers

- **Content-Type**: multipart/form-data
- **Accept**: application/json

[[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)

14 changes: 14 additions & 0 deletions samples/client/petstore/perl/docs/StringBooleanMap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# WWW::OpenAPIClient::Object::StringBooleanMap

## Load the model package
```perl
use WWW::OpenAPIClient::Object::StringBooleanMap;
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

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


Loading

0 comments on commit f464fac

Please sign in to comment.