Giter Club home page Giter Club logo

swagger-ts-client's People

Contributors

ajrodrigues avatar dbreheret avatar dependabot[bot] avatar kjayasa avatar poppa avatar vankeisb avatar webmonger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

swagger-ts-client's Issues

basePath in swagger.json ignored in endpoint URL generation

The basePath property in swagger.json doesn't seem to be acknowledged when the endpoint path is generated. So I end up with request.get('/operation') instead of request('/api/v1/operation'), where /api/v1 is the basePath in my swagger.json.

I got around it by overriding operation.templateFile, but it seems like something that is easily fixed.

Issue with in-path parameters

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?

HttpVerbs

instead
const httpVerbs = ["get", "put", "post", "delete", " options", "head", " patch"];
need
const httpVerbs = ["get", "put", "post", "delete", "options", "head", "patch"];

Problem with latest handlebars version

Hi,

I try to use swagger-ts-client with the latest version of handlebars, but some features changed since the version 4.0.11.

Here is the feature which can be problematic.

If you wan't to continue to use swagger-ts-client, you should fix the version of handlebars to 4.0.11 in your project.

Is there a way to check condition and then generate a template in the handle bar?

really handy tool - helped me setup angular 4 services in less than half hour for a full project rebuild. By default handle bars does not allow if comparisons - so how to get a custom filter injected to the process. like

handlebars.registerHelper('xif', function(v1, v2, options) { if(v1 === v2) { return options.fn(this); } return options.inverse(this); });

Function properties of ts-client.config.js are being ignored

const settings = {
  operations: {
    outPutPath:"./src/api/http/",
    operationsGroupNameTransformFn (operationName, httpVerb, operation) {
      return 'whatever' + httpVerb +operation;
    }
  }
};

module.exports = settings;

In the example settings from the ts-client.config.ts file above, the outPutPath is being honoured, but the operationsGroupNameTransformFn is being ignored, in favour of the default method.

typesDefinitionRender file case sensitive

Hi

const typesDefinitionRender_1 = require("./renderer/typesDefinitionRender"); should be
const typesDefinitionRender_1 = require("./renderer/TypesDefinitionRender"); My linux machine in CI/CD pipeline fails on line 14 tsFromSwagger.js

Any chance this can be resolved sooner?

Cheers

Parameter with formData

Hi,

I wanna to know if there is a way to manage parameter using formData.
Here the specification about the formData.

Maybe we just need another property like inBody or inPath. I don't know if there is another possible values for the in property of a swagger.json

Thanks for reading

Generator doesn't seem to respect path parameters

First off, nice work on this package. Secondly, I'm trying to generate a client that has path parameters and despite being in the context of the template, they are treated as query parameters. Which for my backend doesn't work since it's expecting the parameters in the path. I created a super simple handlebar helper that just converted the url into an interpolated string:

    templateHelpers: {
        "toInterpolatedString": (url) => {
            return (url || "").replace("{", "${");
        }
    },

then in the template...

    {{#each operationGroup.operations}}
    public async {{operationName}}({{#joinList operationParams}} {{paramDisplayName}}:{{paramType}} {{/joinList}}):Promise<{{responsesType}}>{
        {{#if operationParams}}
            {{#some operationParams "op=>(!op.inBody && !op.inPath)"}}
        const params = { 
            {{#joinList this ",\n" "op=>(!op.inBody && !op.inPath)"}}
            "{{paramName}}":{{paramDisplayName}}{{/joinList}} 
        };
            {{/some}}
        {{/if}}
            const response = await this.agent.{{httpVerb}}(`{{{toInterpolatedString url}}}`)
                {{#some operationParams "op=>(!op.inBody && !op.inPath)"}}
                .query(params)
                {{/some}}        
                {{#filterList operationParams "op=>op.inBody" "1"}}
                .send({{paramDisplayName}})
                {{/filterList}} 
            return response.body as {{responsesType}};

It's an extremely naiive fix, but thought i'd share it anyways.

Just had a thought that this will likely break if there are both path and query params.

Bug: body is not sent if any other parameters exist

Because of this line, in filterListHelper:

for (let i = 0; i < take; i++) {
  if (fliterFn(context[i], i, context)) {
    ret = ret + options.fn(context[i]);
  }
}

The take parameter should be incremented if the filter matches, otherwise:

            {{#filterList operationParams "op=>op.inBody" "1"}}

Will bail on the first parameter, even if it isn't in the body.

Host and scheme is ignored if set

Currently the host and schemes are ignored when creating the URL so it will only attempt to make calls to localhost.

Current:
request.get("/path/to/data.json")

If host and scheme exist:
request.get("https://api.awesomesite.com/path/to/data.json")

Is it available to use only typings?

Hello, guys! Thanks for this beautiful tool. It works perfectly as expected.
Is there any opportunity to use only typing-generator feature? For example, I want to write HTTP requester by my own, but I want to use types generated by swagger schema.

What do you think? What is the best way to do it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.