Skip to content

[go-server] Moved helper code from router and updated logger for chi #20823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 9, 2025

Conversation

jarangutan
Copy link
Contributor

Addresses #20817

Moves the helper code not used in the NewRouter function within routers.go into the helpers.go file. This way the router.go file is clean for when users want to take over it when they want to add or update middlewares not yet supported by the generator.

This MR also updates the NewRouter function for chi middleware to use the logger file rather than hardcode the default chi logger. This allows for a user to take over the logger file without needing to take over the router file. That lets users be able to update the default logger logic which matches the behavior of the mux router.

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 || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    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*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.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.

@antihax (2017/11) @grokify (2018/07) @kemokemo (2018/09) @jirikuncar (2021/01) @ph4r5h4d (2021/04) @lwj5 (2023/04)

@jarangutan
Copy link
Contributor Author

Please let me know if it would be better to split this into two MRs. One for the router helper move and one for the logger update. I thought doing both since they're related might be ok

@jarangutan jarangutan force-pushed the go-server-router-update branch from 9d321e6 to ba4c1d7 Compare March 8, 2025 00:15
@lwj5
Copy link
Contributor

lwj5 commented Mar 8, 2025

I think you can remove middleware import from router

@jarangutan
Copy link
Contributor Author

I think you can remove middleware import from router

Yep I can! Sorry about that. Let me do another pass and see if I find anything else goofy I may have left

@jarangutan
Copy link
Contributor Author

Fixed the imports for chi and mux and reran the servers to make sure logs were still being spat out correctly. Missed the problem the first time due to my autoformatter kicking in and fixing imports for me

@lwj5
Copy link
Contributor

lwj5 commented Mar 8, 2025

@wing328 could you help to run the workflows

So far lgtm

@wing328
Copy link
Member

wing328 commented Mar 8, 2025

@lwj5 thanks for reviewing the change

@jarangutan thanks for the PR

@wing328
Copy link
Member

wing328 commented Mar 8, 2025

@jarangutan
Copy link
Contributor Author

@wing328 checked it. The samples_tests/routers_test.go was expecting the line "type Routes map[string]Route" to be on line 34 but my change had removed a lot of imports when I moved the helper logic which caused this line to go up to line 25.

@jarangutan
Copy link
Contributor Author

To make sure, the samples_tests in that go-api-server folder wasn't auto generated right? I was checking to see if it was being made by something but couldn't find it

@wing328 wing328 added Server: Go Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc. labels Mar 9, 2025
@wing328 wing328 added this to the 7.13.0 milestone Mar 9, 2025
@wing328
Copy link
Member

wing328 commented Mar 9, 2025

yes, those manually written tests need to be updated manually as part of this PR

thanks for the contribution, which looks good

@wing328 wing328 merged commit 4ad76cc into OpenAPITools:master Mar 9, 2025
21 checks passed
@jarangutan
Copy link
Contributor Author

Gotcha 👍! And thank you and @lwj5 for the reviews!
Appreciate the partnership :D

kpy3 pushed a commit to kpy3/openapi-generator that referenced this pull request Mar 13, 2025
…penAPITools#20823)

* [go-server] Moved helper code from router and updated logger

* [go-server] fixed imports for mux and chi

* [go-server] fix go-api-server sample test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc. Server: Go
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants