kjayasa / swagger-ts-client

A tool to generate typescript http clients and types from swagger definitions
MIT License
27 stars 24 forks source link

Issue with in-path parameters #10

Open yebrahim opened 6 years ago

yebrahim commented 6 years ago

Hi. Thanks so much for providing this library, it's the simplest and lightest I found so far!

I have an issue when generating a Tyepscript client library though. I have a resource definition like this in swagger:

    "/apis/myresources/{id}": {
      "get": {
        "operationId": "GetMyResource",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
      },
    },

Which generates the following Typescript client code:

    public GetMyResource( id:string ):Promise<apiMyResource>{
        const params = { 
            "id":id 
        };
        return new Promise<apiMyResource>((resolve, reject) => {
            request
            .get("/apis/myresources/{id}")
            .query(params)
            .end(function(error, res){
                if(error){
                    reject(error);
                }else{
                   resolve(res.body as apiMyResource);
                }
            });
        });
    }

This doesn't seem right to me though, since now the request goes to /apis/myresources/{id}?id=123 instead of /apis/myresources/123. Is there anything I missed here or does this need a fix?

wolever commented 5 years ago

I'm also having this issue. As far as I can tell, URL parameters aren't supported at all.

webmonger commented 5 years ago

Can you check the latest version from github not NPM? I cant remember exactly but I changed something to do with the querystring in one of my PRs.

If not should be an easy fix.