Swagger CodeGen,使代理删除某些元素并进行简化

问题描述

有没有办法使用 Swagger Io Codegen Editor 自动生成代理,同时删除某些元素?我们正在将 C# API 转换为 Angular Typescript 代理。

  1. 我有以下 4 种方法

  2. 如果声明不要求身份验证

  3. 我也不需要 HeadersAccept

https://editor.swagger.io/

原始代理:

    public getUserDepartment(departmentId: number,observe?: 'body',reportProgress?: boolean): Observable<GetUserResponse>;
    public getUserDepartment(departmentId: number,observe?: 'response',reportProgress?: boolean): Observable<HttpResponse<GetUserResponse>>;
    public getUserDepartment(departmentId: number,observe?: 'events',reportProgress?: boolean): Observable<HttpEvent<GetUserResponse>>;
    public getUserDepartment(departmentId: number,observe: any = 'body',reportProgress: boolean = false ): Observable<any> {

        if (departmentId === null || departmentId === undefined) {
            throw new Error('required parameter departmentId was null or undefined when calling getUserDepartment.');
        }

        let headers = this.defaultHeaders;

        // authentication (Token) required
        if (this.configuration.apiKeys && this.configuration.apiKeys["Authorization"]) {
            headers = headers.set('Authorization',this.configuration.apiKeys["Authorization"]);
        }

        // to determine the Accept header
        let httpHeaderAccepts: string[] = [
            'application/json;odata.Metadata=minimal;odata.streaming=true','application/json;odata.Metadata=minimal;odata.streaming=false','application/json;odata.Metadata=minimal','application/json;odata.Metadata=full;odata.streaming=true','application/json;odata.Metadata=full;odata.streaming=false','application/json;odata.Metadata=full','application/json;odata.Metadata=none;odata.streaming=true','application/json;odata.Metadata=none;odata.streaming=false','application/json;odata.Metadata=none','application/json;odata.streaming=true','application/json;odata.streaming=false','application/json','application/xml','application/prs.odatatestxx-odata','text/plain','text/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected != undefined) {
            headers = headers.set('Accept',httpHeaderAcceptSelected);
        }

        // to determine the Content-Type header
        const consumes: string[] = [
        ];

        return this.httpClient.request<GetUserResponse>('get',`${this.basePath}/api/Users/department/${encodeURIComponent(String(departmentId))}`,{
                withCredentials: this.configuration.withCredentials,headers: headers,observe: observe,reportProgress: reportProgress
            }
        );
    }

最终预期结果:

    public getUserDepartment(departmentId: number) {

        if (departmentId === null || departmentId === undefined) {
            throw new Error('required parameter departmentId was null or undefined when calling getUserDepartment.');
        }
    
        return this.httpClient.request<GetUserResponse>('get',{}
        );
    }

团队有1000+Api方法转换,寻找简化代码

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)