diff --git a/bin/security/silex-petstore-server.sh b/bin/security/silex-petstore-server.sh index a939c2da9a8..229eac1391c 100755 --- a/bin/security/silex-petstore-server.sh +++ b/bin/security/silex-petstore-server.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="$@ generate -t modules/swagger-codegen/src/main/resources/silex -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l silex-PHP -o samples/server/petstore-security-test/silex" +ags="$@ generate -t modules/swagger-codegen/src/main/resources/php-silex -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l php-silex -o samples/server/petstore-security-test/silex" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/security/typescript-angular2.sh b/bin/security/typescript-angular2.sh index 4bb954bae85..192932f1b3b 100755 --- a/bin/security/typescript-angular2.sh +++ b/bin/security/typescript-angular2.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="$@ generate -t modules/swagger-codegen/src/main/resources/typescript-angular2 -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l typescript-angular -o samples/client/petstore-security-test/typescript-angular2" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l typescript-angular -o samples/client/petstore-security-test/typescript-angular2" java $JAVA_OPTS -jar $executable $ags diff --git a/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs b/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs index f94789ba974..b5f0d4003b0 100644 --- a/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs +++ b/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Client/ApiClient.cs @@ -139,14 +139,7 @@ namespace IO.Swagger.Client if (postBody != null) // http body (model or byte[]) parameter { - if (postBody.GetType() == typeof(String)) - { - request.AddParameter("application/json", postBody, ParameterType.RequestBody); - } - else if (postBody.GetType() == typeof(byte[])) - { - request.AddParameter(contentType, postBody, ParameterType.RequestBody); - } + request.AddParameter(contentType, postBody, ParameterType.RequestBody); } return request; @@ -351,9 +344,25 @@ namespace IO.Swagger.Client } } + /// + ///Check if the given MIME is a JSON MIME. + ///JSON MIME examples: + /// application/json + /// application/json; charset=UTF8 + /// APPLICATION/JSON + /// application/vnd.company+json + /// + /// MIME + /// Returns True if MIME type is json. + public bool IsJsonMime(String mime) + { + var jsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"); + return mime != null && (jsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json")); + } + /// /// Select the Content-Type header's value from the given content-type array: - /// if JSON exists in the given array, use it; + /// if JSON type exists in the given array, use it; /// otherwise use the first one defined in 'consumes' /// /// The Content-Type array to select from. @@ -361,11 +370,14 @@ namespace IO.Swagger.Client public String SelectHeaderContentType(String[] contentTypes) { if (contentTypes.Length == 0) - return null; - - if (contentTypes.Contains("application/json", StringComparer.OrdinalIgnoreCase)) return "application/json"; + foreach (var contentType in contentTypes) + { + if (IsJsonMime(contentType.ToLower())) + return contentType; + } + return contentTypes[0]; // use the first content type specified in 'consumes' } diff --git a/samples/client/petstore-security-test/go/api_client.go b/samples/client/petstore-security-test/go/api_client.go index 948f60420ea..db4d1d0757b 100644 --- a/samples/client/petstore-security-test/go/api_client.go +++ b/samples/client/petstore-security-test/go/api_client.go @@ -1,11 +1,11 @@ -/* +/* * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r * * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- * - * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r - * Generated by: https://github.com/swagger-api/swagger-codegen.git + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) */ package swagger diff --git a/samples/client/petstore-security-test/go/api_response.go b/samples/client/petstore-security-test/go/api_response.go index d2cd6766832..8b8f3b928ed 100644 --- a/samples/client/petstore-security-test/go/api_response.go +++ b/samples/client/petstore-security-test/go/api_response.go @@ -1,11 +1,11 @@ -/* +/* * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r * * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- * - * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r - * Generated by: https://github.com/swagger-api/swagger-codegen.git + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) */ package swagger diff --git a/samples/client/petstore-security-test/go/configuration.go b/samples/client/petstore-security-test/go/configuration.go index a36b57c4b55..bd7622870d4 100644 --- a/samples/client/petstore-security-test/go/configuration.go +++ b/samples/client/petstore-security-test/go/configuration.go @@ -1,11 +1,11 @@ -/* +/* * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r * * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- * - * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r - * Generated by: https://github.com/swagger-api/swagger-codegen.git + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) */ package swagger diff --git a/samples/client/petstore-security-test/go/fake_api.go b/samples/client/petstore-security-test/go/fake_api.go index b20c99c8014..6375ef8234e 100644 --- a/samples/client/petstore-security-test/go/fake_api.go +++ b/samples/client/petstore-security-test/go/fake_api.go @@ -1,11 +1,11 @@ -/* +/* * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r * * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- * - * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r - * Generated by: https://github.com/swagger-api/swagger-codegen.git + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) */ package swagger @@ -77,14 +77,14 @@ func (a *FakeApiService) TestCodeInjectEndRnNR(localVarOptionals map[string]inte return nil, err } - localVarHttpResponse, err := a.client.callAPI(r) - if err != nil || localVarHttpResponse == nil { - return localVarHttpResponse, err - } - defer localVarHttpResponse.Body.Close() - if localVarHttpResponse.StatusCode >= 300 { + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { return localVarHttpResponse, reportError(localVarHttpResponse.Status) - } + } return localVarHttpResponse, err } diff --git a/samples/client/petstore-security-test/go/model_return.go b/samples/client/petstore-security-test/go/model_return.go index d2c0ccb2e81..d1a82197416 100644 --- a/samples/client/petstore-security-test/go/model_return.go +++ b/samples/client/petstore-security-test/go/model_return.go @@ -1,11 +1,11 @@ -/* +/* * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r * * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- * - * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r - * Generated by: https://github.com/swagger-api/swagger-codegen.git + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) */ package swagger diff --git a/samples/client/petstore-security-test/javascript-closure-angular/API/Client/FakeApi.js b/samples/client/petstore-security-test/javascript-closure-angular/API/Client/FakeApi.js index 061532b28b5..3256c954a05 100644 --- a/samples/client/petstore-security-test/javascript-closure-angular/API/Client/FakeApi.js +++ b/samples/client/petstore-security-test/javascript-closure-angular/API/Client/FakeApi.js @@ -8,7 +8,7 @@ * Generated by: io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen */ /** - * @license Apache 2.0 *_/ ' \" =end -- \\r\\n \\n \\r + * @license Apache-2.0 *_/ ' \" =end -- \\r\\n \\n \\r * http://www.apache.org/licenses/LICENSE-2.0.html *_/ ' \" =end -- \\r\\n \\n \\r */ diff --git a/samples/client/petstore-security-test/javascript/.swagger-codegen/VERSION b/samples/client/petstore-security-test/javascript/.swagger-codegen/VERSION index 7fea99011a6..f9f7450d135 100644 --- a/samples/client/petstore-security-test/javascript/.swagger-codegen/VERSION +++ b/samples/client/petstore-security-test/javascript/.swagger-codegen/VERSION @@ -1 +1 @@ -2.2.3-SNAPSHOT \ No newline at end of file +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/javascript/README.md b/samples/client/petstore-security-test/javascript/README.md index 144c7dbfd55..4a9bd7e80db 100644 --- a/samples/client/petstore-security-test/javascript/README.md +++ b/samples/client/petstore-security-test/javascript/README.md @@ -23,6 +23,30 @@ Then install it via: npm install swagger_petstore____end____rn_n_r --save ``` +##### Local development + +To use the library locally without publishing to a remote npm registry, first install the dependencies by changing +into the directory containing `package.json` (and this README). Let's call this `JAVASCRIPT_CLIENT_DIR`. Then run: + +```shell +npm install +``` + +Next, [link](https://docs.npmjs.com/cli/link) it globally in npm with the following, also from `JAVASCRIPT_CLIENT_DIR`: + +```shell +npm link +``` + +Finally, switch to the directory you want to use your swagger_petstore____end____rn_n_r from, and run: + +```shell +npm link /path/to/ +``` + +You should now be able to `require('swagger_petstore____end____rn_n_r')` in javascript files from the directory you ran the last +command above from. + #### git # If the library is hosted at a git repository, e.g. @@ -37,7 +61,8 @@ then install it via: The library also works in the browser environment via npm and [browserify](http://browserify.org/). After following the above steps with Node.js and installing browserify with `npm install -g browserify`, -perform the following (assuming *main.js* is your entry file): +perform the following (assuming *main.js* is your entry file, that's to say your javascript file where you actually +use this library): ```shell browserify main.js > bundle.js @@ -45,6 +70,24 @@ browserify main.js > bundle.js Then include *bundle.js* in the HTML pages. +### Webpack Configuration + +Using Webpack you may encounter the following error: "Module not found: Error: +Cannot resolve module", most certainly you should disable AMD loader. Add/merge +the following section to your webpack config: + +```javascript +module: { + rules: [ + { + parser: { + amd: false + } + } + ] +} +``` + ## Getting Started Please follow the [installation](#installation) instruction and execute the following JS code: diff --git a/samples/client/petstore-security-test/javascript/package.json b/samples/client/petstore-security-test/javascript/package.json index 9bb9f494674..9fae64eb646 100644 --- a/samples/client/petstore-security-test/javascript/package.json +++ b/samples/client/petstore-security-test/javascript/package.json @@ -2,7 +2,7 @@ "name": "swagger_petstore____end____rn_n_r", "version": "1.0.0 *_/ =end -- \r\n \n \r", "description": "This_spec_is_mainly_for_testing_Petstore_server_and_contains_fake_endpoints_models__Please_do_not_use_this_for_any_other_purpose__Special_characters_______end______", - "license": "Unlicense", + "license": "Apache-2.0 */ ' " =end -- \r\n \n \r", "main": "src/index.js", "scripts": { "test": "./node_modules/mocha/bin/mocha --recursive" diff --git a/samples/client/petstore-security-test/javascript/src/ApiClient.js b/samples/client/petstore-security-test/javascript/src/ApiClient.js index b7eb8adcbdc..193dcfa683b 100644 --- a/samples/client/petstore-security-test/javascript/src/ApiClient.js +++ b/samples/client/petstore-security-test/javascript/src/ApiClient.js @@ -8,7 +8,7 @@ * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * - * Swagger Codegen version: 2.2.3-SNAPSHOT + * Swagger Codegen version: 2.3.0-SNAPSHOT * * Do not edit the class manually. * @@ -362,6 +362,7 @@ * @param {String} httpMethod The HTTP method to use. * @param {Object.} pathParams A map of path parameters and their values. * @param {Object.} queryParams A map of query parameters and their values. + * @param {Object.} collectionQueryParams A map of collection query parameters and their values. * @param {Object.} headerParams A map of header parameters and their values. * @param {Object.} formParams A map of form parameters and their values. * @param {Object} bodyParam The value to pass as the request body. @@ -374,7 +375,7 @@ * @returns {Object} The SuperAgent request object. */ exports.prototype.callApi = function callApi(path, httpMethod, pathParams, - queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, + queryParams, collectionQueryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, callback) { var _this = this; @@ -384,6 +385,25 @@ // apply authentications this.applyAuthToRequest(request, authNames); + // set collection query parameters + for (var key in collectionQueryParams) { + if (collectionQueryParams.hasOwnProperty(key)) { + var param = collectionQueryParams[key]; + if (param.collectionFormat === 'csv') { + // SuperAgent normally percent-encodes all reserved characters in a query parameter. However, + // commas are used as delimiters for the 'csv' collectionFormat so they must not be encoded. We + // must therefore construct and encode 'csv' collection query parameters manually. + if (param.value != null) { + var value = param.value.map(this.paramToString).map(encodeURIComponent).join(','); + request.query(encodeURIComponent(key) + "=" + value); + } + } else { + // All other collection query parameters should be treated as ordinary query parameters. + queryParams[key] = this.buildCollectionParam(param.value, param.collectionFormat); + } + } + } + // set query parameters if (httpMethod.toUpperCase() === 'GET' && this.cache === false) { queryParams['_'] = new Date().getTime(); diff --git a/samples/client/petstore-security-test/javascript/src/api/FakeApi.js b/samples/client/petstore-security-test/javascript/src/api/FakeApi.js index 4a5d37f908e..32e2c7ea1ec 100644 --- a/samples/client/petstore-security-test/javascript/src/api/FakeApi.js +++ b/samples/client/petstore-security-test/javascript/src/api/FakeApi.js @@ -8,7 +8,7 @@ * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * - * Swagger Codegen version: 2.2.3-SNAPSHOT + * Swagger Codegen version: 2.3.0-SNAPSHOT * * Do not edit the class manually. * @@ -71,6 +71,8 @@ }; var queryParams = { }; + var collectionQueryParams = { + }; var headerParams = { }; var formParams = { @@ -84,7 +86,7 @@ return this.apiClient.callApi( '/fake', 'PUT', - pathParams, queryParams, headerParams, formParams, postBody, + pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback ); } diff --git a/samples/client/petstore-security-test/javascript/src/index.js b/samples/client/petstore-security-test/javascript/src/index.js index 24c45e90a68..4da0fef98ea 100644 --- a/samples/client/petstore-security-test/javascript/src/index.js +++ b/samples/client/petstore-security-test/javascript/src/index.js @@ -8,7 +8,7 @@ * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * - * Swagger Codegen version: 2.2.3-SNAPSHOT + * Swagger Codegen version: 2.3.0-SNAPSHOT * * Do not edit the class manually. * diff --git a/samples/client/petstore-security-test/javascript/src/model/ModelReturn.js b/samples/client/petstore-security-test/javascript/src/model/ModelReturn.js index 40043ceb412..6e9c1fd3c72 100644 --- a/samples/client/petstore-security-test/javascript/src/model/ModelReturn.js +++ b/samples/client/petstore-security-test/javascript/src/model/ModelReturn.js @@ -8,7 +8,7 @@ * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * - * Swagger Codegen version: 2.2.3-SNAPSHOT + * Swagger Codegen version: 2.3.0-SNAPSHOT * * Do not edit the class manually. * diff --git a/samples/client/petstore-security-test/perl/README.md b/samples/client/petstore-security-test/perl/README.md index c60bcf8bc30..090ffbd1f9a 100644 --- a/samples/client/petstore-security-test/perl/README.md +++ b/samples/client/petstore-security-test/perl/README.md @@ -251,10 +251,10 @@ use WWW::SwaggerClient::; my $api_instance = WWW::SwaggerClient::->new( ); -my $test code inject */ ' " =end __ \r\n \n \r = 'test code inject */ ' " =end __ \r\n \n \r_example'; # string | To test code injection */ ' \" =_end -- \\r\\n \\n \\r +my $test_code_inject_*/_'_"_=end____\r\n_\n_\r = 'test_code_inject_*/_'_"_=end____\r\n_\n_\r_example'; # string | To test code injection */ ' \" =_end -- \\r\\n \\n \\r eval { - $api_instance->test_code_inject____end__rn_n_r(test code inject */ ' " =end __ \r\n \n \r => $test code inject */ ' " =end __ \r\n \n \r); + $api_instance->test_code_inject____end__rn_n_r(test_code_inject_*/_'_"_=end____\r\n_\n_\r => $test_code_inject_*/_'_"_=end____\r\n_\n_\r); }; if ($@) { warn "Exception when calling FakeApi->test_code_inject____end__rn_n_r: $@\n"; diff --git a/samples/client/petstore-security-test/perl/deep_module_test/README.md b/samples/client/petstore-security-test/perl/deep_module_test/README.md index dfbd75f4abc..fa7a62f046a 100644 --- a/samples/client/petstore-security-test/perl/deep_module_test/README.md +++ b/samples/client/petstore-security-test/perl/deep_module_test/README.md @@ -251,10 +251,10 @@ use Something::Deep::; my $api_instance = Something::Deep::->new( ); -my $test code inject */ ' " =end __ \r\n \n \r = 'test code inject */ ' " =end __ \r\n \n \r_example'; # string | To test code injection */ ' \" =_end -- \\r\\n \\n \\r +my $test_code_inject_*/_'_"_=end____\r\n_\n_\r = 'test_code_inject_*/_'_"_=end____\r\n_\n_\r_example'; # string | To test code injection */ ' \" =_end -- \\r\\n \\n \\r eval { - $api_instance->test_code_inject____end__rn_n_r(test code inject */ ' " =end __ \r\n \n \r => $test code inject */ ' " =end __ \r\n \n \r); + $api_instance->test_code_inject____end__rn_n_r(test_code_inject_*/_'_"_=end____\r\n_\n_\r => $test_code_inject_*/_'_"_=end____\r\n_\n_\r); }; if ($@) { warn "Exception when calling FakeApi->test_code_inject____end__rn_n_r: $@\n"; diff --git a/samples/client/petstore-security-test/perl/deep_module_test/docs/FakeApi.md b/samples/client/petstore-security-test/perl/deep_module_test/docs/FakeApi.md index 35f56434164..bafb5c09467 100644 --- a/samples/client/petstore-security-test/perl/deep_module_test/docs/FakeApi.md +++ b/samples/client/petstore-security-test/perl/deep_module_test/docs/FakeApi.md @@ -13,7 +13,7 @@ Method | HTTP request | Description # **test_code_inject____end__rn_n_r** -> test_code_inject____end__rn_n_r(test code inject */ ' " =end __ \r\n \n \r => $test code inject */ ' " =end __ \r\n \n \r) +> test_code_inject____end__rn_n_r(test_code_inject_*/_'_"_=end____\r\n_\n_\r => $test_code_inject_*/_'_"_=end____\r\n_\n_\r) To test code injection */ ' \" =_end -- \\r\\n \\n \\r @@ -24,10 +24,10 @@ use Something::Deep::FakeApi; my $api_instance = Something::Deep::FakeApi->new( ); -my $test code inject */ ' " =end __ \r\n \n \r = 'test code inject */ ' " =end __ \r\n \n \r_example'; # string | To test code injection */ ' \" =_end -- \\r\\n \\n \\r +my $test_code_inject_*/_'_"_=end____\r\n_\n_\r = 'test_code_inject_*/_'_"_=end____\r\n_\n_\r_example'; # string | To test code injection */ ' \" =_end -- \\r\\n \\n \\r eval { - $api_instance->test_code_inject____end__rn_n_r(test code inject */ ' " =end __ \r\n \n \r => $test code inject */ ' " =end __ \r\n \n \r); + $api_instance->test_code_inject____end__rn_n_r(test_code_inject_*/_'_"_=end____\r\n_\n_\r => $test_code_inject_*/_'_"_=end____\r\n_\n_\r); }; if ($@) { warn "Exception when calling FakeApi->test_code_inject____end__rn_n_r: $@\n"; @@ -38,7 +38,7 @@ if ($@) { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **test code inject */ ' " =end __ \r\n \n \r** | **string**| To test code injection */ ' \" =_end -- \\r\\n \\n \\r | [optional] + **test_code_inject_*/_'_"_=end____\r\n_\n_\r** | **string**| To test code injection */ ' \" =_end -- \\r\\n \\n \\r | [optional] ### Return type diff --git a/samples/client/petstore-security-test/perl/deep_module_test/lib/Something/Deep/FakeApi.pm b/samples/client/petstore-security-test/perl/deep_module_test/lib/Something/Deep/FakeApi.pm index 33c0f7b3936..ef60e30b9a9 100644 --- a/samples/client/petstore-security-test/perl/deep_module_test/lib/Something/Deep/FakeApi.pm +++ b/samples/client/petstore-security-test/perl/deep_module_test/lib/Something/Deep/FakeApi.pm @@ -53,10 +53,10 @@ sub new { # # To test code injection */ ' \" =_end -- \\r\\n \\n \\r # -# @param string $test code inject */ ' " =end __ \r\n \n \r To test code injection */ ' \" =_end -- \\r\\n \\n \\r (optional) +# @param string $test_code_inject_*/_'_"_=end____\r\n_\n_\r To test code injection */ ' \" =_end -- \\r\\n \\n \\r (optional) { my $params = { - 'test code inject */ ' " =end __ \r\n \n \r' => { + 'test_code_inject_*/_'_"_=end____\r\n_\n_\r' => { data_type => 'string', description => 'To test code injection */ ' \" =_end -- \\r\\n \\n \\r', required => '0', @@ -89,8 +89,8 @@ sub test_code_inject____end__rn_n_r { $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json', '*/ \" =_end -- '); # form params - if ( exists $args{'test code inject */ ' " =end __ \r\n \n \r'} ) { - $form_params->{'test code inject */ ' " =end -- \r\n \n \r'} = $self->{api_client}->to_form_value($args{'test code inject */ ' " =end __ \r\n \n \r'}); + if ( exists $args{'test_code_inject_*/_'_"_=end____\r\n_\n_\r'} ) { + $form_params->{'test code inject */ ' " =end -- \r\n \n \r'} = $self->{api_client}->to_form_value($args{'test_code_inject_*/_'_"_=end____\r\n_\n_\r'}); } my $_body_data; diff --git a/samples/client/petstore-security-test/perl/docs/FakeApi.md b/samples/client/petstore-security-test/perl/docs/FakeApi.md index fbea6c1fc8d..ce7fac2f822 100644 --- a/samples/client/petstore-security-test/perl/docs/FakeApi.md +++ b/samples/client/petstore-security-test/perl/docs/FakeApi.md @@ -13,7 +13,7 @@ Method | HTTP request | Description # **test_code_inject____end__rn_n_r** -> test_code_inject____end__rn_n_r(test code inject */ ' " =end __ \r\n \n \r => $test code inject */ ' " =end __ \r\n \n \r) +> test_code_inject____end__rn_n_r(test_code_inject_*/_'_"_=end____\r\n_\n_\r => $test_code_inject_*/_'_"_=end____\r\n_\n_\r) To test code injection */ ' \" =_end -- \\r\\n \\n \\r @@ -24,10 +24,10 @@ use WWW::SwaggerClient::FakeApi; my $api_instance = WWW::SwaggerClient::FakeApi->new( ); -my $test code inject */ ' " =end __ \r\n \n \r = 'test code inject */ ' " =end __ \r\n \n \r_example'; # string | To test code injection */ ' \" =_end -- \\r\\n \\n \\r +my $test_code_inject_*/_'_"_=end____\r\n_\n_\r = 'test_code_inject_*/_'_"_=end____\r\n_\n_\r_example'; # string | To test code injection */ ' \" =_end -- \\r\\n \\n \\r eval { - $api_instance->test_code_inject____end__rn_n_r(test code inject */ ' " =end __ \r\n \n \r => $test code inject */ ' " =end __ \r\n \n \r); + $api_instance->test_code_inject____end__rn_n_r(test_code_inject_*/_'_"_=end____\r\n_\n_\r => $test_code_inject_*/_'_"_=end____\r\n_\n_\r); }; if ($@) { warn "Exception when calling FakeApi->test_code_inject____end__rn_n_r: $@\n"; @@ -38,7 +38,7 @@ if ($@) { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **test code inject */ ' " =end __ \r\n \n \r** | **string**| To test code injection */ ' \" =_end -- \\r\\n \\n \\r | [optional] + **test_code_inject_*/_'_"_=end____\r\n_\n_\r** | **string**| To test code injection */ ' \" =_end -- \\r\\n \\n \\r | [optional] ### Return type diff --git a/samples/client/petstore-security-test/perl/lib/WWW/SwaggerClient/FakeApi.pm b/samples/client/petstore-security-test/perl/lib/WWW/SwaggerClient/FakeApi.pm index 79318d9180b..db8e379beec 100644 --- a/samples/client/petstore-security-test/perl/lib/WWW/SwaggerClient/FakeApi.pm +++ b/samples/client/petstore-security-test/perl/lib/WWW/SwaggerClient/FakeApi.pm @@ -53,10 +53,10 @@ sub new { # # To test code injection */ ' \" =_end -- \\r\\n \\n \\r # -# @param string $test code inject */ ' " =end __ \r\n \n \r To test code injection */ ' \" =_end -- \\r\\n \\n \\r (optional) +# @param string $test_code_inject_*/_'_"_=end____\r\n_\n_\r To test code injection */ ' \" =_end -- \\r\\n \\n \\r (optional) { my $params = { - 'test code inject */ ' " =end __ \r\n \n \r' => { + 'test_code_inject_*/_'_"_=end____\r\n_\n_\r' => { data_type => 'string', description => 'To test code injection */ ' \" =_end -- \\r\\n \\n \\r', required => '0', @@ -89,8 +89,8 @@ sub test_code_inject____end__rn_n_r { $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json', '*/ \" =_end -- '); # form params - if ( exists $args{'test code inject */ ' " =end __ \r\n \n \r'} ) { - $form_params->{'test code inject */ ' " =end -- \r\n \n \r'} = $self->{api_client}->to_form_value($args{'test code inject */ ' " =end __ \r\n \n \r'}); + if ( exists $args{'test_code_inject_*/_'_"_=end____\r\n_\n_\r'} ) { + $form_params->{'test code inject */ ' " =end -- \r\n \n \r'} = $self->{api_client}->to_form_value($args{'test_code_inject_*/_'_"_=end____\r\n_\n_\r'}); } my $_body_data; diff --git a/samples/client/petstore-security-test/python/petstore_api/api_client.py b/samples/client/petstore-security-test/python/petstore_api/api_client.py index 0325d3bad9e..ea9f0084ba5 100644 --- a/samples/client/petstore-security-test/python/petstore_api/api_client.py +++ b/samples/client/petstore-security-test/python/petstore_api/api_client.py @@ -283,7 +283,7 @@ class ApiClient(object): _request_timeout=None): """ Makes the HTTP request (synchronous) and return the deserialized data. - To make an async request, define a function for callback. + To make an async request, set the async parameter. :param resource_path: Path to method endpoint. :param method: Method to call. @@ -307,10 +307,10 @@ class ApiClient(object): :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts. :return: - If provide parameter callback, + If async parameter is True, the request will be called asynchronously. The method will return the request thread. - If parameter callback is None, + If parameter async is False or missing, then the method will return the response directly. """ if not async: diff --git a/samples/client/petstore-security-test/python/petstore_api/configuration.py b/samples/client/petstore-security-test/python/petstore_api/configuration.py index 3da74bb2f43..da9d119a09e 100644 --- a/samples/client/petstore-security-test/python/petstore_api/configuration.py +++ b/samples/client/petstore-security-test/python/petstore_api/configuration.py @@ -15,14 +15,30 @@ from __future__ import absolute_import import urllib3 -import sys +import copy import logging +import multiprocessing +import sys from six import iteritems +from six import with_metaclass from six.moves import http_client as httplib +class TypeWithDefault(type): + def __init__(cls, name, bases, dct): + super(TypeWithDefault, cls).__init__(name, bases, dct) + cls._default = None -class Configuration(object): + def __call__(cls): + if cls._default == None: + cls._default = type.__call__(cls) + return copy.copy(cls._default) + + def set_default(cls, default): + cls._default = copy.copy(default) + + +class Configuration(with_metaclass(TypeWithDefault, object)): """ NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen @@ -75,6 +91,16 @@ class Configuration(object): self.cert_file = None # client key file self.key_file = None + # Set this to True/False to enable/disable SSL hostname verification. + self.assert_hostname = None + + # urllib3 connection pool's maximum number of connections saved + # per pool. urllib3 uses 1 connection as default value, but this is + # not the best value when you are making a lot of possibly parallel + # requests to the same host, which is often the case here. + # cpu_count * 5 is used as default value to increase performance. + self.connection_pool_maxsize = multiprocessing.cpu_count() * 5 + # Proxy URL self.proxy = None diff --git a/samples/client/petstore-security-test/python/petstore_api/rest.py b/samples/client/petstore-security-test/python/petstore_api/rest.py index 46fbdbb63bb..8ccd6a6f5e5 100644 --- a/samples/client/petstore-security-test/python/petstore_api/rest.py +++ b/samples/client/petstore-security-test/python/petstore_api/rest.py @@ -56,7 +56,7 @@ class RESTResponse(io.IOBase): class RESTClientObject(object): - def __init__(self, configuration, pools_size=4, maxsize=4): + def __init__(self, configuration, pools_size=4, maxsize=None): # urllib3.PoolManager will pass all kw parameters to connectionpool # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 @@ -76,6 +76,16 @@ class RESTClientObject(object): # if not set certificate file, use Mozilla's root certificates. ca_certs = certifi.where() + addition_pool_args = {} + if configuration.assert_hostname is not None: + addition_pool_args['assert_hostname'] = configuration.assert_hostname + + if maxsize is None: + if configuration.connection_pool_maxsize is not None: + maxsize = configuration.connection_pool_maxsize + else: + maxsize = 4 + # https pool manager if configuration.proxy: self.pool_manager = urllib3.ProxyManager( @@ -85,7 +95,8 @@ class RESTClientObject(object): ca_certs=ca_certs, cert_file=configuration.cert_file, key_file=configuration.key_file, - proxy_url=configuration.proxy + proxy_url=configuration.proxy, + **addition_pool_args ) else: self.pool_manager = urllib3.PoolManager( @@ -94,7 +105,8 @@ class RESTClientObject(object): cert_reqs=cert_reqs, ca_certs=ca_certs, cert_file=configuration.cert_file, - key_file=configuration.key_file + key_file=configuration.key_file, + **addition_pool_args ) def request(self, method, url, query_params=None, headers=None, diff --git a/samples/client/petstore-security-test/qt5cpp/client/SWGFakeApi.cpp b/samples/client/petstore-security-test/qt5cpp/client/SWGFakeApi.cpp index e7d60bc8ba0..771940cd241 100644 --- a/samples/client/petstore-security-test/qt5cpp/client/SWGFakeApi.cpp +++ b/samples/client/petstore-security-test/qt5cpp/client/SWGFakeApi.cpp @@ -29,7 +29,7 @@ SWGFakeApi::SWGFakeApi(QString host, QString basePath) { } void -SWGFakeApi::testCodeInject */ ' " =end \r\n \n \r(QString* test_code_inject____end____rn_n_r) { +SWGFakeApi::testCodeInject____end__rn_n_r(QString* test_code_inject____end____rn_n_r) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("/fake"); @@ -45,16 +45,20 @@ SWGFakeApi::testCodeInject */ ' " =end \r\n \n \r(QString* test_c + foreach(QString key, this->defaultHeaders.keys()) { + input.headers.insert(key, this->defaultHeaders.value(key)); + } + connect(worker, &HttpRequestWorker::on_execution_finished, this, - &SWGFakeApi::testCodeInject */ ' " =end \r\n \n \rCallback); + &SWGFakeApi::testCodeInject____end__rn_n_rCallback); worker->execute(&input); } void -SWGFakeApi::testCodeInject */ ' " =end \r\n \n \rCallback(HttpRequestWorker * worker) { +SWGFakeApi::testCodeInject____end__rn_n_rCallback(HttpRequestWorker * worker) { QString msg; QString error_str = worker->error_str; QNetworkReply::NetworkError error_type = worker->error_type; @@ -68,8 +72,12 @@ SWGFakeApi::testCodeInject */ ' " =end \r\n \n \rCallback(HttpReq worker->deleteLater(); - emit testCodeInject */ ' " =end \r\n \n \rSignal(); - emit testCodeInject */ ' " =end \r\n \n \rSignalE(error_type, error_str); + if (worker->error_type == QNetworkReply::NoError) { + emit testCodeInject____end__rn_n_rSignal(); + } else { + emit testCodeInject____end__rn_n_rSignalE(error_type, error_str); + emit testCodeInject____end__rn_n_rSignalEFull(worker, error_type, error_str); + } } diff --git a/samples/client/petstore-security-test/qt5cpp/client/SWGFakeApi.h b/samples/client/petstore-security-test/qt5cpp/client/SWGFakeApi.h index 5a28a4ce2c9..087e498423f 100644 --- a/samples/client/petstore-security-test/qt5cpp/client/SWGFakeApi.h +++ b/samples/client/petstore-security-test/qt5cpp/client/SWGFakeApi.h @@ -31,16 +31,19 @@ public: QString host; QString basePath; + QMap defaultHeaders; - void testCodeInject */ ' " =end \r\n \n \r(QString* test_code_inject____end____rn_n_r); + void testCodeInject____end__rn_n_r(QString* test_code_inject____end____rn_n_r); private: - void testCodeInject */ ' " =end \r\n \n \rCallback (HttpRequestWorker * worker); + void testCodeInject____end__rn_n_rCallback (HttpRequestWorker * worker); signals: - void testCodeInject */ ' " =end \r\n \n \rSignal(); + void testCodeInject____end__rn_n_rSignal(); - void testCodeInject */ ' " =end \r\n \n \rSignalE(QNetworkReply::NetworkError error_type, QString& error_str); + void testCodeInject____end__rn_n_rSignalE(QNetworkReply::NetworkError error_type, QString& error_str); + + void testCodeInject____end__rn_n_rSignalEFull(HttpRequestWorker* worker, QNetworkReply::NetworkError error_type, QString& error_str); }; diff --git a/samples/client/petstore-security-test/qt5cpp/client/SWGHttpRequest.cpp b/samples/client/petstore-security-test/qt5cpp/client/SWGHttpRequest.cpp index 2300fb2753b..7ad7930206c 100644 --- a/samples/client/petstore-security-test/qt5cpp/client/SWGHttpRequest.cpp +++ b/samples/client/petstore-security-test/qt5cpp/client/SWGHttpRequest.cpp @@ -262,6 +262,9 @@ void HttpRequestWorker::execute(HttpRequestInput *input) { // prepare connection QNetworkRequest request = QNetworkRequest(QUrl(input->url_str)); + if (HttpRequestWorker::sslDefaultConfiguration != nullptr) { + request.setSslConfiguration(*HttpRequestWorker::sslDefaultConfiguration); + } request.setRawHeader("User-Agent", "Swagger-Client"); foreach(QString key, input->headers.keys()) { request.setRawHeader(key.toStdString().c_str(), input->headers.value(key).toStdString().c_str()); @@ -309,16 +312,14 @@ void HttpRequestWorker::execute(HttpRequestInput *input) { void HttpRequestWorker::on_manager_finished(QNetworkReply *reply) { error_type = reply->error(); - if (error_type == QNetworkReply::NoError) { - response = reply->readAll(); - } - else { - error_str = reply->errorString(); - } + response = reply->readAll(); + error_str = reply->errorString(); reply->deleteLater(); emit on_execution_finished(this); } +QSslConfiguration* HttpRequestWorker::sslDefaultConfiguration; + } diff --git a/samples/client/petstore-security-test/qt5cpp/client/SWGHttpRequest.h b/samples/client/petstore-security-test/qt5cpp/client/SWGHttpRequest.h index 045bcd9c075..5e14062e162 100644 --- a/samples/client/petstore-security-test/qt5cpp/client/SWGHttpRequest.h +++ b/samples/client/petstore-security-test/qt5cpp/client/SWGHttpRequest.h @@ -73,6 +73,7 @@ public: QString http_attribute_encode(QString attribute_name, QString input); void execute(HttpRequestInput *input); + static QSslConfiguration* sslDefaultConfiguration; signals: void on_execution_finished(HttpRequestWorker *worker); diff --git a/samples/client/petstore-security-test/qt5cpp/client/SWGReturn.cpp b/samples/client/petstore-security-test/qt5cpp/client/SWGReturn.cpp index fc4cd89e5aa..c549fb37ace 100644 --- a/samples/client/petstore-security-test/qt5cpp/client/SWGReturn.cpp +++ b/samples/client/petstore-security-test/qt5cpp/client/SWGReturn.cpp @@ -37,7 +37,7 @@ SWGReturn::~SWGReturn() { void SWGReturn::init() { - return = 0; + _return = 0; } void @@ -56,7 +56,7 @@ SWGReturn::fromJson(QString &json) { void SWGReturn::fromJsonObject(QJsonObject &pJson) { - ::Swagger::setValue(&return, pJson["return"], "qint32", ""); + ::Swagger::setValue(&_return, pJson["return"], "qint32", ""); } QString @@ -73,18 +73,18 @@ QJsonObject* SWGReturn::asJsonObject() { QJsonObject* obj = new QJsonObject(); - obj->insert("return", QJsonValue(return)); + obj->insert("return", QJsonValue(_return)); return obj; } qint32 SWGReturn::getReturn() { - return return; + return _return; } void -SWGReturn::setReturn(qint32 return) { - this->return = return; +SWGReturn::setReturn(qint32 _return) { + this->_return = _return; } diff --git a/samples/client/petstore-security-test/qt5cpp/client/SWGReturn.h b/samples/client/petstore-security-test/qt5cpp/client/SWGReturn.h index 778899dbe3a..0988110ae28 100644 --- a/samples/client/petstore-security-test/qt5cpp/client/SWGReturn.h +++ b/samples/client/petstore-security-test/qt5cpp/client/SWGReturn.h @@ -42,11 +42,11 @@ public: SWGReturn* fromJson(QString &jsonString); qint32 getReturn(); - void setReturn(qint32 return); + void setReturn(qint32 _return); private: - qint32 return; + qint32 _return; }; } diff --git a/samples/client/petstore-security-test/ruby/lib/petstore.rb b/samples/client/petstore-security-test/ruby/lib/petstore.rb index c85b301c423..5c6e14b6a4a 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore.rb @@ -6,6 +6,7 @@ OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git +Swagger Codegen version: 2.3.0-SNAPSHOT =end diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/api/fake_api.rb b/samples/client/petstore-security-test/ruby/lib/petstore/api/fake_api.rb index 9c15fc51e88..62ba6e73b8f 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/api/fake_api.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/api/fake_api.rb @@ -6,6 +6,7 @@ OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git +Swagger Codegen version: 2.3.0-SNAPSHOT =end diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/api_client.rb b/samples/client/petstore-security-test/ruby/lib/petstore/api_client.rb index 8695f6e89c1..9c68cfea20d 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/api_client.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/api_client.rb @@ -6,6 +6,7 @@ OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git +Swagger Codegen version: 2.3.0-SNAPSHOT =end @@ -122,7 +123,9 @@ module Petstore end end - Typhoeus::Request.new(url, req_opts) + request = Typhoeus::Request.new(url, req_opts) + download_file(request) if opts[:return_type] == 'File' + request end # Check if the given MIME is a JSON MIME. @@ -143,14 +146,16 @@ module Petstore # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]" def deserialize(response, return_type) body = response.body + + # handle file downloading - return the File instance processed in request callbacks + # note that response body is empty when the file is written in chunks in request on_body callback + return @tempfile if return_type == 'File' + return nil if body.nil? || body.empty? # return response body directly for String return type return body if return_type == 'String' - # handle file downloading - save response body into a tmp file and return the File instance - return download_file(response) if return_type == 'File' - # ensuring a default content type content_type = response.headers['Content-Type'] || 'application/json' @@ -213,30 +218,38 @@ module Petstore # Save response body into a file in (the defined) temporary folder, using the filename # from the "Content-Disposition" header if provided, otherwise a random filename. + # The response body is written to the file in chunks in order to handle files which + # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby + # process can use. # # @see Configuration#temp_folder_path - # @return [Tempfile] the file downloaded - def download_file(response) - content_disposition = response.headers['Content-Disposition'] - if content_disposition and content_disposition =~ /filename=/i - filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] - prefix = sanitize_filename(filename) - else - prefix = 'download-' - end - prefix = prefix + '-' unless prefix.end_with?('-') - + def download_file(request) tempfile = nil - encoding = response.body.encoding - Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file| - file.write(response.body) - tempfile = file + encoding = nil + request.on_headers do |response| + content_disposition = response.headers['Content-Disposition'] + if content_disposition and content_disposition =~ /filename=/i + filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] + prefix = sanitize_filename(filename) + else + prefix = 'download-' + end + prefix = prefix + '-' unless prefix.end_with?('-') + encoding = response.body.encoding + tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) + @tempfile = tempfile + end + request.on_body do |chunk| + chunk.force_encoding(encoding) + tempfile.write(chunk) + end + request.on_complete do |response| + tempfile.close + @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ + "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ + "will be deleted automatically with GC. It's also recommended to delete the temp file "\ + "explicitly with `tempfile.delete`" end - @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ - "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ - "will be deleted automatically with GC. It's also recommended to delete the temp file "\ - "explicitly with `tempfile.delete`" - tempfile end # Sanitize filename by removing path. @@ -267,7 +280,7 @@ module Petstore data = {} form_params.each do |key, value| case value - when File, Array, nil + when ::File, ::Array, nil # let typhoeus handle File, Array and nil parameters data[key] = value else diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/api_error.rb b/samples/client/petstore-security-test/ruby/lib/petstore/api_error.rb index 27fc3cf9ad4..27fd7c1a8ef 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/api_error.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/api_error.rb @@ -6,6 +6,7 @@ OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git +Swagger Codegen version: 2.3.0-SNAPSHOT =end diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/configuration.rb b/samples/client/petstore-security-test/ruby/lib/petstore/configuration.rb index 630b1dd6681..78fcfc16030 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/configuration.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/configuration.rb @@ -6,6 +6,7 @@ OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git +Swagger Codegen version: 2.3.0-SNAPSHOT =end @@ -75,6 +76,11 @@ module Petstore # Default to 0 (never times out). attr_accessor :timeout + # Set this to false to skip client side validation in the operation. + # Default to true. + # @return [true, false] + attr_accessor :client_side_validation + ### TLS/SSL setting # Set this to false to skip verifying SSL certificate when calling API from https server. # Default to true. @@ -128,6 +134,7 @@ module Petstore @api_key = {} @api_key_prefix = {} @timeout = 0 + @client_side_validation = true @verify_ssl = true @verify_ssl_host = true @params_encoding = nil diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/models/model_return.rb b/samples/client/petstore-security-test/ruby/lib/petstore/models/model_return.rb index 9c4d50023c7..9e6ffd465a7 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/models/model_return.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/models/model_return.rb @@ -6,6 +6,7 @@ OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git +Swagger Codegen version: 2.3.0-SNAPSHOT =end diff --git a/samples/client/petstore-security-test/ruby/lib/petstore/version.rb b/samples/client/petstore-security-test/ruby/lib/petstore/version.rb index 4b5eadf50a1..c6ba3189c52 100644 --- a/samples/client/petstore-security-test/ruby/lib/petstore/version.rb +++ b/samples/client/petstore-security-test/ruby/lib/petstore/version.rb @@ -6,6 +6,7 @@ OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git +Swagger Codegen version: 2.3.0-SNAPSHOT =end diff --git a/samples/client/petstore-security-test/ruby/petstore.gemspec b/samples/client/petstore-security-test/ruby/petstore.gemspec index eb2a20c6607..51d168e828b 100644 --- a/samples/client/petstore-security-test/ruby/petstore.gemspec +++ b/samples/client/petstore-security-test/ruby/petstore.gemspec @@ -8,6 +8,7 @@ OpenAPI spec version: 1.0.0 */ ' \" =_end -- \\r\\n \\n \\r Contact: apiteam@swagger.io */ ' \" =_end -- \\r\\n \\n \\r Generated by: https://github.com/swagger-api/swagger-codegen.git +Swagger Codegen version: 2.3.0-SNAPSHOT =end @@ -28,15 +29,15 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 1.9" s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1' - s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.3' + s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0' - s.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0' + s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1' s.add_development_dependency 'webmock', '~> 1.24', '>= 1.24.3' s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6' s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2' s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16' - s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.11' + s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.12' s.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? } s.test_files = `find spec/*`.split("\n") diff --git a/samples/client/petstore-security-test/scala/pom.xml b/samples/client/petstore-security-test/scala/pom.xml index 81bcd8887f4..eceb1e6fdc4 100644 --- a/samples/client/petstore-security-test/scala/pom.xml +++ b/samples/client/petstore-security-test/scala/pom.xml @@ -153,7 +153,7 @@ com.fasterxml.jackson.module - jackson-module-scala_2.10 + jackson-module-scala_2.11 ${jackson-version} @@ -189,7 +189,7 @@ org.scalatest - scalatest_2.10 + scalatest_2.11 ${scala-test-version} test @@ -211,16 +211,16 @@ com.wordnik.swagger - swagger-async-httpclient_2.10 + swagger-async-httpclient_2.11 ${swagger-async-httpclient-version} - 2.10.4 + 2.11.11 1.2 2.2 1.19 - 1.5.15 + 1.5.16 1.0.5 1.0.0 2.8.9 diff --git a/samples/client/petstore-security-test/scala/src/main/scala/io/swagger/client/ApiInvoker.scala b/samples/client/petstore-security-test/scala/src/main/scala/io/swagger/client/ApiInvoker.scala index 182c49fc99d..5d31e36a762 100644 --- a/samples/client/petstore-security-test/scala/src/main/scala/io/swagger/client/ApiInvoker.scala +++ b/samples/client/petstore-security-test/scala/src/main/scala/io/swagger/client/ApiInvoker.scala @@ -28,7 +28,7 @@ import java.util.UUID import javax.ws.rs.core.MediaType import scala.collection.JavaConverters._ -import scala.collection.mutable.HashMap +import scala.collection.mutable import com.fasterxml.jackson.module.scala.DefaultScalaModule import com.fasterxml.jackson.datatype.joda.JodaModule @@ -41,8 +41,8 @@ object ScalaJsonUtil { def getJsonMapper = { val mapper = new ObjectMapper() mapper.registerModule(new DefaultScalaModule()) - mapper.registerModule(new JodaModule()); - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.registerModule(new JodaModule()) + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT) mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) @@ -52,13 +52,14 @@ object ScalaJsonUtil { } class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, - httpHeaders: HashMap[String, String] = HashMap(), - hostMap: HashMap[String, Client] = HashMap(), + httpHeaders: mutable.HashMap[String, String] = mutable.HashMap(), + hostMap: mutable.HashMap[String, Client] = mutable.HashMap(), asyncHttpClient: Boolean = false, authScheme: String = "", - authPreemptive: Boolean = false) { + authPreemptive: Boolean = false +) { - var defaultHeaders: HashMap[String, String] = httpHeaders + var defaultHeaders: mutable.HashMap[String, String] = httpHeaders def escape(value: String): String = { URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20") @@ -68,11 +69,8 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, } def escape(value: Long): String = value.toString - def escape(value: Double): String = value.toString - def escape(value: Float): String = value.toString - def escape(value: UUID): String = value.toString def deserialize(json: String, containerType: String, cls: Class[_]) = { @@ -89,16 +87,16 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, } else { containerType.toLowerCase match { case "array" => - val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls) + val typeInfo = mapper.getTypeFactory.constructCollectionType(classOf[java.util.List[_]], cls) val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]] response.asScala.toList case "list" => - val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls) + val typeInfo = mapper.getTypeFactory.constructCollectionType(classOf[java.util.List[_]], cls) val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]] response.asScala.toList case _ => json match { - case e: String if ("\"\"" == e) => null + case e: String if "\"\"" == e => null case _ => mapper.readValue(json, cls) } } @@ -111,16 +109,27 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, case e: List[_] => mapper.writeValueAsString(obj.asInstanceOf[List[_]].asJava) case _ => mapper.writeValueAsString(obj) } - } else null + } else { + null + } } - def invokeApi(host: String, path: String, method: String, queryParams: Map[String, String], formParams: Map[String, String], body: AnyRef, headerParams: Map[String, String], contentType: String): String = { + def invokeApi( + host: String, + path: String, + method: String, + queryParams: Map[String, String], + formParams: Map[String, String], + body: AnyRef, + headerParams: Map[String, String], + contentType: String +): String = { val client = getClient(host) - val querystring = queryParams.filter(k => k._2 != null).map(k => (escape(k._1) + "=" + escape(k._2))).mkString("?", "&", "") + val querystring = queryParams.filter(k => k._2 != null).map(k => escape(k._1) + "=" + escape(k._2)).mkString("?", "&", "") val builder = client.resource(host + path + querystring).accept(contentType) headerParams.map(p => builder.header(p._1, p._2)) - defaultHeaders.map(p => { + defaultHeaders.foreach(p => { headerParams.contains(p._1) match { case true => // override default with supplied header case false => if (p._2 != null) builder.header(p._1, p._2) @@ -129,18 +138,18 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, var formData: MultivaluedMapImpl = null if (contentType == "application/x-www-form-urlencoded") { formData = new MultivaluedMapImpl() - formParams.map(p => formData.add(p._1, p._2)) + formParams.foreach(p => formData.add(p._1, p._2)) } val response: ClientResponse = method match { case "GET" => builder.get(classOf[ClientResponse]).asInstanceOf[ClientResponse] case "POST" => - if (formData != null) { - builder.post(classOf[ClientResponse], formData) + if (formData != null && formData.size() > 0) { + builder.post(classOf[ClientResponse], formData) } else if (body != null && body.isInstanceOf[File]) { val file = body.asInstanceOf[File] val form = new FormDataMultiPart() - form.field("filename", file.getName()) + form.field("filename", file.getName) form.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE)) builder.post(classOf[ClientResponse], form) } else { @@ -151,36 +160,37 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, } } case "PUT" => - if (formData != null) builder.post(classOf[ClientResponse], formData) - else if (body == null) builder.put(classOf[ClientResponse], null) - else builder.`type`(contentType).put(classOf[ClientResponse], serialize(body)) - case "DELETE" => builder.delete(classOf[ClientResponse]) - case "PATCH" => { if (formData != null) { - builder.header("X-HTTP-Method-Override", "PATCH").post(classOf[ClientResponse], formData) + builder.post(classOf[ClientResponse], formData) } else if (body == null) { + builder.put(classOf[ClientResponse], null) + } else { + builder.`type`(contentType).put(classOf[ClientResponse], serialize(body)) + } + case "DELETE" => builder.delete(classOf[ClientResponse]) + case "PATCH" => + if(formData != null) { + builder.header("X-HTTP-Method-Override", "PATCH").post(classOf[ClientResponse], formData) + } else if(body == null) { builder.header("X-HTTP-Method-Override", "PATCH").post(classOf[ClientResponse], null) } else { builder.header("X-HTTP-Method-Override", "PATCH").`type`(contentType).post(classOf[ClientResponse], serialize(body)) } - } case _ => null } - response.getStatusInfo().getStatusCode() match { + response.getStatusInfo.getStatusCode match { case 204 => "" - case code: Int if (Range(200, 299).contains(code)) => - response.hasEntity() match { + case code: Int if Range(200, 299).contains(code) => + response.hasEntity match { case true => response.getEntity(classOf[String]) case false => "" } case _ => - val entity = response.hasEntity() match { + val entity = response.hasEntity match { case true => response.getEntity(classOf[String]) case false => "no data" } - throw new ApiException( - response.getStatusInfo().getStatusCode(), - entity) + throw new ApiException(response.getStatusInfo.getStatusCode, entity) } } @@ -192,7 +202,7 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, // client.addFilter(new LoggingFilter()) hostMap += host -> client client - } + } } def newClient(host: String): Client = asyncHttpClient match { @@ -204,9 +214,10 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, val config: DefaultAhcConfig = new DefaultAhcConfig() if (!authScheme.isEmpty) { val authSchemeEnum = Realm.AuthScheme.valueOf(authScheme) - config.getAsyncHttpClientConfigBuilder + config + .getAsyncHttpClientConfigBuilder .setRealm(new Realm.RealmBuilder().setScheme(authSchemeEnum) - .setUsePreemptiveAuth(authPreemptive).build) + .setUsePreemptiveAuth(authPreemptive).build) } AhcHttpClient.create(config) case _ => Client.create() @@ -215,8 +226,8 @@ class ApiInvoker(val mapper: ObjectMapper = ScalaJsonUtil.getJsonMapper, object ApiInvoker extends ApiInvoker( mapper = ScalaJsonUtil.getJsonMapper, - httpHeaders = HashMap(), - hostMap = HashMap(), + httpHeaders = mutable.HashMap(), + hostMap = mutable.HashMap(), asyncHttpClient = false, authScheme = "", authPreemptive = false diff --git a/samples/client/petstore-security-test/scala/src/main/scala/io/swagger/client/api/FakeApi.scala b/samples/client/petstore-security-test/scala/src/main/scala/io/swagger/client/api/FakeApi.scala index 83acded275f..05a73b29609 100644 --- a/samples/client/petstore-security-test/scala/src/main/scala/io/swagger/client/api/FakeApi.scala +++ b/samples/client/petstore-security-test/scala/src/main/scala/io/swagger/client/api/FakeApi.scala @@ -40,8 +40,10 @@ import scala.concurrent._ import scala.concurrent.duration._ import scala.util.{Failure, Success, Try} -class FakeApi(val defBasePath: String = "https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r", - defApiInvoker: ApiInvoker = ApiInvoker) { +class FakeApi( + val defBasePath: String = "https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r", + defApiInvoker: ApiInvoker = ApiInvoker +) { implicit val formats = new org.json4s.DefaultFormats { override def dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+0000") @@ -53,10 +55,12 @@ class FakeApi(val defBasePath: String = "https://petstore.swagger.io *_/ ' \" =e implicit val stringWriter = RequestWriters.StringWriter implicit val jsonWriter = JsonFormatsWriter - var basePath = defBasePath - var apiInvoker = defApiInvoker + var basePath: String = defBasePath + var apiInvoker: ApiInvoker = defApiInvoker - def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value + def addHeader(key: String, value: String): mutable.HashMap[String, String] = { + apiInvoker.defaultHeaders += key -> value + } val config = SwaggerConfig.forUrl(new URI(defBasePath)) val client = new RestClient(config) @@ -86,7 +90,6 @@ class FakeApi(val defBasePath: String = "https://petstore.swagger.io *_/ ' \" =e helper.testCodeInject * ' " =end rn n r(testCodeInjectEndRnNR) } - } class FakeApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) { diff --git a/samples/client/petstore-security-test/typescript-angular/.gitignore b/samples/client/petstore-security-test/typescript-angular/.gitignore index 35e2fb2b02e..149b5765472 100644 --- a/samples/client/petstore-security-test/typescript-angular/.gitignore +++ b/samples/client/petstore-security-test/typescript-angular/.gitignore @@ -1,3 +1,4 @@ wwwroot/*.js node_modules typings +dist diff --git a/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION b/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION index 6b4d1577382..f9f7450d135 100644 --- a/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION +++ b/samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION @@ -1 +1 @@ -2.2.3 \ No newline at end of file +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular/api.module.ts b/samples/client/petstore-security-test/typescript-angular/api.module.ts index daa111453ca..c3bde487bc4 100644 --- a/samples/client/petstore-security-test/typescript-angular/api.module.ts +++ b/samples/client/petstore-security-test/typescript-angular/api.module.ts @@ -1,7 +1,21 @@ -import * as api from './api/api'; -import * as angular from 'angular'; +import { NgModule, ModuleWithProviders } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { HttpModule } from '@angular/http'; +import { Configuration } from './configuration'; -const apiModule = angular.module('api', []) -.service('FakeApi', api.FakeApi) +import { FakeService } from './api/fake.service'; -export default apiModule; +@NgModule({ + imports: [ CommonModule, HttpModule ], + declarations: [], + exports: [], + providers: [ FakeService ] +}) +export class ApiModule { + public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders { + return { + ngModule: ApiModule, + providers: [ {provide: Configuration, useFactory: configurationFactory}] + } + } +} diff --git a/samples/client/petstore-security-test/typescript-angular/api/api.ts b/samples/client/petstore-security-test/typescript-angular/api/api.ts index 4c0b3c9f56b..1457e1d01f4 100644 --- a/samples/client/petstore-security-test/typescript-angular/api/api.ts +++ b/samples/client/petstore-security-test/typescript-angular/api/api.ts @@ -1,3 +1,3 @@ -export * from './FakeApi'; -import { FakeApi } from './FakeApi'; -export const APIS = [FakeApi]; +export * from './fake.service'; +import { FakeService } from './fake.service'; +export const APIS = [FakeService]; diff --git a/samples/client/petstore-security-test/typescript-angular/index.ts b/samples/client/petstore-security-test/typescript-angular/index.ts index 557365516ad..c312b70fa3e 100644 --- a/samples/client/petstore-security-test/typescript-angular/index.ts +++ b/samples/client/petstore-security-test/typescript-angular/index.ts @@ -1,2 +1,5 @@ export * from './api/api'; -export * from './model/models'; \ No newline at end of file +export * from './model/models'; +export * from './variables'; +export * from './configuration'; +export * from './api.module'; \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular/model/ModelReturn.ts b/samples/client/petstore-security-test/typescript-angular/model/ModelReturn.ts index 0440a6393c6..e2360156a9d 100644 --- a/samples/client/petstore-security-test/typescript-angular/model/ModelReturn.ts +++ b/samples/client/petstore-security-test/typescript-angular/model/ModelReturn.ts @@ -10,7 +10,7 @@ * Do not edit the class manually. */ -import * as models from './models'; + /** * Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r @@ -19,6 +19,8 @@ export interface ModelReturn { /** * property description *_/ ' \" =end -- \\r\\n \\n \\r */ - "return"?: number; + return?: number; + } + diff --git a/samples/client/petstore-security-test/typescript-angular/model/models.ts b/samples/client/petstore-security-test/typescript-angular/model/models.ts index df8a2d48008..bca4c78d6b0 100644 --- a/samples/client/petstore-security-test/typescript-angular/model/models.ts +++ b/samples/client/petstore-security-test/typescript-angular/model/models.ts @@ -1 +1 @@ -export * from './ModelReturn'; +export * from './modelReturn'; diff --git a/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION b/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION index 7fea99011a6..f9f7450d135 100644 --- a/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION +++ b/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION @@ -1 +1 @@ -2.2.3-SNAPSHOT \ No newline at end of file +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular2/api.module.ts b/samples/client/petstore-security-test/typescript-angular2/api.module.ts index 4ed0510d0d1..c3bde487bc4 100644 --- a/samples/client/petstore-security-test/typescript-angular2/api.module.ts +++ b/samples/client/petstore-security-test/typescript-angular2/api.module.ts @@ -12,10 +12,10 @@ import { FakeService } from './api/fake.service'; providers: [ FakeService ] }) export class ApiModule { - public static forConfig(configuration: Configuration): ModuleWithProviders { + public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders { return { ngModule: ApiModule, - providers: [ {provide: Configuration, useValue: configuration}] + providers: [ {provide: Configuration, useFactory: configurationFactory}] } } } diff --git a/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts b/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts index ec12093e92c..ec51d332251 100644 --- a/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts +++ b/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts @@ -10,10 +10,10 @@ * Do not edit the class manually. */ +/* tslint:disable:no-unused-variable member-ordering */ + import { Inject, Injectable, Optional } from '@angular/core'; -import { Http, Headers, URLSearchParams } from '@angular/http'; -import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; -import { Response, ResponseContentType } from '@angular/http'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import '../rxjs-operators'; @@ -21,41 +21,26 @@ import '../rxjs-operators'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; - -/* tslint:disable:no-unused-variable member-ordering */ +import { CustomHttpUrlEncodingCodec } from '../encoder'; @Injectable() export class FakeService { - protected basePath = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); - constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + protected basePath = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; + public defaultHeaders = new HttpHeaders(); + public configuration = new Configuration(); + + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { this.basePath = basePath; } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -70,21 +55,6 @@ export class FakeService { return false; } - /** - * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r - * - * @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r - */ - public testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, extraHttpRequestParams?: any): Observable<{}> { - return this.testCodeInjectEndRnNRWithHttpInfo(test code inject * ' " =end rn n r, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } /** @@ -92,47 +62,37 @@ export class FakeService { * * @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r */ - public testCodeInjectEndRnNRWithHttpInfo(test code inject * ' " =end rn n r?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/fake'; + public testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string): Observable<{}> { - let queryParameters = new URLSearchParams(); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headers = this.defaultHeaders; // to determine the Content-Type header let consumes: string[] = [ - 'application/json', + 'application/json', '*_/ =end -- ' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + let convertFormParamsToString = false; + if (useForm) { + formParams = new FormData(); + } else { + formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); + } + - // to determine the Accept header - let produces: string[] = [ - 'application/json', - '*_/ =end -- ' - ]; - if (test code inject * ' " =end rn n r !== undefined) { - formParams.set('test code inject */ ' " =end -- \r\n \n \r', test code inject * ' " =end rn n r); + formParams = formParams.append('test code inject */ ' " =end -- \r\n \n \r', test code inject * ' " =end rn n r) || formParams; } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, + return this.httpClient.put(`${this.basePath}/fake`, + convertFormParamsToString ? formParams.toString() : formParams, { headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } } diff --git a/samples/client/petstore-security-test/typescript-angular2/configuration.ts b/samples/client/petstore-security-test/typescript-angular2/configuration.ts index 0eed43fd575..005c3a26df3 100644 --- a/samples/client/petstore-security-test/typescript-angular2/configuration.ts +++ b/samples/client/petstore-security-test/typescript-angular2/configuration.ts @@ -2,18 +2,18 @@ export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string; + accessToken?: string | (() => string); basePath?: string; withCredentials?: boolean; } export class Configuration { - apiKeys: {[ key: string ]: string}; - username: string; - password: string; - accessToken: string | (() => string); - basePath: string; - withCredentials: boolean; + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + accessToken?: string | (() => string); + basePath?: string; + withCredentials?: boolean; constructor(configurationParameters: ConfigurationParameters = {}) { this.apiKeys = configurationParameters.apiKeys; diff --git a/samples/client/petstore-security-test/typescript-angular2/model/ModelReturn.ts b/samples/client/petstore-security-test/typescript-angular2/model/ModelReturn.ts index 170661be61a..e2360156a9d 100644 --- a/samples/client/petstore-security-test/typescript-angular2/model/ModelReturn.ts +++ b/samples/client/petstore-security-test/typescript-angular2/model/ModelReturn.ts @@ -22,3 +22,5 @@ export interface ModelReturn { return?: number; } + + diff --git a/samples/client/petstore-security-test/typescript-angular2/variables.ts b/samples/client/petstore-security-test/typescript-angular2/variables.ts index b734b2e5918..6fe58549f39 100644 --- a/samples/client/petstore-security-test/typescript-angular2/variables.ts +++ b/samples/client/petstore-security-test/typescript-angular2/variables.ts @@ -1,4 +1,4 @@ -import { InjectionToken } from '@angular/core'; +import { InjectionToken } from '@angular/core'; export const BASE_PATH = new InjectionToken('basePath'); export const COLLECTION_FORMATS = { @@ -6,4 +6,4 @@ export const COLLECTION_FORMATS = { 'tsv': ' ', 'ssv': ' ', 'pipes': '|' -} \ No newline at end of file +} diff --git a/samples/client/petstore-security-test/typescript-fetch/api.ts b/samples/client/petstore-security-test/typescript-fetch/api.ts index 7e8b409725e..5146ea641b6 100644 --- a/samples/client/petstore-security-test/typescript-fetch/api.ts +++ b/samples/client/petstore-security-test/typescript-fetch/api.ts @@ -10,7 +10,7 @@ * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ - + import * as url from "url"; import * as isomorphicFetch from "isomorphic-fetch"; @@ -18,7 +18,11 @@ import { Configuration } from "./configuration"; const BASE_PATH = "https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r".replace(/\/+$/, ""); -const COLLECTION_FORMATS = { +/** + * + * @export + */ +export const COLLECTION_FORMATS = { csv: ",", ssv: " ", tsv: "\t", @@ -102,26 +106,28 @@ export const FakeApiFetchParamCreator = function (configuration?: Configuration) * @throws {RequiredError} */ testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, options: any = {}): FetchArgs { - const path = `/fake`; - const urlObj = url.parse(path, true); - const requestOptions = Object.assign({ method: 'PUT' }, options); - const headerParameter = {} as any; - const queryParameter = {} as any; - const formParams = new url.URLSearchParams(); + const localVarPath = `/fake`; + const localVarUrlObj = url.parse(localVarPath, true); + const localVarRequestOptions = Object.assign({ method: 'PUT' }, options); + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + const localVarFormParams = new url.URLSearchParams(); if (test code inject * ' " =end rn n r !== undefined) { - formParams.set('test code inject */ ' " =end -- \r\n \n \r', test code inject * ' " =end rn n r as any); + localVarFormParams.set('test code inject */ ' " =end -- \r\n \n \r', test code inject * ' " =end rn n r as any); } - headerParameter['Content-Type'] = 'application/x-www-form-urlencoded'; + localVarHeaderParameter['Content-Type'] = 'application/x-www-form-urlencoded'; - urlObj.query = Object.assign({}, urlObj.query, queryParameter, options.query); - requestOptions.headers = Object.assign({}, headerParameter, options.headers); - requestOptions.body = formParams.toString(); + localVarUrlObj.query = Object.assign({}, localVarUrlObj.query, localVarQueryParameter, options.query); + // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943 + delete localVarUrlObj.search; + localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers); + localVarRequestOptions.body = localVarFormParams.toString(); return { - url: url.format(urlObj), - options: requestOptions, + url: url.format(localVarUrlObj), + options: localVarRequestOptions, }; }, } @@ -141,9 +147,9 @@ export const FakeApiFp = function(configuration?: Configuration) { * @throws {RequiredError} */ testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise { - const fetchArgs = FakeApiFetchParamCreator(configuration).testCodeInjectEndRnNR(test code inject * ' " =end rn n r, options); + const localVarFetchArgs = FakeApiFetchParamCreator(configuration).testCodeInjectEndRnNR(test code inject * ' " =end rn n r, options); return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => { - return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => { + return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => { if (response.status >= 200 && response.status < 300) { return response; } else { diff --git a/samples/client/petstore-security-test/typescript-fetch/configuration.ts b/samples/client/petstore-security-test/typescript-fetch/configuration.ts index 8dd6dd60c63..06288872871 100644 --- a/samples/client/petstore-security-test/typescript-fetch/configuration.ts +++ b/samples/client/petstore-security-test/typescript-fetch/configuration.ts @@ -10,7 +10,7 @@ * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ - + export interface ConfigurationParameters { apiKey?: string | ((name: string) => string); diff --git a/samples/client/petstore-security-test/typescript-fetch/index.ts b/samples/client/petstore-security-test/typescript-fetch/index.ts index bcb691f7489..2670610eb94 100644 --- a/samples/client/petstore-security-test/typescript-fetch/index.ts +++ b/samples/client/petstore-security-test/typescript-fetch/index.ts @@ -10,7 +10,7 @@ * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ - + export * from "./api"; export * from "./configuration"; diff --git a/samples/client/petstore-security-test/typescript-node/api.ts b/samples/client/petstore-security-test/typescript-node/api.ts index 47fb8499ec1..dbc8f6e5c4b 100644 --- a/samples/client/petstore-security-test/typescript-node/api.ts +++ b/samples/client/petstore-security-test/typescript-node/api.ts @@ -269,8 +269,8 @@ export class FakeApi { this.authentications.petstore_auth.accessToken = token; } /** - * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * + * @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r */ public testCodeInjectEndRnNR (test code inject * ' " =end rn n r?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { @@ -280,7 +280,6 @@ export class FakeApi { let formParams: any = {}; - let useFormData = false; if (test code inject * ' " =end rn n r !== undefined) { diff --git a/samples/server/petstore-security-test/silex/SwaggerServer/index.php b/samples/server/petstore-security-test/silex/SwaggerServer/index.php index 23edb3a670c..7be322ca7ea 100644 --- a/samples/server/petstore-security-test/silex/SwaggerServer/index.php +++ b/samples/server/petstore-security-test/silex/SwaggerServer/index.php @@ -9,7 +9,7 @@ $app = new Silex\Application(); $app->PUT('/v2 *_/ ' \" =end -- \\r\\n \\n \\r/fake', function(Application $app, Request $request) { - $test code inject */ ' " =end __ \r\n \n \r = $request->get('test code inject */ ' " =end __ \r\n \n \r'); + $test_code_inject_*/_'_"_=end____\r\n_\n_\r = $request->get('test_code_inject_*/_'_"_=end____\r\n_\n_\r'); return new Response('How about implementing testCodeInject */ ' " =end \r\n \n \r as a PUT method ?'); });