cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Correctly handle media types with +json suffix #10

Closed exejutable closed 5 years ago

exejutable commented 5 years ago

Hello thanks for this amazing tool. I have a issue based on my open api yaml

When all services are generated they pass to the requestBuilder a object with reponseType blob, the reques runs fine in the network tab on chrome


Edit

Searching in the code in operation-vartiant.ts i can see the problem. This behavior is all about the custom response types like application/iway-csr-api-customer-response-v1-hal+json this is very common in a tons of restful api, maybe we can fix it if parse the content searching a substring with json to avoid blob in this cases?


Raw Generated service:

/**
   * This method provides access to only to the response body.
   * To access the full response (for headers, for example), `showSearchSettings$Response()` instead.
   *
   * This method doesn't expect any response body
   */
  showSearchSettings(params: {

    /**
     * Orgnanization Code or tenan ID.
     */
    xOrganizationCode: string;

  }): Observable<SearchSettingResource> {

    return this.showSearchSettings$Response(params).pipe(
      map((r: StrictHttpResponse<SearchSettingResource>) => r.body as SearchSettingResource)
    );
  }

  /**
   * Path part for operation modifySearchSettings
   */
  static readonly ModifySearchSettingsPath = '/admin/search';

  /**
   * This method provides access to the full `HttpResponse`, allowing access to response headers.
   * To access only the response body, use `modifySearchSettings()` instead.
   *
   * This method sends `application/iway-csr-api-settings-search-put-v1-hal+json` and handles response body of type `application/iway-csr-api-settings-search-put-v1-hal+json`
   */
  modifySearchSettings$Response(params: {

    /**
     * Orgnanization Code or tenan ID.
     */
    xOrganizationCode: string;

    body?: SearchSetting
  }): Observable<StrictHttpResponse<SearchSettingResource>> {

    const rb = new RequestBuilder(this.rootUrl, '/admin/search', 'put');
    if (params) {

      rb.header('X-Organization-Code', params.xOrganizationCode);
      rb.body(params.body, 'application/iway-csr-api-settings-search-put-v1-hal+json');
    }
    return this.http.request(rb.build({
      responseType: 'blob',
      accept: 'application/iway-csr-api-settings-search-response-v1-hal+json'
    })).pipe(
      filter((r: any) => r instanceof HttpResponse),
      map((r: HttpResponse<any>) => {
        return r as StrictHttpResponse<SearchSettingResource>;
      })
    );
  }

Calling the service from controller returns a blob object


this.adminDomainService.showSearchSettings({xOrganizationCode:'Intraway'})
      .subscribe((response: any) => {
        console.log(response) // Blob {size: 305, type: "application/iway-csr-api-settings-search-response-v1-hal+json"}
      })

I change it to json and works fine now, but i need to change the response builder every time i do a new openapi build

Here is my openapi yaml:

csr.yaml.tar.gz

exejutable commented 5 years ago

Searching in the code in operation-vartiant.ts i can see the problem. This behavior is all about the custom response types like application/iway-csr-api-customer-response-v1-hal+json this is very common in a tons of restful api, maybe we can fix it if parse the content searching a substring with json to avoid blob in this cases?