swagger-api / swagger-api/swagger-codegen
[Client-SDK] [Typescript] [Bug] Service class does not include the request "body" as 2nd parameter of "httpClient.post" and "httpClient.patch".
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
[Client-SDK] [Typescript] [Bug] Service class does not include the request "body" as 2nd parameter of "httpClient.post" and "httpClient.patch".
Description
The httpClient.post and httpClient.patch in typescript expects 3 parameters as follows respectively..
- the api url
- the request body
- options
However in the client sdk the generated code submits only 1. api url and 2. options. As a result the options is submitted as body to the request.
Following is the code from typescript client sdk.
POST:
public ....Post(body?: model1, observe: any = 'body', reportProgress: boolean = false): Observable {
.......;
......;
return this.httpClient.post(${this.basePath}/api,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
}
PATCH:
public .....IdPatch(id: string, ifMatch: string, body?: model1, observe: any = 'body', reportProgress: boolean = false): Observable {
.......;
......;
return this.httpClient.patch(${this.basePath}/api/${encodeURIComponent(String(id))},
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
}
Swagger-codegen version
as used in https://app.swaggerhub.com
Swagger declaration file content or url
paths:
/api:
post:
tags:
- tag1
summary: Create a model1
description: >-
Create a model1
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/model1'
responses:
'201':
description: Create model1
content:
application/json:
schema:
type: object
properties:
_id:
type: string
format: string
components:
model1:
type: object
properties:
id:
type: string
format: string
readOnly: true
property1:
type: string
format: string
property2:
type: integer
format: int32
property3:
type: string
enum: [A, B, C, D]
Command line used for generation
web interface of https://app.swaggerhub.com
Steps to reproduce
1. Login to https://app.swaggerhub.com
2. Go to your My Hub and go to your project
3. Click the "Export" > "Client SDK" > "typescript-angular" bropdown at the right top section.
4. Check the Service class in the generated typescript code.
Suggest a fix/enhancement
Enter the "body" as the 2nd parameter to the "httpClient.post" and "httpClient.patch".
POST:
public ....Post(body?: model1, observe: any = 'body', reportProgress: boolean = false): Observable<any> {
.......;
......;
return this.httpClient.post(`api`, body, { options: .. });
}
PATCH:
public .....IdPatch(id: string, ifMatch: string, body?: model1, observe: any = 'body', reportProgress: boolean = false): Observable<any> {
.......;
......;
return this.httpClient.patch(`api/${encodeURIComponent(String(id))}`, body, { options: .. });
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the template or generator entry point for the TypeScript service class and inspect the generated POST and PATCH methods described in the issue. Compare their httpClient calls with the documented request signature, then verify generated output for operations with request bodies and confirm the body is handled separately from the options.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100