Skip to content

Commit

Permalink
[Bash] Minor improvements (#4274)
Browse files Browse the repository at this point in the history
* minor improvements to bash generator

* test bash

* fix path

* test bash in travis

* fix pom
  • Loading branch information
wing328 authored Oct 26, 2019
1 parent 66be33a commit d5b09cf
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ before_install:
- docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore
- docker ps -a
# Add bats test framework and cURL for Bash script integration tests
#- sudo add-apt-repository ppa:duggan/bats --yes
#- sudo apt-get update -qq
#- sudo apt-get install -qq bats
#- sudo apt-get install -qq curl
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
- sudo apt-get install -qq bats
- sudo apt-get install -qq curl
# install dart
#- sudo apt-get update
#- sudo apt-get install apt-transport-https
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/";

protected static int emptyMethodNameCounter = 0;

public static final String CURL_OPTIONS = "curlOptions";
public static final String PROCESS_MARKDOWN = "processMarkdown";
public static final String SCRIPT_NAME = "scriptName";
Expand Down Expand Up @@ -99,6 +101,26 @@ public String getHelp() {
public BashClientCodegen() {
super();

setReservedWordsLowerCase(
Arrays.asList(
"case",
"do",
"done",
"elif",
"else",
"esac",
"fi",
"for",
"function",
"if",
"in",
"select",
"then",
"until",
"while"
)
);

/**
* Set the output folder here
*/
Expand Down Expand Up @@ -411,9 +433,9 @@ public String getSchemaType(Schema p) {

/**
* Convert OpenAPI Parameter object to Codegen Parameter object
*
* @param imports set of imports for library/package/module
* @param param OpenAPI parameter object
*
* @return Codegen Parameter object
*/
@Override
Expand Down Expand Up @@ -749,5 +771,29 @@ public String toModelFilename(String name) {
return camelize(name);
}

@Override
public String toOperationId(String operationId) {
// rename to empty_method_name_1 (e.g.) if method name is empty
if (StringUtils.isEmpty(operationId)) {
operationId = camelize("empty_method_name_" + emptyMethodNameCounter++, true);
LOGGER.warn("Empty method name (operationId) found. Renamed to " + operationId);
return operationId;
}

// method name cannot use reserved keyword, e.g. return
if (isReservedWord(operationId)) {
String newOperationId = underscore("call" + camelize(operationId));
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId;
}

// operationId starts with a number
if (operationId.matches("^\\d.*")) {
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId;
}

return camelize(sanitizeName(operationId), true);
}

}
14 changes: 1 addition & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@
<modules>
<module>samples/server/petstore/python-aiohttp</module>
<!-- clients -->
<module>samples/client/petstore/bash</module>
<module>samples/client/petstore/c</module>
<module>samples/client/petstore/cpp-qt5</module>
<module>samples/client/petstore/elm-0.18</module>
Expand Down Expand Up @@ -1072,7 +1073,6 @@
<module>samples/client/petstore/typescript-angular-v4.3/npm</module>
<module>samples/client/petstore/typescript-angular-v6-provided-in-root</module>
<module>samples/client/petstore/typescript-angular-v7-provided-in-root</module>
<!--<module>samples/client/petstore/bash</module>-->
<module>samples/server/petstore/rust-server</module>
<module>samples/server/petstore/python-flask</module>
<module>samples/server/petstore/python-flask-python2</module>
Expand Down Expand Up @@ -1311,18 +1311,6 @@
<module>samples/client/petstore/objc/core-data/SwaggerClientTests</module>-->
</modules>
</profile>
<profile>
<id>samples.bash</id>
<activation>
<property>
<name>env</name>
<value>samples.bash</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/bash</module>
</modules>
</profile>
</profiles>
<modules>
<module>modules/openapi-generator-core</module>
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/bash/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0-SNAPSHOT
4.2.0-SNAPSHOT
3 changes: 2 additions & 1 deletion samples/client/petstore/bash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ All URIs are relative to */v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AnotherFakeApi* | [**123Test@$%SpecialTags**](docs/AnotherFakeApi.md#123test@$%specialtags) | **PATCH** /another-fake/dummy | To test special tags
*AnotherFakeApi* | [**call123TestSpecialTags**](docs/AnotherFakeApi.md#call123testspecialtags) | **PATCH** /another-fake/dummy | To test special tags
*FakeApi* | [**createXmlItem**](docs/FakeApi.md#createxmlitem) | **POST** /fake/create_xml_item | creates an XmlItem
*FakeApi* | [**fakeOuterBooleanSerialize**](docs/FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean |
*FakeApi* | [**fakeOuterCompositeSerialize**](docs/FakeApi.md#fakeoutercompositeserialize) | **POST** /fake/outer/composite |
Expand All @@ -117,6 +117,7 @@ Class | Method | HTTP request | Description
*FakeApi* | [**testGroupParameters**](docs/FakeApi.md#testgroupparameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
*FakeApi* | [**testInlineAdditionalProperties**](docs/FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
*FakeApi* | [**testJsonFormData**](docs/FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data
*FakeApi* | [**testQueryParameterCollectionFormat**](docs/FakeApi.md#testqueryparametercollectionformat) | **PUT** /fake/test-query-paramters |
*FakeClassnameTags123Api* | [**testClassname**](docs/FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case
*PetApi* | [**addPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**deletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
Expand Down
18 changes: 15 additions & 3 deletions samples/client/petstore/bash/_petstore-cli
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ case $state in
ops)
# Operations
_values "Operations" \
"123Test@$%SpecialTags[To test special tags]" "createXmlItem[creates an XmlItem]" \
"call123TestSpecialTags[To test special tags]" "createXmlItem[creates an XmlItem]" \
"fakeOuterBooleanSerialize[]" \
"fakeOuterCompositeSerialize[]" \
"fakeOuterNumberSerialize[]" \
Expand All @@ -311,7 +311,8 @@ case $state in
"testEnumParameters[To test enum parameters]" \
"testGroupParameters[Fake endpoint to test group parameters (optional)]" \
"testInlineAdditionalProperties[test inline additionalProperties]" \
"testJsonFormData[test json serialization of form data]" "testClassname[To test class name in snake case]" "addPet[Add a new pet to the store]" \
"testJsonFormData[test json serialization of form data]" \
"testQueryParameterCollectionFormat[]" "testClassname[To test class name in snake case]" "addPet[Add a new pet to the store]" \
"deletePet[Deletes a pet]" \
"findPetsByStatus[Finds Pets by status]" \
"findPetsByTags[Finds Pets by tags]" \
Expand All @@ -336,7 +337,7 @@ case $state in
;;
args)
case $line[1] in
123Test@$%SpecialTags)
call123TestSpecialTags)
local -a _op_arguments
_op_arguments=(
)
Expand Down Expand Up @@ -433,6 +434,17 @@ case $state in
)
_describe -t actions 'operations' _op_arguments -S '' && ret=0
;;
testQueryParameterCollectionFormat)
local -a _op_arguments
_op_arguments=(
"pipe=:[QUERY] "
"ioutil=:[QUERY] "
"http=:[QUERY] "
"url=:[QUERY] "
"context=:[QUERY] "
)
_describe -t actions 'operations' _op_arguments -S '' && ret=0
;;
testClassname)
local -a _op_arguments
_op_arguments=(
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/bash/docs/AnotherFakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ All URIs are relative to */v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**123Test@$%SpecialTags**](AnotherFakeApi.md#123Test@$%SpecialTags) | **PATCH** /another-fake/dummy | To test special tags
[**call123TestSpecialTags**](AnotherFakeApi.md#call123TestSpecialTags) | **PATCH** /another-fake/dummy | To test special tags



## 123Test@$%SpecialTags
## call123TestSpecialTags

To test special tags

Expand All @@ -17,7 +17,7 @@ To test special tags and operation ID starting with number
### Example

```bash
petstore-cli 123Test@$%SpecialTags
petstore-cli call123TestSpecialTags
```

### Parameters
Expand Down
40 changes: 40 additions & 0 deletions samples/client/petstore/bash/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Method | HTTP request | Description
[**testGroupParameters**](FakeApi.md#testGroupParameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
[**testInlineAdditionalProperties**](FakeApi.md#testInlineAdditionalProperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
[**testJsonFormData**](FakeApi.md#testJsonFormData) | **GET** /fake/jsonFormData | test json serialization of form data
[**testQueryParameterCollectionFormat**](FakeApi.md#testQueryParameterCollectionFormat) | **PUT** /fake/test-query-paramters |



Expand Down Expand Up @@ -504,3 +505,42 @@ 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)


## testQueryParameterCollectionFormat



To test the collection format in query parameters

### Example

```bash
petstore-cli testQueryParameterCollectionFormat Specify as: pipe="value1,value2,..." Specify as: ioutil="value1,value2,..." Specify as: Specify as: url="value1,value2,..." Specify as: context=value1 context=value2 context=...
```

### Parameters


Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pipe** | [**array[string]**](string.md) | | [default to null]
**ioutil** | [**array[string]**](string.md) | | [default to null]
**http** | [**array[string]**](string.md) | | [default to null]
**url** | [**array[string]**](string.md) | | [default to null]
**context** | [**array[string]**](string.md) | | [default to null]

### Return type

(empty response body)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not Applicable
- **Accept**: Not Applicable

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

1 change: 1 addition & 0 deletions samples/client/petstore/bash/docs/FormatTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Name | Type | Description | Notes
**dateTime** | **string** | | [optional] [default to null]
**uuid** | **string** | | [optional] [default to null]
**password** | **string** | | [default to null]
**BigDecimal** | [**BigDecimal**](BigDecimal.md) | | [optional] [default to null]

[[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
4 changes: 2 additions & 2 deletions samples/client/petstore/bash/docs/HasOnlyReadOnly.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**bar** | **string** | | [optional] [default to null]
**foo** | **string** | | [optional] [default to null]
**bar** | **string** | | [optional] [readonly] [default to null]
**foo** | **string** | | [optional] [readonly] [default to null]

[[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
4 changes: 2 additions & 2 deletions samples/client/petstore/bash/docs/Name.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **integer** | | [default to null]
**snakeUnderscorecase** | **integer** | | [optional] [default to null]
**snakeUnderscorecase** | **integer** | | [optional] [readonly] [default to null]
**property** | **string** | | [optional] [default to null]
**123Number** | **integer** | | [optional] [default to null]
**123Number** | **integer** | | [optional] [readonly] [default to null]

[[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
2 changes: 1 addition & 1 deletion samples/client/petstore/bash/docs/ReadOnlyFirst.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**bar** | **string** | | [optional] [default to null]
**bar** | **string** | | [optional] [readonly] [default to null]
**baz** | **string** | | [optional] [default to null]

[[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
1 change: 1 addition & 0 deletions samples/client/petstore/bash/docs/TypeHolderExample.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**stringUnderscoreitem** | **string** | | [default to null]
**numberUnderscoreitem** | **integer** | | [default to null]
**floatUnderscoreitem** | **float** | | [default to null]
**integerUnderscoreitem** | **integer** | | [default to null]
**boolUnderscoreitem** | **boolean** | | [default to null]
**arrayUnderscoreitem** | **array[integer]** | | [default to null]
Expand Down
Loading

0 comments on commit d5b09cf

Please # to comment.