swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

POST API endpoints require subscribing to return value from generated typescript to work

Open brian15co opened this issue 10 years ago • 3 comments

Description

I generated a typescript Angular2 client from the online generator (editor.swagger.io). I noticed that POST endpoints were not making it to the server. No errors thrown or otherwise indicate that something broke.

Swagger-codegen version

Using Swagger online code editor V 2.10.3. YAML format

Swagger declaration file content or url

Here is the relavant yaml code for my POST endpoint

  /Snapshots/bulkUpsert:
    post:
      tags:
        - Snapshot
      summary: creates or updates snapshots according to a list of snapshots provided by the labeler GUI
      x-swagger-router-controller: server.api
      operationId: Snapshots.bulkUpsert
      parameters:
        - name: data
          in: body
          description: a list of objects like {video_id, frame, x, y, label}
          required: true
          schema:
            type: array
            items:
              $ref: '#/definitions/Snapshot'
      responses:
        '200':
          description: Request was successful
          schema:
            $ref: '#/definitions/Snapshot'
      deprecated: false
Command line used for generation

Generated typescript Angular2 client using https://editor.swagger.io

Steps to reproduce

Making requests to the endpoint from the swagger ui work ok. Making requests from a tool like postman work ok. Although, when I try to reach the endpoint from within my application using generated client code, the POST does not post at all and no errors are thrown. I can fix the issue by changing the following line (located within a function in my Angular Component):

this.snapshotApi.snapshotsFoo([6,7,8]);

to the following:

let whoCares = this.snapshotApi.snapshotsFoo([6,7,8]);

whoCares.subscribe(res => {
    console.log('i dont even');
}

This suggests that the http result is getting prematurely thrown away. Strange because all other methods of request succeed.

Related issues
Suggest a Fix

brian15co avatar Oct 27 '16 16:10 brian15co

@brian15co thanks for reporting the issue. I wonder if you can try the latest master to generate the typescript-angular2 client as there's been many enhancements to typescript client since the last stable release.

wing328 avatar Nov 01 '16 08:11 wing328

@brian15co closing this as there's no update from you.

wing328 avatar Feb 17 '17 06:02 wing328

@wing328 I just ran into this while using the typescript Angular 2 client also. We are using the codegen off of the 2.2.3 branch. Using the network debugger in Chrome I could see that the POST never went through on that console until I added the ".subscribe()" call. I admittedly don't have any experience into the inner workings of the codegen but wanted to let you know that someone else had seen this issue since it was closed due to the other user not updating you.

Blackbaud-TrevorBurch avatar Apr 04 '17 20:04 Blackbaud-TrevorBurch