Как указать OpenAPI для бинарной загрузки в угловых - PullRequest
0 голосов
/ 15 ноября 2018

У меня есть метод для загрузки бинарного файла.В настоящее время в openapi.yaml имеется следующая спецификация:

  /processing/getZippedReports:
    post:
      tags:
      - ProcessingRest
      description: Get the reports
      operationId: getZippedReports
      requestBody:
        description: The list of items for which to get the HTML
        content:
          application/json:
            schema:
              type: array
              items:
                type: string
        required: true
      responses:
        200:
          description: file with zipped reports
          content:
            application/octet-stream: {}

Сгенерированный машинописный код содержит этот вызов httpClient:

return this.httpClient.post<any>(`${this.configuration.basePath}/processing/getZippedReports`,
    requestBody,
    {
        withCredentials: this.configuration.withCredentials,
        headers: headers,
        observe: observe,
        reportProgress: reportProgress
    }
);

Таким образом, angular, кажется, не может получитьбинарный контент.Мне пришлось изменить httpClient, использовать сигнатуру без переменной типа post и добавить responseType: blob к параметрам

return this.httpClient.post(`${this.configuration.basePath}/processing/getZippedReports`,
    requestBody,
    {
        withCredentials: this.configuration.withCredentials,
        headers: headers,
        observe: 'response',
        responseType: 'blob',
        reportProgress: reportProgress
    }
);

Является ли это ошибкой / отсутствующей функцией в коде Swagger или мне следует изменитьопределение openapi, чтобы получить рабочий угловой код?

1 Ответ

0 голосов
/ 16 ноября 2018

Чтобы указать, что ответ является двоичным файлом, используйте схему с type: string с format: binary.

          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
...