Skip to content

Extension options for generated service classes #935

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

Closed
wants to merge 2 commits into from

Conversation

kutlugsahin
Copy link

@kutlugsahin kutlugsahin commented Jan 19, 2022

Hey Ferdi! I hope you are doing well!
First I'm very glad to see that this super handy library keeps growing and improving 🚀 Keep up the awesome work!
I'm willing to use this in my new project but it needs a little bit tuning though. So what's not enough already? Well for angular I need to have these generated service classes a little bit different. Btw it works as is also with angular but you need to compromise on angular's http service and dependency injection mechanism which makes angular devs unhappy 😭 . I also appreciate the framework agnostic structure of the current project so I have added few extension points to the exportService template where the user can inject additional code and finally an injectable angular service using http client is possible.

More details see the open issue #936

@ferdikoomen
Copy link
Owner

@kutlugsahin Does it make sense to add an Angular client? I pushed a WIP (definitly not working yet) branch: https://github.com/ferdikoomen/openapi-typescript-codegen/tree/feature/angular

When you run yarn run build && yarn run run then you will see some generated services inside /geneated/v3

Example:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

import { request as __request } from '../core/request';
import { OpenAPI } from '../core/OpenAPI';

@Injectable()
export class SimpleService {
    private readonly http: HttpClient;

    constructor(http: HttpClient) {
        this.http = http;
    }

    /**
     * @throws ApiError
     */
    public getCallWithoutParametersAndResponse(): Observable<void> {
        return __request(this.http, {
            method: 'GET',
            path: `/api/v${OpenAPI.VERSION}/simple`,
        });
    }
}

I'm writing the request method to work with the Observable pattern, then it should just be plug-and-play

@ferdikoomen
Copy link
Owner

@kutlugsahin I pushed a new update in the branch, the client is WIP but should work. It supports all the same options as other clients, but is using the Angular HTTP client.

@kutlugsahin
Copy link
Author

kutlugsahin commented Jan 26, 2022

It absolutely makes sense! This will be easier to use for an angular user. I've added few comments here 1d8dc54#r64661125
After that I think it's good to go 🚀 and feel free to close this PR. Cheers!

@ferdikoomen ferdikoomen mentioned this pull request Jan 26, 2022
@ferdikoomen
Copy link
Owner

@kutlugsahin I merged the initial version of Angular support. Im testing it further now to see how / if it works well. Closing this PR and will publish a new version to NPM soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants