From 5de338d7813a5ab8afb4f35d6eb1088dc5bda468 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 14 Oct 2016 17:49:43 +0800 Subject: [PATCH] [Python] fix `tags` with underscore for python (#3995) * fix tag with underscore for python * remove log --- .../languages/PythonClientCodegen.java | 8 +- ...ith-fake-endpoints-models-for-testing.yaml | 23 +++ samples/client/petstore/python/README.md | 1 + .../python/docs/FakeClassnameTags123Api.md | 55 ++++++ .../petstore/python/petstore_api/__init__.py | 1 + .../python/petstore_api/apis/__init__.py | 1 + .../apis/fake_classname_tags_123_api.py | 160 ++++++++++++++++++ .../test/test_fake_classname_tags_123_api.py | 55 ++++++ 8 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 samples/client/petstore/python/docs/FakeClassnameTags123Api.md create mode 100644 samples/client/petstore/python/petstore_api/apis/fake_classname_tags_123_api.py create mode 100644 samples/client/petstore/python/test/test_fake_classname_tags_123_api.py diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java index f0e9814fb12..9b07cd13101 100755 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java @@ -430,7 +430,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig // replace - with _ e.g. created-at => created_at name = name.replaceAll("-", "_"); - // e.g. PhoneNumberApi.rb => phone_number_api.rb + // e.g. PhoneNumberApi.py => phone_number_api.py return underscore(name) + "_api"; } @@ -608,6 +608,12 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig p.example = example; } + + @Override + public String sanitizeTag(String tag) { + return sanitizeName(tag); + } + @Override public String escapeQuotationMark(String input) { diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml index c42dc774a22..ea5714fd72f 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -560,6 +560,29 @@ paths: '404': description: User not found + /fake_classname_test: + patch: + tags: + - "fake_classname_tags 123#$%^" + summary: To test class name in snake case + descriptions: To test class name in snake case + operationId: testClassname + consumes: + - application/json + produces: + - application/json + parameters: + - in: body + name: body + description: client model + required: true + schema: + $ref: '#/definitions/Client' + responses: + '200': + description: successful operation + schema: + $ref: '#/definitions/Client' /fake: patch: tags: diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index 7b29cebd534..80bb8461ebe 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -72,6 +72,7 @@ Class | Method | HTTP request | Description *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 假端點 偽のエンドポイント 가짜 엔드 포인트 *FakeApi* | [**test_enum_parameters**](docs/FakeApi.md#test_enum_parameters) | **GET** /fake | To test enum parameters +*FakeClassnameTags123Api* | [**test_classname**](docs/FakeClassnameTags123Api.md#test_classname) | **PATCH** /fake_classname_test | To test class name in snake case *PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store *PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status diff --git a/samples/client/petstore/python/docs/FakeClassnameTags123Api.md b/samples/client/petstore/python/docs/FakeClassnameTags123Api.md new file mode 100644 index 00000000000..e51d67f902d --- /dev/null +++ b/samples/client/petstore/python/docs/FakeClassnameTags123Api.md @@ -0,0 +1,55 @@ +# petstore_api.FakeClassnameTags123Api + +All URIs are relative to *http://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**test_classname**](FakeClassnameTags123Api.md#test_classname) | **PATCH** /fake_classname_test | To test class name in snake case + + +# **test_classname** +> Client test_classname(body) + +To test class name in snake case + +### Example +```python +from __future__ import print_statement +import time +import petstore_api +from petstore_api.rest import ApiException +from pprint import pprint + +# create an instance of the API class +api_instance = petstore_api.FakeClassnameTags123Api() +body = petstore_api.Client() # Client | client model + +try: + # To test class name in snake case + api_response = api_instance.test_classname(body) + pprint(api_response) +except ApiException as e: + print("Exception when calling FakeClassnameTags123Api->test_classname: %s\n" % e) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**Client**](Client.md)| client model | + +### Return type + +[**Client**](Client.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **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) + diff --git a/samples/client/petstore/python/petstore_api/__init__.py b/samples/client/petstore/python/petstore_api/__init__.py index 8f043d8a1ad..ddc6fe66e9c 100644 --- a/samples/client/petstore/python/petstore_api/__init__.py +++ b/samples/client/petstore/python/petstore_api/__init__.py @@ -57,6 +57,7 @@ from .models.user import User # import apis into sdk package from .apis.fake_api import FakeApi +from .apis.fake_classname_tags_123_api import FakeClassnameTags123Api from .apis.pet_api import PetApi from .apis.store_api import StoreApi from .apis.user_api import UserApi diff --git a/samples/client/petstore/python/petstore_api/apis/__init__.py b/samples/client/petstore/python/petstore_api/apis/__init__.py index ddde8c164bf..af71d636229 100644 --- a/samples/client/petstore/python/petstore_api/apis/__init__.py +++ b/samples/client/petstore/python/petstore_api/apis/__init__.py @@ -2,6 +2,7 @@ from __future__ import absolute_import # import apis into api package from .fake_api import FakeApi +from .fake_classname_tags_123_api import FakeClassnameTags123Api from .pet_api import PetApi from .store_api import StoreApi from .user_api import UserApi diff --git a/samples/client/petstore/python/petstore_api/apis/fake_classname_tags_123_api.py b/samples/client/petstore/python/petstore_api/apis/fake_classname_tags_123_api.py new file mode 100644 index 00000000000..de8d248fb9e --- /dev/null +++ b/samples/client/petstore/python/petstore_api/apis/fake_classname_tags_123_api.py @@ -0,0 +1,160 @@ +# coding: utf-8 + +""" + Swagger Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 1.0.0 + Contact: apiteam@swagger.io + Generated by: https://github.com/swagger-api/swagger-codegen.git + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" + +from __future__ import absolute_import + +import sys +import os +import re + +# python 2 and python 3 compatibility library +from six import iteritems + +from ..configuration import Configuration +from ..api_client import ApiClient + + +class FakeClassnameTags123Api(object): + """ + NOTE: This class is auto generated by the swagger code generator program. + Do not edit the class manually. + Ref: https://github.com/swagger-api/swagger-codegen + """ + + def __init__(self, api_client=None): + config = Configuration() + if api_client: + self.api_client = api_client + else: + if not config.api_client: + config.api_client = ApiClient() + self.api_client = config.api_client + + def test_classname(self, body, **kwargs): + """ + To test class name in snake case + + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please define a `callback` function + to be invoked when receiving the response. + >>> def callback_function(response): + >>> pprint(response) + >>> + >>> thread = api.test_classname(body, callback=callback_function) + + :param callback function: The callback function + for asynchronous request. (optional) + :param Client body: client model (required) + :return: Client + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('callback'): + return self.test_classname_with_http_info(body, **kwargs) + else: + (data) = self.test_classname_with_http_info(body, **kwargs) + return data + + def test_classname_with_http_info(self, body, **kwargs): + """ + To test class name in snake case + + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please define a `callback` function + to be invoked when receiving the response. + >>> def callback_function(response): + >>> pprint(response) + >>> + >>> thread = api.test_classname_with_http_info(body, callback=callback_function) + + :param callback function: The callback function + for asynchronous request. (optional) + :param Client body: client model (required) + :return: Client + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['body'] + all_params.append('callback') + all_params.append('_return_http_data_only') + + params = locals() + for key, val in iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method test_classname" % key + ) + params[key] = val + del params['kwargs'] + # verify the required parameter 'body' is set + if ('body' not in params) or (params['body'] is None): + raise ValueError("Missing the required parameter `body` when calling `test_classname`") + + + collection_formats = {} + + resource_path = '/fake_classname_test'.replace('{format}', 'json') + path_params = {} + + query_params = {} + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + if 'body' in params: + body_params = params['body'] + + # HTTP header `Accept` + header_params['Accept'] = self.api_client.\ + select_header_accept(['application/json']) + if not header_params['Accept']: + del header_params['Accept'] + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.\ + select_header_content_type(['application/json']) + + # Authentication setting + auth_settings = [] + + return self.api_client.call_api(resource_path, 'PATCH', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='Client', + auth_settings=auth_settings, + callback=params.get('callback'), + _return_http_data_only=params.get('_return_http_data_only'), + collection_formats=collection_formats) diff --git a/samples/client/petstore/python/test/test_fake_classname_tags_123_api.py b/samples/client/petstore/python/test/test_fake_classname_tags_123_api.py new file mode 100644 index 00000000000..c0ca01d53d4 --- /dev/null +++ b/samples/client/petstore/python/test/test_fake_classname_tags_123_api.py @@ -0,0 +1,55 @@ +# coding: utf-8 + +""" + Swagger Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 1.0.0 + Contact: apiteam@swagger.io + Generated by: https://github.com/swagger-api/swagger-codegen.git + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" + +from __future__ import absolute_import + +import os +import sys +import unittest + +import petstore_api +from petstore_api.rest import ApiException +from petstore_api.apis.fake_classname_tags_123_api import FakeClassnameTags123Api + + +class TestFakeClassnameTags123Api(unittest.TestCase): + """ FakeClassnameTags123Api unit test stubs """ + + def setUp(self): + self.api = petstore_api.apis.fake_classname_tags_123_api.FakeClassnameTags123Api() + + def tearDown(self): + pass + + def test_test_classname(self): + """ + Test case for test_classname + + To test class name in snake case + """ + pass + + +if __name__ == '__main__': + unittest.main()