kjayasa / swagger-ts-client Goto Github PK
View Code? Open in Web Editor NEWA tool to generate typescript http clients and types from swagger definitions
License: MIT License
A tool to generate typescript http clients and types from swagger definitions
License: MIT License
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.
What about enum generation from swagger Swashbuckle?
Enum example -
... "properties": { "EnumTest": { "enum": [ "Test", "Test2", ], "type": "string" } }...
Now swagger-ts-client
miss enum types. Just generate properties as string type - propTest?: string;
For example it works in https://github.com/RSuter/NSwag/wiki/NSwagStudio but it's in c#.
It generates something this -
export enum EnumTest { Test = <any>"Test", Test2 = <any>"Test2", }
See the list of open issues. This project is not production ready, and hopefully this warning will save you the time I've spent working through them.
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?
when i generate get request with required params, it comes up in URL =>/api/Search/Position/{Id}. This {id} should not be a part of the url by default - i can templated though!
instead
const httpVerbs = ["get", "put", "post", "delete", " options", "head", " patch"];
need
const httpVerbs = ["get", "put", "post", "delete", "options", "head", "patch"];
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.
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); });
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.
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
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
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...
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.
As of the most recent version on NPM (0.9.6), in-path parameters (ex, /foo/{id}
) are not replaced.
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.
To recreate:
$ yarn add swagger-ts-client (notice that 0.9.6 is installed)
$ swagger-ts-client --version
0.9.0
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")
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.