diff --git a/.gitignore b/.gitignore index 370da9c3256..7be184f11ba 100644 --- a/.gitignore +++ b/.gitignore @@ -142,7 +142,6 @@ samples/client/petstore/typescript-node/npm/node_modules samples/client/petstore/typescript-node/**/typings samples/client/petstore/typescript-angular/**/typings samples/client/petstore/typescript-fetch/**/dist/ -samples/client/petstore/typescript-fetch/**/typings samples/client/petstore/typescript-angular2/npm/npm-debug.log samples/client/petstore/typescript-node/npm/npm-debug.log diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptFetchClientCodegen.java index a6449587ac3..f8c00eaadb3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptFetchClientCodegen.java @@ -38,7 +38,6 @@ public void processOpts() { supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); supportingFiles.add(new SupportingFile("README.md", "", "README.md")); supportingFiles.add(new SupportingFile("package.json.mustache", "", "package.json")); - supportingFiles.add(new SupportingFile("typings.json.mustache", "", "typings.json")); supportingFiles.add(new SupportingFile("tsconfig.json.mustache", "", "tsconfig.json")); supportingFiles.add(new SupportingFile("tslint.json.mustache", "", "tslint.json")); supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore")); diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/README.md b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/README.md index 664e1755933..2a1a4d7740c 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/README.md +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/README.md @@ -15,11 +15,11 @@ Module system * CommonJS * ES6 module system -It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html)) +It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html)) ### Installation ### -`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`. +`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`. CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`. diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache index 88db5deda9d..b0f0b337357 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache @@ -46,7 +46,7 @@ export type {{{classname}}} = {{#allowableValues}}{{#values}}"{{{.}}}"{{^-last}} * {{{description}}} */ {{/description}} - "{{name}}"{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; + "{{baseName}}"{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; {{/vars}} {{^isEnum}} } @@ -100,12 +100,24 @@ export const {{classname}}FetchParamCreator = { let contentTypeHeader: Dictionary = {}; {{#hasFormParams}} - contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; - fetchOptions.body = querystring.stringify({ - {{#formParams}} - "{{baseName}}": params["{{paramName}}"], - {{/formParams}} - }); + let formData: Dictionary = {}; + let isMultipartData = false; +{{#formParams}} + {{#isFile}}isMultipartData = true; + {{/isFile}}formData["{{baseName}}"] = params["{{paramName}}"]; +{{/formParams}} + + if (isMultipartData) { + let body = new FormData(); + for (let key in formData) { + body.append(key, formData[key]); + } + fetchOptions.body = body; + } + else { + fetchOptions.body = querystring.stringify(formData); + contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; + } {{/hasFormParams}} {{#hasBodyParam}} contentTypeHeader = { "Content-Type": "application/json" };{{#bodyParam}} diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/gitignore b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/gitignore index 35e2fb2b02e..1ce70fb9321 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/gitignore +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/gitignore @@ -1,3 +1,2 @@ wwwroot/*.js node_modules -typings diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/package.json.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/package.json.mustache index 05aec69d7ec..3ef820c300d 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/package.json.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/package.json.mustache @@ -6,16 +6,18 @@ "browser": "./dist/api.js", "typings": "./dist/api.d.ts", "dependencies": { - {{^supportsES6}}"core-js": "^2.4.0", - {{/supportsES6}}"isomorphic-fetch": "^2.2.1" + "@types/node": "6.0.46", + "@types/isomorphic-fetch": "0.0.33",{{^supportsES6}} + "@types/core-js": "0.9.35", + "core-js": "2.4.1",{{/supportsES6}} + "isomorphic-fetch": "2.2.1" }, "scripts" : { - "prepublish" : "typings install && tsc", + "prepublish" : "tsc", "test": "tslint api.ts" }, "devDependencies": { "tslint": "^3.15.1", - "typescript": "^1.8.10", - "typings": "^1.0.4" + "typescript": "^2.0.7" } } diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/tsconfig.json.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/tsconfig.json.mustache index 25f414e9840..08e2e596dbe 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/tsconfig.json.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/tsconfig.json.mustache @@ -9,9 +9,6 @@ }, "exclude": [ "dist", - "node_modules", - "typings/browser", - "typings/main", - "typings/main.d.ts" + "node_modules" ] } diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/typings.json.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/typings.json.mustache deleted file mode 100644 index e5bd78f06fe..00000000000 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/typings.json.mustache +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": false, - "dependencies": {}, - "globalDependencies": { {{^supportsES6}} - "core-js": "registry:dt/core-js#0.0.0+20160317120654",{{/supportsES6}} - "node": "registry:dt/node#4.0.0+20160423143914", - "isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433" - } -} diff --git a/samples/client/petstore/typescript-fetch/builds/default/.gitignore b/samples/client/petstore/typescript-fetch/builds/default/.gitignore index 35e2fb2b02e..1ce70fb9321 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/.gitignore +++ b/samples/client/petstore/typescript-fetch/builds/default/.gitignore @@ -1,3 +1,2 @@ wwwroot/*.js node_modules -typings diff --git a/samples/client/petstore/typescript-fetch/builds/default/README.md b/samples/client/petstore/typescript-fetch/builds/default/README.md index 664e1755933..2a1a4d7740c 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/README.md +++ b/samples/client/petstore/typescript-fetch/builds/default/README.md @@ -15,11 +15,11 @@ Module system * CommonJS * ES6 module system -It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html)) +It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html)) ### Installation ### -`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`. +`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`. CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`. diff --git a/samples/client/petstore/typescript-fetch/builds/default/api.ts b/samples/client/petstore/typescript-fetch/builds/default/api.ts index 1ab5a830727..bae16464a5a 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/api.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/api.ts @@ -249,11 +249,22 @@ export const PetApiFetchParamCreator = { let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); let contentTypeHeader: Dictionary = {}; - contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; - fetchOptions.body = querystring.stringify({ - "name": params["name"], - "status": params["status"], - }); + let formData: Dictionary = {}; + let isMultipartData = false; + formData["name"] = params["name"]; + formData["status"] = params["status"]; + + if (isMultipartData) { + let body = new FormData(); + for (let key in formData) { + body.append(key, formData[key]); + } + fetchOptions.body = body; + } + else { + fetchOptions.body = querystring.stringify(formData); + contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; + } if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -280,11 +291,23 @@ export const PetApiFetchParamCreator = { let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); let contentTypeHeader: Dictionary = {}; - contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; - fetchOptions.body = querystring.stringify({ - "additionalMetadata": params["additionalMetadata"], - "file": params["file"], - }); + let formData: Dictionary = {}; + let isMultipartData = false; + formData["additionalMetadata"] = params["additionalMetadata"]; + isMultipartData = true; + formData["file"] = params["file"]; + + if (isMultipartData) { + let body = new FormData(); + for (let key in formData) { + body.append(key, formData[key]); + } + fetchOptions.body = body; + } + else { + fetchOptions.body = querystring.stringify(formData); + contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; + } if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } diff --git a/samples/client/petstore/typescript-fetch/builds/default/package.json b/samples/client/petstore/typescript-fetch/builds/default/package.json index 0204e3c39c9..a1accf5df25 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/package.json +++ b/samples/client/petstore/typescript-fetch/builds/default/package.json @@ -6,16 +6,18 @@ "browser": "./dist/api.js", "typings": "./dist/api.d.ts", "dependencies": { - "core-js": "^2.4.0", - "isomorphic-fetch": "^2.2.1" + "@types/node": "6.0.46", + "@types/isomorphic-fetch": "0.0.33", + "@types/core-js": "0.9.35", + "core-js": "2.4.1", + "isomorphic-fetch": "2.2.1" }, "scripts" : { - "prepublish" : "typings install && tsc", + "prepublish" : "tsc", "test": "tslint api.ts" }, "devDependencies": { "tslint": "^3.15.1", - "typescript": "^1.8.10", - "typings": "^1.0.4" + "typescript": "^2.0.7" } } diff --git a/samples/client/petstore/typescript-fetch/builds/default/tsconfig.json b/samples/client/petstore/typescript-fetch/builds/default/tsconfig.json index 72ff2567206..1a36def5fe7 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/tsconfig.json +++ b/samples/client/petstore/typescript-fetch/builds/default/tsconfig.json @@ -9,9 +9,6 @@ }, "exclude": [ "dist", - "node_modules", - "typings/browser", - "typings/main", - "typings/main.d.ts" + "node_modules" ] } diff --git a/samples/client/petstore/typescript-fetch/builds/default/typings.json b/samples/client/petstore/typescript-fetch/builds/default/typings.json deleted file mode 100644 index a82ea152b4a..00000000000 --- a/samples/client/petstore/typescript-fetch/builds/default/typings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": false, - "dependencies": {}, - "globalDependencies": { - "core-js": "registry:dt/core-js#0.0.0+20160317120654", - "node": "registry:dt/node#4.0.0+20160423143914", - "isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433" - } -} diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/.gitignore b/samples/client/petstore/typescript-fetch/builds/es6-target/.gitignore index 35e2fb2b02e..1ce70fb9321 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/.gitignore +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/.gitignore @@ -1,3 +1,2 @@ wwwroot/*.js node_modules -typings diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/README.md b/samples/client/petstore/typescript-fetch/builds/es6-target/README.md index 664e1755933..2a1a4d7740c 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/README.md +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/README.md @@ -15,11 +15,11 @@ Module system * CommonJS * ES6 module system -It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html)) +It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html)) ### Installation ### -`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`. +`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`. CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`. diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/api.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/api.ts index 5b787dc84bb..97cf826c578 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/api.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/api.ts @@ -248,11 +248,22 @@ export const PetApiFetchParamCreator = { let fetchOptions: RequestInit = Object.assign({}, { method: "POST" }, options); let contentTypeHeader: Dictionary = {}; - contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; - fetchOptions.body = querystring.stringify({ - "name": params["name"], - "status": params["status"], - }); + let formData: Dictionary = {}; + let isMultipartData = false; + formData["name"] = params["name"]; + formData["status"] = params["status"]; + + if (isMultipartData) { + let body = new FormData(); + for (let key in formData) { + body.append(key, formData[key]); + } + fetchOptions.body = body; + } + else { + fetchOptions.body = querystring.stringify(formData); + contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; + } if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -279,11 +290,23 @@ export const PetApiFetchParamCreator = { let fetchOptions: RequestInit = Object.assign({}, { method: "POST" }, options); let contentTypeHeader: Dictionary = {}; - contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; - fetchOptions.body = querystring.stringify({ - "additionalMetadata": params["additionalMetadata"], - "file": params["file"], - }); + let formData: Dictionary = {}; + let isMultipartData = false; + formData["additionalMetadata"] = params["additionalMetadata"]; + isMultipartData = true; + formData["file"] = params["file"]; + + if (isMultipartData) { + let body = new FormData(); + for (let key in formData) { + body.append(key, formData[key]); + } + fetchOptions.body = body; + } + else { + fetchOptions.body = querystring.stringify(formData); + contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; + } if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/package.json b/samples/client/petstore/typescript-fetch/builds/es6-target/package.json index 9797e3483f9..eb36757a032 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/package.json +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/package.json @@ -6,15 +6,16 @@ "browser": "./dist/api.js", "typings": "./dist/api.d.ts", "dependencies": { - "isomorphic-fetch": "^2.2.1" + "@types/node": "6.0.46", + "@types/isomorphic-fetch": "0.0.33", + "isomorphic-fetch": "2.2.1" }, "scripts" : { - "prepublish" : "typings install && tsc", + "prepublish" : "tsc", "test": "tslint api.ts" }, "devDependencies": { "tslint": "^3.15.1", - "typescript": "^1.8.10", - "typings": "^1.0.4" + "typescript": "^2.0.7" } } diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/tsconfig.json b/samples/client/petstore/typescript-fetch/builds/es6-target/tsconfig.json index 06a8e0437b9..a2f16303408 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/tsconfig.json +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/tsconfig.json @@ -9,9 +9,6 @@ }, "exclude": [ "dist", - "node_modules", - "typings/browser", - "typings/main", - "typings/main.d.ts" + "node_modules" ] } diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/typings.json b/samples/client/petstore/typescript-fetch/builds/es6-target/typings.json deleted file mode 100644 index 2ec50862694..00000000000 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/typings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": false, - "dependencies": {}, - "globalDependencies": { - "node": "registry:dt/node#4.0.0+20160423143914", - "isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433" - } -} diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/.gitignore b/samples/client/petstore/typescript-fetch/builds/with-npm-version/.gitignore index 35e2fb2b02e..1ce70fb9321 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/.gitignore +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/.gitignore @@ -1,3 +1,2 @@ wwwroot/*.js node_modules -typings diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/README.md b/samples/client/petstore/typescript-fetch/builds/with-npm-version/README.md index 664e1755933..2a1a4d7740c 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/README.md +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/README.md @@ -15,11 +15,11 @@ Module system * CommonJS * ES6 module system -It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html)) +It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html)) ### Installation ### -`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`. +`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`. CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`. diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/api.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/api.ts index 1ab5a830727..bae16464a5a 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/api.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/api.ts @@ -249,11 +249,22 @@ export const PetApiFetchParamCreator = { let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); let contentTypeHeader: Dictionary = {}; - contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; - fetchOptions.body = querystring.stringify({ - "name": params["name"], - "status": params["status"], - }); + let formData: Dictionary = {}; + let isMultipartData = false; + formData["name"] = params["name"]; + formData["status"] = params["status"]; + + if (isMultipartData) { + let body = new FormData(); + for (let key in formData) { + body.append(key, formData[key]); + } + fetchOptions.body = body; + } + else { + fetchOptions.body = querystring.stringify(formData); + contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; + } if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } @@ -280,11 +291,23 @@ export const PetApiFetchParamCreator = { let fetchOptions: RequestInit = assign({}, { method: "POST" }, options); let contentTypeHeader: Dictionary = {}; - contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; - fetchOptions.body = querystring.stringify({ - "additionalMetadata": params["additionalMetadata"], - "file": params["file"], - }); + let formData: Dictionary = {}; + let isMultipartData = false; + formData["additionalMetadata"] = params["additionalMetadata"]; + isMultipartData = true; + formData["file"] = params["file"]; + + if (isMultipartData) { + let body = new FormData(); + for (let key in formData) { + body.append(key, formData[key]); + } + fetchOptions.body = body; + } + else { + fetchOptions.body = querystring.stringify(formData); + contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" }; + } if (contentTypeHeader) { fetchOptions.headers = contentTypeHeader; } diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/package.json b/samples/client/petstore/typescript-fetch/builds/with-npm-version/package.json index f4c8ca8a162..0dfa342750a 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/package.json +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/package.json @@ -6,16 +6,18 @@ "browser": "./dist/api.js", "typings": "./dist/api.d.ts", "dependencies": { - "core-js": "^2.4.0", - "isomorphic-fetch": "^2.2.1" + "@types/node": "6.0.46", + "@types/isomorphic-fetch": "0.0.33", + "@types/core-js": "0.9.35", + "core-js": "2.4.1", + "isomorphic-fetch": "2.2.1" }, "scripts" : { - "prepublish" : "typings install && tsc", + "prepublish" : "tsc", "test": "tslint api.ts" }, "devDependencies": { "tslint": "^3.15.1", - "typescript": "^1.8.10", - "typings": "^1.0.4" + "typescript": "^2.0.7" } } diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/tsconfig.json b/samples/client/petstore/typescript-fetch/builds/with-npm-version/tsconfig.json index 72ff2567206..1a36def5fe7 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/tsconfig.json +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/tsconfig.json @@ -9,9 +9,6 @@ }, "exclude": [ "dist", - "node_modules", - "typings/browser", - "typings/main", - "typings/main.d.ts" + "node_modules" ] } diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/typings.json b/samples/client/petstore/typescript-fetch/builds/with-npm-version/typings.json deleted file mode 100644 index a82ea152b4a..00000000000 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/typings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": false, - "dependencies": {}, - "globalDependencies": { - "core-js": "registry:dt/core-js#0.0.0+20160317120654", - "node": "registry:dt/node#4.0.0+20160423143914", - "isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433" - } -} diff --git a/samples/client/petstore/typescript-fetch/tests/default/package.json b/samples/client/petstore/typescript-fetch/tests/default/package.json index b95b42bc29e..f692d2015b9 100644 --- a/samples/client/petstore/typescript-fetch/tests/default/package.json +++ b/samples/client/petstore/typescript-fetch/tests/default/package.json @@ -1,14 +1,17 @@ { "private": true, "dependencies": { - "chai": "^3.5.0" + "@types/chai": "^3.4.35", + "@types/core-js": "0.9.35", + "@types/mocha": "^2.2.40", + "chai": "^3.5.0", + "core-js": "2.4.1" }, "devDependencies": { - "browserify": "^13.0.1", + "browserify": "14.1.0", "ts-loader": "^0.8.2", - "tsify": "^0.16.0", - "typescript": "^1.8.10", - "typings": "^1.0.4", + "tsify": "3.0.1", + "typescript": "^2.0.7", "webpack": "^1.13.0" }, "scripts": { diff --git a/samples/client/petstore/typescript-fetch/tests/default/scripts/prepublish.sh b/samples/client/petstore/typescript-fetch/tests/default/scripts/prepublish.sh index 3c0dfb05953..94e4e063398 100755 --- a/samples/client/petstore/typescript-fetch/tests/default/scripts/prepublish.sh +++ b/samples/client/petstore/typescript-fetch/tests/default/scripts/prepublish.sh @@ -1,7 +1,6 @@ #!/bin/bash npm install ../../builds/default -typings install # Build Node.js tsc diff --git a/samples/client/petstore/typescript-fetch/tests/default/test/PetApi.ts b/samples/client/petstore/typescript-fetch/tests/default/test/PetApi.ts index 251c3f3a902..04007292d37 100644 --- a/samples/client/petstore/typescript-fetch/tests/default/test/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/tests/default/test/PetApi.ts @@ -10,6 +10,13 @@ describe('PetApi', () => { let api: PetApi; const fixture: Pet = createTestFixture(); + const parameterInspector = (...args: any[]) => { + return Promise.resolve({ + status: 200, + arguments: args + }); + }; + beforeEach(() => { api = new PetApi(); }); @@ -36,6 +43,18 @@ describe('PetApi', () => { }); }); + it('should update Pet using url-encoded form', () => { + return new PetApi(parameterInspector).updatePetWithForm({ petId: fixture.id.toString(), name: "Snoopy" }).then(({arguments: [url, init]}) => { + return expect(init.headers['Content-Type']).to.equal('application/x-www-form-urlencoded'); + }); + }); + + it('should not set a content-type header when uploading a file', () => { + return new PetApi(parameterInspector).uploadFile({ petId: fixture.id, file: new File(['snoopy'], 'Snoopy.png')}).then(({arguments: [url, init]}) => { + return expect(init.headers['Content-Type']).to.be.undefined; + }); + }); + it('should delete Pet', () => { return api.deletePet({ petId: fixture.id }, requestOptions); }); diff --git a/samples/client/petstore/typescript-fetch/tests/default/tsconfig.json b/samples/client/petstore/typescript-fetch/tests/default/tsconfig.json index e47c2647e01..dbf5d34fd48 100644 --- a/samples/client/petstore/typescript-fetch/tests/default/tsconfig.json +++ b/samples/client/petstore/typescript-fetch/tests/default/tsconfig.json @@ -5,12 +5,13 @@ "noImplicitAny": true, "sourceMap": false, "outDir": "dist", - "rootDir": "." + "rootDir": ".", + "types":[ + "mocha", + "core-js" + ] }, "exclude": [ - "node_modules", - "typings/browser", - "typings/main", - "typings/main.d.ts" + "node_modules" ] } \ No newline at end of file diff --git a/samples/client/petstore/typescript-fetch/tests/default/typings.json b/samples/client/petstore/typescript-fetch/tests/default/typings.json deleted file mode 100644 index d05709202f7..00000000000 --- a/samples/client/petstore/typescript-fetch/tests/default/typings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "typescript-fetch-test", - "version": false, - "globalDependencies": { - "chai": "registry:dt/chai#3.4.0+20160317120654", - "es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304", - "mocha": "registry:dt/mocha#2.2.5+20160317120654" - } -}