Closed mpopp closed 2 years ago
Hey Thanks for raising this I will try to reproduce and fix it soon. Tomasz
Awesome. I have debugged into the code a little bit in the meantime and couldn't find any call to importMap.put for return types
import for return type is added here com/blueveery/springrest2ts/converters/SpringAnnotationsBasedRestClassConverter.java:90
TSEnum extends TSScopedElement ,when You look at this method:
com/blueveery/springrest2ts/tsmodel/TSModule.java:171
here TSScopedElement element is added to importMap
so I think it should work but maybe there an issue in the code which need to be investigated or based on mentioned method, enum is placed in systemModule
TSModule module = tsScopedElement.getModule(); if (module != this && module != TypeMapper.systemModule) {
You can check if this enum module is not a systemModule, systemModule it is global scope from which we don't need to import things like JS Array type
hey
In branch enums-import-test
I created test which generates TS service based on the Java controller which has method where return type is enum, please check this test com.blueveery.springrest2ts.converters.SpringRestToTsConverterTest#endpointReturnTypeShouldBeImported
Import is generated, test prints to std out generated code which looks following:
`import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {Injectable} from '@angular/core'; import {ProductType} from './converters-enums'; import {Observable} from 'rxjs'; import {map} from 'rxjs/operators';
@Injectable() export class ProductController { httpService: HttpClient;
public constructor(httpService: HttpClient) { this.httpService = httpService; }
public getProductType(): Observable
}` Please feel free to modify this test to replicate your case. You can also check in setUp method how tsGenerator is configured maybe the issue is in configuration
Thank you, your test helped me figuring out the issue.
It has to do with generics. I use SingleResult
I modified the test to reproduce the case.
ok, thanks I will check that over the weekend
this SingleResult is a spring type or it is your own custom type?
I'm preparing the branch on a fork right now so you can check my setup. It is my own custom type.
ok thanks
Here is the branch in my fork: https://github.com/mpopp/spring-rest-2-ts/tree/failing-enums-import
thanks Matthias, it was a good finding.
I've pushed fix to enums-import-test
branch You can pull changes, build them locally and use in your setup version 1.5.1-SNAPSHOT
if it solve your problem I will make release during the weekend
Sorry for the late response. Just got around trying out your fix on the SNAPSHOT version you provided.
With the fix, the imports are generated as expected.
great, thanks version 1.5.1 is already in maven central repo https://search.maven.org/artifact/com.blue-veery/spring-rest2ts-generator/1.5.1/jar
I have a small controller where I return something like ListResult from one of the endpoints.
The enum is not used as a request parameter in any of the endpoints of this controller.
The generated ts api does not contain an import {enum} from "./enum-module" in the imports block. The return types are generated correctly though.
As soon as I add an endpoint that uses the enum as a bodyParameter, the import is done correctly. I have not verified if this happens with Java Classes as well. Right now I only run into this issue with Enums.
This happens independent of whether I use my own ImplementationGenerator, the FetchBased one or the Angular based one.