swagger-api / swagger-api/swagger-codegen
[JAVASCRIPT] How to use generated client?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I'm getting used to Swagger, so I've created a sample API via editor and generated javascript-client code. README.md tells me to execute the following code in browser:
var PistacheTest = require('pistache_test');
var api = new PistacheTest.CalcApi()
var number1 = 789; // {Number} 1st number
var number2 = 789; // {Number} 2nd number
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully.');
}
};
api.calcPost(number1, number2, callback);
Since I see require keyword, it means Node.JS, not browser javascript. Okay, I installed browserify (npm install -g browserify) and got bundle.js as browserify index.js -o bundle.js.
Then I included bundle.js as <script type="text/javascript" src="bundle.js"></script> in my test HTML webpage.
But the question is: How can I execute any functions from that bundle.js?
I tried:
var api = PistacheTest.EchoApi();
var api = PistacheTest.Echo();
var api = PistacheTest;
etc.
I see no way to execute my API calls from browser. At this point I think writing Python script which executes my API endpoints will be faster and more convenient than dealing with non-working Javascript code, which was generated by Swagger.
Swagger-codegen version
2.4.0-SNAPSHOT
Swagger declaration file content or url
https://gist.github.com/MasterGroosha/6e4ed847a53ba170273d41c5bea5c003
Command line used for generation
sudo docker run -u 1000:1000 -rm -v $(PWD):/local swaggerapi/swagger-codegen-cli generate -i /local/swagger.json -l javascript -o /local/out/code
Related issues/PRs
I don't see anything related, maybe because of my inexperience in JS/NodeJS.
Suggest a fix/enhancement
Pls help :(
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated README.md example, the generated index.js, and the browserify command described in the issue. Check whether the JavaScript client documents or supports browser use and how its exports are exposed. Done means reproducing the usage problem and either clarifying the supported invocation or identifying a concrete generator change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, developer-experience, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100