swagger-api / swagger-api/swagger-codegen
[Javascript] Improve Chrome console output by explicit constructor name instead of "exports"
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When outputting responses from the generated Api, Chrome is smart enough to provide smart type names for the objects that are rendered. For example, when calling a api function in console, Chrome gives me:
api.getSomething().then(function() { console.log(arguments); })
> [exports]
This is because of the generated Models having the following code:
var exports = function() {
var _this = this;
}
...
return exports;
To be honest, even I am not too sure how Chrome does this in V8, as Firefox definitely does not do this for me. Edit: seems like Chrome may be simply using obj.constructor.name as the output.
api.getSomething().then(function() { console.log(arguments[0]); })
> Object { ... }
Anyway, just a suggestion, not a big one =)
Swagger-codegen version
2.1.6, 2.2.0
Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues
Suggest a Fix
Even a quick hack like this works, for example in a model file called ResourceModel.js:
var ResourceModel = function() {
var _this = this;
};
var exports = ResourceModel;
...
return exports;
api.getSomething().then(function() { console.log(arguments); })
> [ResourceModel]
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 ResourceModel.js example and locate the JavaScript model template that emits models through an exports function. Verify how Chrome derives the constructor name, then make the generated console output identify the model explicitly and confirm the resulting output matches the requested model name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100