ng-openapi-gen icon indicating copy to clipboard operation
ng-openapi-gen copied to clipboard

ES5 compatibility

Open maximebochon opened this issue 3 years ago • 4 comments

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.)

  • Is there a way to make ng-openapi-gen produce ES5 compliant code only?
  • Is there anything I might have misunderstood in the process?
  • If ES6 is an absolute requirement when using this code generator, could you add this information in the README?

Regards.

maximebochon avatar Jan 04 '22 14:01 maximebochon

What exact error do you have?

luisfpg avatar Jan 20 '22 16:01 luisfpg

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.

maximebochon avatar Jan 25 '22 07:01 maximebochon

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

luisfpg avatar Jan 25 '22 13:01 luisfpg

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.

maximebochon avatar Jan 26 '22 08:01 maximebochon

Closing for lack of activity

luisfpg avatar Jan 04 '23 18:01 luisfpg