cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
404 stars 134 forks source link

FileResult/FileStreamResult return value from web api #205

Closed snisar closed 2 years ago

snisar commented 2 years ago

I have a controller end point which is returning a FileStreamResult (tested with FileResult as well)

    [HttpGet]

    [Route("download")]

    public async Task<FileStreamResult> DownloadInvoice(Guid id)

    {

        var saleInvoice = await _unitOfwork.SaleInvoice.Get(id);

        var document = await _storageService.RetrieveDocumentFromStorage(saleInvoice.Reference);

        return new FileStreamResult(document, "application/octet-stream");

    }

This generates a Angular service but expects a text response, whereas I believe it should be setting the response type to arraybuffer

/**
   * This method provides access to the full HttpResponse, allowing access to response headers.
   * To access only the response body, use apiSaleInvoiceDownloadGet() instead.
   *
   * This method doesn't expect any request body.
   */
  apiSaleInvoiceDownloadGet$Response(params?: {
    id?: string;
  }): Observable<StrictHttpResponse<void>> {

    const rb = new RequestBuilder(this.rootUrl, SaleInvoiceService.ApiSaleInvoiceDownloadGetPath, 'get');
    if (params) {
      rb.query('id', params.id, {});
    }

    return this.http.request(rb.build({
      responseType: 'text',
      accept: '*/*'
    })).pipe(
      filter((r: any) => r instanceof HttpResponse),
      map((r: HttpResponse<any>) => {
        return (r as HttpResponse<any>).clone({ body: undefined }) as StrictHttpResponse<void>;
      })
    );
  }
luisfpg commented 2 years ago

Sorry, this is not a generator from .NET to TypeScript, rather, from OpenAPI to TypeScript ;). I'd need the OpenAPI source file - either the JSON or YAML.

Also, currently, binary types are generated as Blob when type=string and format=binary.

snisar commented 2 years ago

Sorry, my bad :-( Looking at the portion of the swagger, it does not define a particular response type. Will take a look at my controller and see why that is the case.

/api/SaleInvoice/download: { get: { tags: [ "SaleInvoice" ], parameters: [ { name: "id", in: "query", schema: { type: "string", format: "uuid" } } ], responses: { 200: { description: "Success" } } } },