RicoSuter/NSwag
View on GitHubTrouble with typescript generator for x-www-form-urlencoded endpoint
Open
#1,338 opened on May 22, 2018
help wantedproject: NSwag.CodeGeneration.TypeScripttype: enhancement
Description
For an OAuth compliant endpoint using formData parameters the data is expected to be in application/x-www-form-urlencoded format which looks like this:
grant_type=password&client_id=123456&username=test&password=test
However the typescript generator is using JSON.stringify which generates something like this:
{'grand_type':'password','client_id':'123456','username':'test','password':'test'}
How can I go about replacing the call to JSON.stringify() with something else? Can I provide a custom Client.RequestBody.liquid template to nswag?
I need to replace the JSON.stringify() with something like this:
token(token: OAuth2Request): Observable<SimpleAccessTokenResult> {
let url_ = this.baseUrl + "/api/public/v1/oauth2/token";
//const content_ = JSON.stringify(token);
const content_ = Object.keys(token).map((key) => {
return encodeURIComponent(key) + '=' + encodeURIComponent(token[key]);
}).join('&');
let options_ : any = {
body: content_,
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json"
})
};