The import of Observable in rxjs 6 is changed from previous versions. The typescript-angular generator should support the new version
3.0.2
Taking any definition, the created services imports rxjs in this way:
import { Observable } from 'rxjs/Observable';
With rxjs 6, the correct way to import Observable is:
import { Observable } from 'rxjs';
This should be supported with a specific configuration flag, or when ngVersion is greater than 6.
This has already been fixed and merged into master, but sadly it didn't make it to the v3.
https://github.com/swagger-api/swagger-codegen/pull/8155/commits/887afa8ea798ef232f260518b941701499c3488f#diff-5bdae26ba753c4986ceb5af35bada047
Any update on when this might get merged to master?
Please take a look at the issue. This does not let me remove rxjs-compat from dependencies.
Moreover, this will become a bigger problem after rxjs-compat deprecation.
The PR that @britvik mentioned is indeed in the master branch only (<3.0.0). I've created a separate issue for the 3.0.0 branch (in the swagger-codegen-generators repo) to get these commits to the 3.0.0+ version as well.
Please be aware that the default Angular build still runs for Angular 4.3.0 (see TypeScriptAngularClientCodegen.java):
SemVer ngVersion;
if (additionalProperties.containsKey(NG_VERSION)) {
ngVersion = new SemVer(additionalProperties.get(NG_VERSION).toString());
} else {
ngVersion = new SemVer("4.3.0");
LOGGER.info("generating code for Angular {} ...", ngVersion);
LOGGER.info(" (you can select the angular version by setting the additionalProperty ngVersion)");
}
You can run the build script for Angular 6 with the --additional-properties ngVersion=6 command:
Linux:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-l typescript-angular \
-o /var/tmp/angular_api_client \
--additional-properties ngVersion=6
Windows:
java -jar modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l typescript-angular -o c:\temp\angular_api_client --additional-properties ngVersion=6
Most helpful comment
For swagger-codegen >=3.0.0
The PR that @britvik mentioned is indeed in the master branch only (<3.0.0). I've created a separate issue for the 3.0.0 branch (in the swagger-codegen-generators repo) to get these commits to the 3.0.0+ version as well.
For swagger-codegen <3.0.0
Please be aware that the default Angular build still runs for Angular 4.3.0 (see TypeScriptAngularClientCodegen.java):
You can run the build script for Angular 6 with the
--additional-properties ngVersion=6command:Linux:
Windows: