-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
Description
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
I want to create an endpoint which allows downloading files based on some parameters. I followed the official instructions
on how to describe this kind of response: https://swagger.io/docs/specification/describing-responses/
But no matter what I try the generated endpoint returns JSON.
openapi-generator version
openapitools/openapi-generator-cli:latest
OpenAPI declaration file content or url
...
/v1/address/postcode-ranges:download:
post:
requestBody:
content:
application/json:
schema:
$ref: './schema.yaml#/V1DownloadPostcodeRangesFileRequest'
responses:
"200":
description: Excel file
content:
application/octet-stream:
schema:
type: string
format: binaryGeneration Details
func (c *AddressApiController) V1AddressPostcodeRangesdownloadPost(w http.ResponseWriter, r *http.Request) {
v1DownloadPostcodeRangesFileRequestParam := V1DownloadPostcodeRangesFileRequest{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&v1DownloadPostcodeRangesFileRequestParam); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertV1DownloadPostcodeRangesFileRequestRequired(v1DownloadPostcodeRangesFileRequestParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.V1AddressPostcodeRangesdownloadPost(r.Context(), v1DownloadPostcodeRangesFileRequestParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
Steps to reproduce
docker run $(DOCKER_USER) --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate \
-i /local/docs.yaml \
-g go-server \
-o /local/_build/go-server \
--additional-properties=onlyInterfaces=true && \
cd ./_build/go-server/go && \
go mod tidy && \
go fmt ./... && \
goimports -w .
Related issues/PRs
Suggest a fix
andreas-goebel, jojoshad, xenking, rm3l, icubbon and 2 more