Update security samples for Javascript clients (#5289)

This commit is contained in:
Paŭlo Ebermann
2017-04-04 08:43:25 +02:00
committed by wing328
parent 0695a58f3c
commit 66bf83e911
8 changed files with 79 additions and 71 deletions

View File

@@ -3,14 +3,13 @@
* Do not edit this file by hand or your changes will be lost next time it is * Do not edit this file by hand or your changes will be lost next time it is
* generated. * generated.
* *
* 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 * 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 --
* Version: 1.0.0 ' \" =end * Version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Generated at: 2016-06-29T22:04:03.401+08:00 * Generated by: io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen
* Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen
*/ */
/** /**
* @license Apache 2.0 ' \" =end * @license Apache 2.0 *_/ ' \" =end -- \\r\\n \\n \\r
* http://www.apache.org/licenses/LICENSE-2.0.html ' \" =end * http://www.apache.org/licenses/LICENSE-2.0.html *_/ ' \" =end -- \\r\\n \\n \\r
*/ */
goog.provide('API.Client.FakeApi'); goog.provide('API.Client.FakeApi');
@@ -27,7 +26,7 @@ API.Client.FakeApi = function($http, $httpParamSerializer, $injector) {
/** @private {!string} */ /** @private {!string} */
this.basePath_ = $injector.has('FakeApiBasePath') ? this.basePath_ = $injector.has('FakeApiBasePath') ?
/** @type {!string} */ ($injector.get('FakeApiBasePath')) : /** @type {!string} */ ($injector.get('FakeApiBasePath')) :
'https://petstore.swagger.io ' \" =end/v2 ' \" =end'; 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r';
/** @private {!Object<string, string>} */ /** @private {!Object<string, string>} */
this.defaultHeaders_ = $injector.has('FakeApiDefaultHeaders') ? this.defaultHeaders_ = $injector.has('FakeApiDefaultHeaders') ?
@@ -44,13 +43,13 @@ API.Client.FakeApi = function($http, $httpParamSerializer, $injector) {
API.Client.FakeApi.$inject = ['$http', '$httpParamSerializer', '$injector']; API.Client.FakeApi.$inject = ['$http', '$httpParamSerializer', '$injector'];
/** /**
* To test code injection &#39; \&quot; &#x3D;end * To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
* *
* @param {!string=} opt_testCodeInjectEnd To test code injection &#39; \&quot; &#x3D;end * @param {!string=} opt_testCodeInjectEndRnNR To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
* @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send.
* @return {!angular.$q.Promise} * @return {!angular.$q.Promise}
*/ */
API.Client.FakeApi.prototype.testCodeInjectEnd = function(opt_testCodeInjectEnd, opt_extraHttpRequestParams) { API.Client.FakeApi.prototype.testCodeInjectEndRnNR = function(opt_testCodeInjectEndRnNR, opt_extraHttpRequestParams) {
/** @const {string} */ /** @const {string} */
var path = this.basePath_ + '/fake'; var path = this.basePath_ + '/fake';
@@ -64,7 +63,7 @@ API.Client.FakeApi.prototype.testCodeInjectEnd = function(opt_testCodeInjectEnd,
headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
formParams['test code inject */ &#39; &quot; &#x3D;end'] = opt_testCodeInjectEnd; formParams['test code inject */ &#39; &quot; &#x3D;end -- \r\n \n \r'] = opt_testCodeInjectEndRnNR;
/** @type {!Object} */ /** @type {!Object} */
var httpRequestParams = { var httpRequestParams = {

View File

@@ -1,13 +1,13 @@
goog.provide('API.Client.Return'); goog.provide('API.Client.Return');
/** /**
* Model for testing reserved words ' \" =end * Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r
* @record * @record
*/ */
API.Client.ModelReturn = function() {} API.Client.ModelReturn = function() {}
/** /**
* property description ' \" =end * property description *_/ ' \" =end -- \\r\\n \\n \\r
* @type {!number} * @type {!number}
* @export * @export
*/ */

View File

@@ -6,7 +6,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/
- API version: 1.0.0 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r - API version: 1.0.0 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
- Package version: 1.0.0 *_/ &#x3D;end -- \r\n \n \r - Package version: 1.0.0 *_/ &#x3D;end -- \r\n \n \r
- Build package: class io.swagger.codegen.languages.JavascriptClientCodegen - Build package: io.swagger.codegen.languages.JavascriptClientCodegen
## Installation ## Installation

View File

@@ -2,13 +2,13 @@
"name": "swagger_petstore____end____rn_n_r", "name": "swagger_petstore____end____rn_n_r",
"version": "1.0.0 *_/ =end -- \r\n \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______", "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": "Apache-2.0", "license": "Unlicense",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
"test": "./node_modules/mocha/bin/mocha --recursive" "test": "./node_modules/mocha/bin/mocha --recursive"
}, },
"dependencies": { "dependencies": {
"superagent": "1.7.1" "superagent": "3.5.2"
}, },
"devDependencies": { "devDependencies": {
"mocha": "~2.3.4", "mocha": "~2.3.4",

View File

@@ -9,34 +9,23 @@
* https://github.com/swagger-api/swagger-codegen.git * https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually. * Do not edit the class manually.
* *
* 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.
*/ */
(function(root, factory) { (function(root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module. // AMD. Register as an anonymous module.
define(['superagent'], factory); define(['superagent', 'querystring'], factory);
} else if (typeof module === 'object' && module.exports) { } else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node. // CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('superagent')); module.exports = factory(require('superagent'), require('querystring'));
} else { } else {
// Browser globals (root is window) // Browser globals (root is window)
if (!root.SwaggerPetstoreEndRnNR) { if (!root.SwaggerPetstoreEndRnNR) {
root.SwaggerPetstoreEndRnNR = {}; root.SwaggerPetstoreEndRnNR = {};
} }
root.SwaggerPetstoreEndRnNR.ApiClient = factory(root.superagent); root.SwaggerPetstoreEndRnNR.ApiClient = factory(root.superagent, root.querystring);
} }
}(this, function(superagent) { }(this, function(superagent, querystring) {
'use strict'; 'use strict';
/** /**
@@ -55,9 +44,9 @@
/** /**
* The base URL against which to resolve every API call's (relative) path. * The base URL against which to resolve every API call's (relative) path.
* @type {String} * @type {String}
* @default https://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r * @default https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r
*/ */
this.basePath = 'https://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r/v2 *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r'.replace(/\/+$/, ''); this.basePath = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'.replace(/\/+$/, '');
/** /**
* The authentication methods to be included for all API calls. * The authentication methods to be included for all API calls.
@@ -80,6 +69,30 @@
* @default 60000 * @default 60000
*/ */
this.timeout = 60000; this.timeout = 60000;
/**
* If set to false an additional timestamp parameter is added to all API GET calls to
* prevent browser caching
* @type {Boolean}
* @default true
*/
this.cache = true;
/**
* If set to true, the client will save the cookies from each server
* response, and return them in the next request.
* @default false
*/
this.enableCookies = false;
/*
* Used to save and return cookies in a node.js (non-browser) setting,
* if this.enableCookies is set to true.
*/
if (typeof window === 'undefined') {
this.agent = new superagent.agent();
}
}; };
/** /**
@@ -316,13 +329,13 @@
* @returns A value of the specified type. * @returns A value of the specified type.
*/ */
exports.prototype.deserialize = function deserialize(response, returnType) { exports.prototype.deserialize = function deserialize(response, returnType) {
if (response == null || returnType == null) { if (response == null || returnType == null || response.status == 204) {
return null; return null;
} }
// Rely on SuperAgent for parsing response body. // Rely on SuperAgent for parsing response body.
// See http://visionmedia.github.io/superagent/#parsing-response-bodies // See http://visionmedia.github.io/superagent/#parsing-response-bodies
var data = response.body; var data = response.body;
if (data == null) { if (data == null || (typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length)) {
// SuperAgent does not always produce a body; use the unparsed response as a fallback // SuperAgent does not always produce a body; use the unparsed response as a fallback
data = response.text; data = response.text;
} }
@@ -366,6 +379,9 @@
this.applyAuthToRequest(request, authNames); this.applyAuthToRequest(request, authNames);
// set query parameters // set query parameters
if (httpMethod.toUpperCase() === 'GET' && this.cache === false) {
queryParams['_'] = new Date().getTime();
}
request.query(this.normalizeParams(queryParams)); request.query(this.normalizeParams(queryParams));
// set header parameters // set header parameters
@@ -385,7 +401,7 @@
} }
if (contentType === 'application/x-www-form-urlencoded') { if (contentType === 'application/x-www-form-urlencoded') {
request.send(this.normalizeParams(formParams)); request.send(querystring.stringify(this.normalizeParams(formParams)));
} else if (contentType == 'multipart/form-data') { } else if (contentType == 'multipart/form-data') {
var _formParams = this.normalizeParams(formParams); var _formParams = this.normalizeParams(formParams);
for (var key in _formParams) { for (var key in _formParams) {
@@ -407,12 +423,33 @@
request.accept(accept); request.accept(accept);
} }
if (returnType === 'Blob') {
request.responseType('blob');
}
// Attach previously saved cookies, if enabled
if (this.enableCookies){
if (typeof window === 'undefined') {
this.agent.attachCookies(request);
}
else {
request.withCredentials();
}
}
request.end(function(error, response) { request.end(function(error, response) {
if (callback) { if (callback) {
var data = null; var data = null;
if (!error) { if (!error) {
data = _this.deserialize(response, returnType); try {
data = _this.deserialize(response, returnType);
if (_this.enableCookies && typeof window === 'undefined'){
_this.agent.saveCookies(response);
}
} catch (err) {
error = err;
}
} }
callback(error, data, response); callback(error, data, response);
} }
@@ -437,9 +474,12 @@
* or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
* return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type: * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
* all properties on <code>data<code> will be converted to this type. * all properties on <code>data<code> will be converted to this type.
* @returns An instance of the specified type. * @returns An instance of the specified type or null or undefined if data is null or undefined.
*/ */
exports.convertToType = function(data, type) { exports.convertToType = function(data, type) {
if (data === null || data === undefined)
return data
switch (type) { switch (type) {
case 'Boolean': case 'Boolean':
return Boolean(data); return Boolean(data);
@@ -451,6 +491,8 @@
return String(data); return String(data);
case 'Date': case 'Date':
return this.parseDate(String(data)); return this.parseDate(String(data));
case 'Blob':
return data;
default: default:
if (type === Object) { if (type === Object) {
// generic object, return directly // generic object, return directly

View File

@@ -9,17 +9,6 @@
* https://github.com/swagger-api/swagger-codegen.git * https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually. * Do not edit the class manually.
* *
* 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.
*/ */
(function(root, factory) { (function(root, factory) {

View File

@@ -9,17 +9,6 @@
* https://github.com/swagger-api/swagger-codegen.git * https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually. * Do not edit the class manually.
* *
* 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.
*/ */
(function(factory) { (function(factory) {

View File

@@ -9,17 +9,6 @@
* https://github.com/swagger-api/swagger-codegen.git * https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually. * Do not edit the class manually.
* *
* 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.
*/ */
(function(root, factory) { (function(root, factory) {