Skip to content

[Go-Server] Support for an endpoint returning a file to the client - #15206#16748

Merged
wing328 merged 5 commits intoOpenAPITools:masterfrom
icubbon:go-server/bugFixes/fileDownload-15206
Oct 17, 2023
Merged

[Go-Server] Support for an endpoint returning a file to the client - #15206#16748
wing328 merged 5 commits intoOpenAPITools:masterfrom
icubbon:go-server/bugFixes/fileDownload-15206

Conversation

@icubbon
Copy link
Contributor

@icubbon icubbon commented Oct 6, 2023

The current Go-Server routers.mustache template does not support an endpoint returning a File to the client.

When the response is about to be sent out to the client, check if the any being sent is of type *os.File. If the item to be sent is a file, read the file into a byte slice and send it out.

The headers should still be written as dictated by the addResponseHeaders mustache variable.

This addresses #15206

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@lwj5 @wing328

@lwj5
Copy link
Contributor

lwj5 commented Oct 10, 2023

Hi @icubbon,

Similarly from the other PR. As there are currently no cases with file in the generation sample, it is difficult to see how the generated files will look.

Would you be able to add a new route that returns file in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml

then regenerate the code for go-server.

Let us know if you need any help with generation

@icubbon
Copy link
Contributor Author

icubbon commented Oct 11, 2023

Hi @icubbon,

Similarly from the other PR. As there are currently no cases with file in the generation sample, it is difficult to see how the generated files will look.

Would you be able to add a new route that returns file in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/go-server/petstore.yaml

then regenerate the code for go-server.

Let us know if you need any help with generation

Hi @lwj5, thank you for looking at these PRs. I added an example but since the changes were done in the router.mustache file, the generated api-controller file doesn't have any meaningful change as that code should look the same.

Copy link
Contributor

@lwj5 lwj5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the PR, I think it will motivate more changes in the future.

@wing328

@wing328 wing328 merged commit e0738a6 into OpenAPITools:master Oct 17, 2023
@wing328 wing328 added this to the 7.1.0 milestone Oct 17, 2023
@icubbon icubbon deleted the go-server/bugFixes/fileDownload-15206 branch October 18, 2023 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants