[BUG] [Go] New go client generator doesn't handle binary/file response
Created by: euiko
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The problem occured when using latest 5.0.0-beta3 release which deprecate old go client implementation. Using path's response with binary/file schema type (i.e. for file download with application specific content-type, e.g. pdf, xls, html, etc), got unhandled response type
when using the generated client.
Peeking on the implementation https://github.com/OpenAPITools/openapi-generator/blob/3f75691da200c20764a860ae8eae9b7b458c6e62/modules/openapi-generator/src/main/resources/go/client.mustache#L397
there is changes compared to the old implementation in go-deprecated
, it doesn't handle (*os.File type). Is there are changes by design?
openapi-generator version
Look like already handled in previous stable version 4.1.3, that are now deprecated but missing in new generator
OpenAPI declaration file content or url
Simple schema, only parts of a whole openapi spec :
...
paths:
'/reports/{id}/get':
parameters:
- schema:
type: string
format: uuid
example: df50a5d7-b9cf-453d-af18-524ff47fe558
name: id
in: path
required: true
get:
summary: Download report
tags:
- client
responses:
'200':
description: OK
headers: {}
content:
application/pdf:
schema:
$ref: '#/components/schemas/FileDownload'
application/vnd.ms-excel:
schema:
$ref: '#/components/schemas/FileDownload'
text/html:
schema:
$ref: '#/components/schemas/FileDownload'
operationId: getReportJobResult
description: Download generated report
components:
schemas:
FileDownload:
title: FileDownload
type: string
format: binary
Generation Details
Generate using go client generator
Steps to reproduce
- Create schema contain binary response
- Generate using new go client
- Use the generated client to integrate with server implementation (either mock or real)
Related issues/PRs
Suggest a fix
Current workaround is by enumerating errors returned by generated client like :
_, httpResp, err := c.client.ClientApi.GetReportJobResult(ctx, jobID).Execute()
if httpResp.StatusCode != 200 {
return ErrDownloadFailed
}
if err != nil {
// error happened? check its type is related with undefined response type
if xerr, ok := err.(schema.GenericOpenAPIError); ok && xerr.Error() == "undefined response type" {
// write the request body to file instead
f.Write(xerr.Body())
return nil
}
return err
}
But I would like to know the proper handling for these such case, I am thinking using the previous approach in go-deprecated
by creating temporary files is enough.
Or maybe using read writer interface as datatype of binary-like format, that could be changed through generation config.