Open beatgrabe opened 6 years ago
Is there a workaround? I'm running into this issue on 3.0.21 and I'm stuck.
As of Swagger Codegen 3.0.25 the issue is still prominent.
The generated ES6 code should have the module import references associated with the proper extension for generated modules, (ex, import GeneratedClass from './GeneratedModule.js'
The workaround is to modify the handlebar (for the API 3.0 specs) templates such that the generated import have a .js extension.
Additionally, the package.mustache template needs to have the "type": "module"
entry.
Description
Composition of model definitions does not work with
es6
javascript
, leading into aTypeError: Cannot call a class as a function
when sources are compiled withbabel
, which is according to ES6 Spec 9.2.1 (Point 2) appropriate bahaviour.This is the related line in the mustache template:
For example in the Cat.js of the petstore sample this compiles to:
Animal.call(this, className)
throws error, because es6 class constructors cannot be called as normal functions, like it is done here withFunction.prototype.call
, when for my case the sources are transpiled by babel.Babel uses an internal function to check if a class is called as function and then throws:
Here ist the related REPL.
Swagger-codegen version
swagger-codegen-cli-2.3.1
Swagger declaration file content or url
Refering the perstore example.
Command line used for generation
config.json
shell command
Steps to reproduce
Using a model definition which implements another model definition and generating a javascript client library which uses es6 standard.
Suggest a fix/enhancement
For now I am using my own
partial_model_generic.mustache
template commenting out the related code line. But I am not sure, what would be the appropriatejavascript
fix, since es6 does not supportinterfaces
. So I will leave this question open for discussion and I will be open to file a PR at appropriate time.