diff --git a/.travis.yml b/.travis.yml index 30ae30d2013f..2e034e8a7c8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/BashClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/BashClientCodegen.java index 94992fd9fcb4..7965641d64ea 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/BashClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/BashClientCodegen.java @@ -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"; @@ -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 */ @@ -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 @@ -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); + } } diff --git a/pom.xml b/pom.xml index cda456a5137f..bde63052fd45 100644 --- a/pom.xml +++ b/pom.xml @@ -1036,6 +1036,7 @@ samples/server/petstore/python-aiohttp + samples/client/petstore/bash samples/client/petstore/c samples/client/petstore/cpp-qt5 samples/client/petstore/elm-0.18 @@ -1072,7 +1073,6 @@ samples/client/petstore/typescript-angular-v4.3/npm samples/client/petstore/typescript-angular-v6-provided-in-root samples/client/petstore/typescript-angular-v7-provided-in-root - samples/server/petstore/rust-server samples/server/petstore/python-flask samples/server/petstore/python-flask-python2 @@ -1311,18 +1311,6 @@ samples/client/petstore/objc/core-data/SwaggerClientTests--> - - samples.bash - - - env - samples.bash - - - - samples/client/petstore/bash - - modules/openapi-generator-core diff --git a/samples/client/petstore/bash/.openapi-generator/VERSION b/samples/client/petstore/bash/.openapi-generator/VERSION index 83a328a9227e..c3a2c7076fa8 100644 --- a/samples/client/petstore/bash/.openapi-generator/VERSION +++ b/samples/client/petstore/bash/.openapi-generator/VERSION @@ -1 +1 @@ -4.1.0-SNAPSHOT \ No newline at end of file +4.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/bash/README.md b/samples/client/petstore/bash/README.md index 9e6a8c0dac3a..ddef97185091 100644 --- a/samples/client/petstore/bash/README.md +++ b/samples/client/petstore/bash/README.md @@ -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 | @@ -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 diff --git a/samples/client/petstore/bash/_petstore-cli b/samples/client/petstore/bash/_petstore-cli index 22d7eaf982d4..a4000b479d7c 100644 --- a/samples/client/petstore/bash/_petstore-cli +++ b/samples/client/petstore/bash/_petstore-cli @@ -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[]" \ @@ -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]" \ @@ -336,7 +337,7 @@ case $state in ;; args) case $line[1] in - 123Test@$%SpecialTags) + call123TestSpecialTags) local -a _op_arguments _op_arguments=( ) @@ -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=( diff --git a/samples/client/petstore/bash/docs/AnotherFakeApi.md b/samples/client/petstore/bash/docs/AnotherFakeApi.md index f93603717d2d..e17a9e75d006 100644 --- a/samples/client/petstore/bash/docs/AnotherFakeApi.md +++ b/samples/client/petstore/bash/docs/AnotherFakeApi.md @@ -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 @@ -17,7 +17,7 @@ To test special tags and operation ID starting with number ### Example ```bash -petstore-cli 123Test@$%SpecialTags +petstore-cli call123TestSpecialTags ``` ### Parameters diff --git a/samples/client/petstore/bash/docs/FakeApi.md b/samples/client/petstore/bash/docs/FakeApi.md index 0f9bf109d342..0b14173e0e61 100644 --- a/samples/client/petstore/bash/docs/FakeApi.md +++ b/samples/client/petstore/bash/docs/FakeApi.md @@ -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 | @@ -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) + diff --git a/samples/client/petstore/bash/docs/FormatTest.md b/samples/client/petstore/bash/docs/FormatTest.md index 8f73bb59bbcf..385631d820c8 100644 --- a/samples/client/petstore/bash/docs/FormatTest.md +++ b/samples/client/petstore/bash/docs/FormatTest.md @@ -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) diff --git a/samples/client/petstore/bash/docs/HasOnlyReadOnly.md b/samples/client/petstore/bash/docs/HasOnlyReadOnly.md index 136c1624714b..e16db1dba02b 100644 --- a/samples/client/petstore/bash/docs/HasOnlyReadOnly.md +++ b/samples/client/petstore/bash/docs/HasOnlyReadOnly.md @@ -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) diff --git a/samples/client/petstore/bash/docs/Name.md b/samples/client/petstore/bash/docs/Name.md index 5c3afc21594f..295812c7bb7e 100644 --- a/samples/client/petstore/bash/docs/Name.md +++ b/samples/client/petstore/bash/docs/Name.md @@ -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) diff --git a/samples/client/petstore/bash/docs/ReadOnlyFirst.md b/samples/client/petstore/bash/docs/ReadOnlyFirst.md index de713c7197b5..9b3b961012a9 100644 --- a/samples/client/petstore/bash/docs/ReadOnlyFirst.md +++ b/samples/client/petstore/bash/docs/ReadOnlyFirst.md @@ -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) diff --git a/samples/client/petstore/bash/docs/TypeHolderExample.md b/samples/client/petstore/bash/docs/TypeHolderExample.md index 411eda408703..b88e8707ed35 100644 --- a/samples/client/petstore/bash/docs/TypeHolderExample.md +++ b/samples/client/petstore/bash/docs/TypeHolderExample.md @@ -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] diff --git a/samples/client/petstore/bash/petstore-cli b/samples/client/petstore/bash/petstore-cli index dabf7c504858..17891dc77b4a 100755 --- a/samples/client/petstore/bash/petstore-cli +++ b/samples/client/petstore/bash/petstore-cli @@ -1,5 +1,4 @@ #!/usr/bin/env bash - # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # ! # ! Note: @@ -10,7 +9,6 @@ # ! # ! # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - # # This is a Bash client for OpenAPI Petstore. # @@ -95,7 +93,7 @@ declare -a result_color_table=( "$WHITE" "$WHITE" "$GREEN" "$YELLOW" "$WHITE" "$ # 0 - optional # 1 - required declare -A operation_parameters_minimum_occurrences -operation_parameters_minimum_occurrences["123Test@$%SpecialTags:::body"]=1 +operation_parameters_minimum_occurrences["call123TestSpecialTags:::body"]=1 operation_parameters_minimum_occurrences["createXmlItem:::XmlItem"]=1 operation_parameters_minimum_occurrences["fakeOuterBooleanSerialize:::body"]=0 operation_parameters_minimum_occurrences["fakeOuterCompositeSerialize:::body"]=0 @@ -136,6 +134,11 @@ operation_parameters_minimum_occurrences["testGroupParameters:::int64_group"]=0 operation_parameters_minimum_occurrences["testInlineAdditionalProperties:::param"]=1 operation_parameters_minimum_occurrences["testJsonFormData:::param"]=1 operation_parameters_minimum_occurrences["testJsonFormData:::param2"]=1 +operation_parameters_minimum_occurrences["testQueryParameterCollectionFormat:::pipe"]=1 +operation_parameters_minimum_occurrences["testQueryParameterCollectionFormat:::ioutil"]=1 +operation_parameters_minimum_occurrences["testQueryParameterCollectionFormat:::http"]=1 +operation_parameters_minimum_occurrences["testQueryParameterCollectionFormat:::url"]=1 +operation_parameters_minimum_occurrences["testQueryParameterCollectionFormat:::context"]=1 operation_parameters_minimum_occurrences["testClassname:::body"]=1 operation_parameters_minimum_occurrences["addPet:::body"]=1 operation_parameters_minimum_occurrences["deletePet:::petId"]=1 @@ -173,7 +176,7 @@ operation_parameters_minimum_occurrences["updateUser:::body"]=1 # N - N values # 0 - unlimited declare -A operation_parameters_maximum_occurrences -operation_parameters_maximum_occurrences["123Test@$%SpecialTags:::body"]=0 +operation_parameters_maximum_occurrences["call123TestSpecialTags:::body"]=0 operation_parameters_maximum_occurrences["createXmlItem:::XmlItem"]=0 operation_parameters_maximum_occurrences["fakeOuterBooleanSerialize:::body"]=0 operation_parameters_maximum_occurrences["fakeOuterCompositeSerialize:::body"]=0 @@ -214,6 +217,11 @@ operation_parameters_maximum_occurrences["testGroupParameters:::int64_group"]=0 operation_parameters_maximum_occurrences["testInlineAdditionalProperties:::param"]=0 operation_parameters_maximum_occurrences["testJsonFormData:::param"]=0 operation_parameters_maximum_occurrences["testJsonFormData:::param2"]=0 +operation_parameters_maximum_occurrences["testQueryParameterCollectionFormat:::pipe"]=0 +operation_parameters_maximum_occurrences["testQueryParameterCollectionFormat:::ioutil"]=0 +operation_parameters_maximum_occurrences["testQueryParameterCollectionFormat:::http"]=0 +operation_parameters_maximum_occurrences["testQueryParameterCollectionFormat:::url"]=0 +operation_parameters_maximum_occurrences["testQueryParameterCollectionFormat:::context"]=0 operation_parameters_maximum_occurrences["testClassname:::body"]=0 operation_parameters_maximum_occurrences["addPet:::body"]=0 operation_parameters_maximum_occurrences["deletePet:::petId"]=0 @@ -248,7 +256,7 @@ operation_parameters_maximum_occurrences["updateUser:::body"]=0 # The type of collection for specifying multiple values for parameter: # - multi, csv, ssv, tsv declare -A operation_parameters_collection_type -operation_parameters_collection_type["123Test@$%SpecialTags:::body"]="" +operation_parameters_collection_type["call123TestSpecialTags:::body"]="" operation_parameters_collection_type["createXmlItem:::XmlItem"]="" operation_parameters_collection_type["fakeOuterBooleanSerialize:::body"]="" operation_parameters_collection_type["fakeOuterCompositeSerialize:::body"]="" @@ -289,6 +297,11 @@ operation_parameters_collection_type["testGroupParameters:::int64_group"]="" operation_parameters_collection_type["testInlineAdditionalProperties:::param"]= operation_parameters_collection_type["testJsonFormData:::param"]="" operation_parameters_collection_type["testJsonFormData:::param2"]="" +operation_parameters_collection_type["testQueryParameterCollectionFormat:::pipe"]="csv" +operation_parameters_collection_type["testQueryParameterCollectionFormat:::ioutil"]="csv" +operation_parameters_collection_type["testQueryParameterCollectionFormat:::http"]= +operation_parameters_collection_type["testQueryParameterCollectionFormat:::url"]="csv" +operation_parameters_collection_type["testQueryParameterCollectionFormat:::context"]="multi" operation_parameters_collection_type["testClassname:::body"]="" operation_parameters_collection_type["addPet:::body"]="" operation_parameters_collection_type["deletePet:::petId"]="" @@ -721,7 +734,7 @@ EOF echo "" echo -e "${BOLD}${WHITE}[anotherFake]${OFF}" read -r -d '' ops <