[TypeScript-Fetch] Support for non-JSON body params (#6994)

* Commit leftover snapshot changes

* Add logic to deal with non-JSON body params

If the spec specifies a list of consumes MIME types, default to the
first MIME type in the list instead of "application/json" (the user may
still override this by passing "Content-Type" in options.headers).

Additionally, only perform explicit JSON serialization if the data type
of the body parameter is not "string", or if it is string, only when the
content type is "application/json".

* Update snapshots
This commit is contained in:
Asad Saeeduddin
2017-12-19 04:20:16 -05:00
committed by William Cheng
parent cb59591eff
commit a3ca8d55e2
4 changed files with 49 additions and 22 deletions

View File

@@ -212,7 +212,12 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
{{/hasFormParams}}
{{#bodyParam}}
{{^consumes}}
localVarHeaderParameter['Content-Type'] = 'application/json';
{{/consumes}}
{{#consumes.0}}
localVarHeaderParameter['Content-Type'] = '{{mediaType}}';
{{/consumes.0}}
{{/bodyParam}}
localVarUrlObj.query = Object.assign({}, localVarUrlObj.query, localVarQueryParameter, options.query);
@@ -223,7 +228,8 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
localVarRequestOptions.body = localVarFormParams.toString();
{{/hasFormParams}}
{{#bodyParam}}
localVarRequestOptions.body = JSON.stringify({{paramName}} || {});
const needsSerialization = (<any>"{{dataType}}" !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';
localVarRequestOptions.body = needsSerialization ? JSON.stringify({{paramName}} || {}) : ({{paramName}} || "");
{{/bodyParam}}
return {