Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Client-SDK] [Typescript] [Bug] Service class does not include the request "body" as 2nd parameter of "httpClient.post" and "httpClient.patch". #9013

Open
madhab opened this issue Dec 27, 2018 · 0 comments

Comments

@madhab
Copy link

madhab commented Dec 27, 2018

[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..

  1. the api url
  2. the request body
  3. 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: .. });
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant