cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
403 stars 134 forks source link

ES5 compatibility #195

Closed maximebochon closed 1 year ago

maximebochon commented 2 years ago

I had to migrate an existing Angular project from Swagger 2 using ng-swagger-gen to OpenAPI 3 using ng-openapi-gen.

One of the issues I encountered was that the generated code seems not to be ES5 compliant. I had to change the tsconfig target from es5 to es2015 to get rid of building problems.

(As a consequence, I now can't run tests using Karma/PhantomJS and trying to use Babel as a workaround.)

Regards.

luisfpg commented 2 years ago

What exact error do you have?

maximebochon commented 2 years ago

The type of errors I get is like this:

Error: src/app/.../request-builder.ts:338:30 - error TS2569:
Type 'IterableIterator<QueryParameter>' is not an array type or a string type.
Use compiler option '--downlevelIteration' to allow iterating of iterators.
338     for (const queryParam of this._query.values()) {

About my previous comment, I now know that PhantomJS is deprecated and is not compatible with ES6.

luisfpg commented 2 years ago

If you edit the request-build.ts file, and change that line to for (const queryParam of [...this._query.values()]) {, does it work?

maximebochon commented 2 years ago

I get the same error with the proposed change. I think that the compatibility problem comes from the type returned by values() which is IterableIterator. I did not have time to figure out exactly what is not ES5 compatible.

By the way, the same problem exists for HeaderParameter and PathParameter.

luisfpg commented 1 year ago

Closing for lack of activity