flowup / api-client-generator

Angular REST API client generator from Swagger YAML or JSON file with camel case settigs
MIT License
115 stars 21 forks source link

(bug) HttpOptions.headers:HttpHeaders compatibility issue with aot compilation #47

Closed resistancecanyon closed 6 years ago

resistancecanyon commented 6 years ago

Running $ ng build --prod while the module is injected to the app. We get the following error

ERROR in app/app.module.ts(14,21): Error during template compile of 'AppModule' Function calls are not supported in decorators but 'HttpHeaders' was called.

This might be due to the fact that simple assignments are only allowed during module declarations. and we're trying to pass new HttpHeaders(...header String/objects) into the module declaration.

Possible Solution:

resistancecanyon commented 6 years ago

@vmasek Is this good ? I'll add test cases for the same.

vmasek commented 6 years ago

I will look into this issue as I don't recall this happening in our projects. It would be better if we could solve it without additional config options

vmasek commented 6 years ago

What is the ng version you are using?

resistancecanyon commented 6 years ago

Angular 5.2.9

resistancecanyon commented 6 years ago

I do think extra options are unnecessary, but if we add imports: [ BrowserModule, ... APIClientModule.forRoot({ domain: 'http://localhost:10507', httpOptions: { headers: new HttpHeaders(xxx), withCredentials: true } }), SharedModule ], It simply won't build with --prod flag causing the above mentioned error. Maybe AoT was off for your projects like in ng4. It is a blocker. Is there any other way to pass the headers: then also its fine.

vmasek commented 6 years ago

After some tests, it would be best if the options we provide for params and headers will be {[key: string]: string} object and not constructed class.

It will require to change some types and interfaces but it should be able to do it without breaking the outer API. I'll cover that in PR soon.

resistancecanyon commented 6 years ago

I do agree that, so AOT compilation will never break again. And we can construct the classes from the {[key: string]: string} pairs inside the api constructor classes & thus instantiated only once.

vmasek commented 6 years ago

the fix should be in master now, @resistancecanyon please try the latest version and see if there is everything resolved.