docs(std-http-server): warn when not using Go 1.22#1967
Merged
jamietanna merged 1 commit intomainfrom May 9, 2025
Merged
Conversation
1adcd35 to
bfcdd6f
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a mechanism to warn users when the target module's Go version is below 1.22 for the std-http-server generation, helping avoid runtime issues such as unexpected 404 responses. Key changes include:
- Adding functions to locate and parse go.mod/tools.mod files and verify the Go version.
- Implementing warning generation in GenerateOptions and integrating warning output in the CLI.
- Updating the main command to display warnings when present.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/codegen/minimum_go_version.go | Introduces functions to search for and parse go.mod/tools.mod and checks for minimum Go version. |
| pkg/codegen/configuration.go | Adds warnings functionality for std-http-server generation based on the Go version in the module file. |
| cmd/oapi-codegen/oapi-codegen.go | Integrates warning output by printing any warnings returned from GenerateOptions into stderr. |
Files not reviewed (1)
- go.mod: Language not supported
| } | ||
|
|
||
| parentDir := filepath.Dir(currentDir) | ||
| if parentDir == "/" { |
There was a problem hiding this comment.
On non-Unix systems, using a hard-coded "/" as the root directory may lead to improper behavior; consider using a cross-platform approach to determine when to stop recursing upward.
Suggested change
| if parentDir == "/" { | |
| if parentDir == currentDir { |
Although this is less necessary after bumping our minimum Go version to 1.22 (in 0e8156a), it's still worthwhile ensuring that the module we're generating the code for is correctly set to Go 1.22, otherwise users will receive: HTTP/1.1 404 Not Found ... 404 page not found To do this, we can introduce a new means to flag "warnings" that need to be output. We need to make sure we're using `ParseLax` to reduce the risk of new directives or content being introduced into a `go.mod` breaking `oapi-codegen`. This is a step towards being able to implement future warnings to ensure that consumers are using correct Go versions. Closes #1628. [0]: https://www.jvt.me/posts/2024/03/04/go-net-http-why-404/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Although this is less necessary after bumping our minimum Go version to
1.22 (in 0e8156a), it's still
worthwhile ensuring that the module we're generating the code for is
correctly set to Go 1.22, otherwise users will receive:
To do this, we can introduce a new means to flag "warnings" that need to
be output.
We need to make sure we're using
ParseLaxto reduce the risk of newdirectives or content being introduced into a
go.modbreakingoapi-codegen.This is a step towards being able to implement future warnings to ensure
that consumers are using correct Go versions.
Closes #1628.
Warning
I'm not quite sure about this - especially for
oapi-codegen-as-a-library