Skip to content

Commit

Permalink
[JS] set option to true by default, update samples (OpenAPITools#20003)
Browse files Browse the repository at this point in the history
* set option to true by default, update samples

* update doc
  • Loading branch information
wing328 authored Oct 31, 2024
1 parent ae4e251 commit b66b7af
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/generators/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sourceFolder|source folder for generated code| |src|
|useInheritance|use JavaScript prototype chains & delegation for inheritance| |true|
|usePromises|use Promises as return values from the client API, instead of superagent callbacks| |false|
|useURLSearchParams|use JS build-in UrlSearchParams, instead of deprecated npm lib 'querystring'| |false|
|useURLSearchParams|use JS build-in UrlSearchParams, instead of deprecated npm lib 'querystring'| |true|

## IMPORT MAPPING

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
protected boolean useES6 = true; // default is ES6
@Setter protected String npmRepository = null;
@Getter private String modelPropertyNaming = "camelCase";
@Setter protected boolean useURLSearchParams = false;
@Setter protected boolean useURLSearchParams = true;

public JavascriptClientCodegen() {
super();
Expand Down Expand Up @@ -194,7 +194,7 @@ public JavascriptClientCodegen() {
cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
cliOptions.add(new CliOption(USE_URL_SEARCH_PARAMS,
"use JS build-in UrlSearchParams, instead of deprecated npm lib 'querystring'")
.defaultValue(Boolean.FALSE.toString())
.defaultValue(Boolean.TRUE.toString())
);

supportedLibraries.put(LIBRARY_JAVASCRIPT, "JavaScript client library");
Expand Down
6 changes: 4 additions & 2 deletions samples/client/petstore/javascript-es6/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


import superagent from "superagent";
import querystring from "querystring";

/**
* @module ApiClient
Expand Down Expand Up @@ -443,7 +442,10 @@ class ApiClient {
}

if (contentType === 'application/x-www-form-urlencoded') {
request.send(querystring.stringify(this.normalizeParams(formParams)));
let normalizedParams = this.normalizeParams(formParams)
let urlSearchParams = new URLSearchParams(normalizedParams);
let queryString = urlSearchParams.toString();
request.send(queryString);
} else if (contentType == 'multipart/form-data') {
var _formParams = this.normalizeParams(formParams);
for (var key in _formParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


import superagent from "superagent";
import querystring from "querystring";

/**
* @module ApiClient
Expand Down Expand Up @@ -435,7 +434,10 @@ class ApiClient {
}

if (contentType === 'application/x-www-form-urlencoded') {
request.send(querystring.stringify(this.normalizeParams(formParams)));
let normalizedParams = this.normalizeParams(formParams)
let urlSearchParams = new URLSearchParams(normalizedParams);
let queryString = urlSearchParams.toString();
request.send(queryString);
} else if (contentType == 'multipart/form-data') {
var _formParams = this.normalizeParams(formParams);
for (var key in _formParams) {
Expand Down

0 comments on commit b66b7af

Please sign in to comment.