-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add overloads in default templates for reportProgress/observe properties #114
Comments
I don't think this should be handled by adding an "anonymous" boolean parameter for each request config option. If so, how about having a single optional requestConfig with these as its attributes. Just my 2 cents. I'm only a consumer here. |
Really, reportProgress / observe are not currently handled by the generator. |
@Lonli-Lokli I know. As long as RequestConfig interface differed, it would still be possible. |
@Lonli-Lokli The swagger 2 sibling project (ng-swagger-gen) is no longer used or maintained by ourselves, only by community contribution, and it is getting harder and harder to maintain, as if I just plainly accept PR's it can break other things, and I really don't have a test project anymore for it. For ng-openapi-gen, if you want to contribute a PR with passing tests, it would be more than welcome. |
@tajnymag can you please explain a little bit how different returned types can be done with single Params object? |
@Lonli-Lokli This works for me. resultFor(Body|Response|Events) gets their types correctly. interface RequestConfig {
observe?: 'body' | 'response' | 'events',
reportProgress?: boolean
}
const RequestConfigDefault: RequestConfig = {
observe: 'body',
reportProgress: false
}
class ExampleService {
public sendConfirmations(businessDate: string, confirmations?: Confirmation[], requestConfig?: RequestConfig & { observe?: 'body' }): Observable<SendConfirmationsResponse>;
public sendConfirmations(businessDate: string, confirmations?: Confirmation[], requestConfig?: RequestConfig & { observe?: 'response' }): Observable<HttpResponse<SendConfirmationsResponse>>;
public sendConfirmations(businessDate: string, confirmations?: Confirmation[], requestConfig?: RequestConfig & { observe?: 'events' }): Observable<HttpEvent<SendConfirmationsResponse>>;
public sendConfirmations(businessDate: string, confirmations?: Confirmation[], requestConfig = RequestConfigDefault): Observable<any> {
if (requestConfig.observe === 'response') {
return new Observable<HttpResponse<SendConfirmationsResponse>>();
}
if (requestConfig.observe === 'events') {
return new Observable<HttpEvent<SendConfirmationsResponse>>();
}
return new Observable<SendConfirmationsResponse>();
}
}
const example = new ExampleService();
const resultForBody = example.sendConfirmations('2020-22-06', [], { observe: 'body' });
const resultForResponse = example.sendConfirmations('2020-22-06', [], { observe: 'response' });
const resultForEvents = example.sendConfirmations('2020-22-06', [], { observe: 'events' }); |
@tajnymag got it, thanks! |
Seems like its more difficult than I thought as current solution is based on pure HttpRequest usage :( |
@luisfpg going back, I was sticker with RequwstBuilder as it does not give full control on props and returned types. That's how it's done in competitor https://github.com/OpenAPITools/openapi-generator/blob/9bd2a45e72bd4e65c22ae3f3ce4a1ff8bd8db8b9/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache |
Example:
The text was updated successfully, but these errors were encountered: