[JS] set option to true by default, update samples (#20003)

* set option to true by default, update samples

* update doc
This commit is contained in:
William Cheng 2024-10-31 15:01:37 +08:00 committed by GitHub
parent ae4e2515dc
commit b66b7af5d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 7 deletions

View File

@ -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

View File

@ -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();
@ -194,7 +194,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
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");

View File

@ -13,7 +13,6 @@
import superagent from "superagent";
import querystring from "querystring";
/**
* @module ApiClient
@ -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) {

View File

@ -13,7 +13,6 @@
import superagent from "superagent";
import querystring from "querystring";
/**
* @module ApiClient
@ -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) {