Skip to content

fix: add x-go-name for server urls#2304

Merged
mromaszewicz merged 3 commits intooapi-codegen:mainfrom
dhpollack:fix-allow-x-go-name-in-server-urls
Apr 8, 2026
Merged

fix: add x-go-name for server urls#2304
mromaszewicz merged 3 commits intooapi-codegen:mainfrom
dhpollack:fix-allow-x-go-name-in-server-urls

Conversation

@dhpollack
Copy link
Copy Markdown
Contributor

This allows one to use the x-go-name in the servers list. I wanted to customize the name instead of generating it from the description. I was able to do this with a server-urls.tmpl as a workaround. This seems like a simple enough feature that it could be implemented as the default behavior, which is why I also did not create an issue for it first. Although I could do that if you feel like it would be useful.

@dhpollack dhpollack requested a review from a team as a code owner March 26, 2026 12:11
@mromaszewicz mromaszewicz added the enhancement New feature or request label Apr 7, 2026
@mromaszewicz
Copy link
Copy Markdown
Member

@greptileai

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 7, 2026

Greptile Summary

This PR adds x-go-name support to OpenAPI server URL code generation, allowing users to override the auto-generated constant name with a custom Go identifier. The logic in server_urls.go correctly checks the extension and falls back to the existing description/URL-derived name when absent.

  • The error returned by extParseGoFieldName when x-go-name has an invalid type is silently swallowed and the code falls back to the auto-generated name, while every other x-go-name call-site in the codebase (renameSchema, renameParameter, renameResponse, renameRequestBody) propagates the error. This inconsistency means a mis-typed x-go-name value on a server entry silently produces the wrong constant name rather than failing loudly.

Confidence Score: 4/5

Safe to merge after addressing the silent error-swallowing in server_urls.go

One P1 finding: the extParseGoFieldName error is silently dropped, which is inconsistent with all other x-go-name handling in the codebase and can produce silently wrong output for malformed specs. The rest of the change is correct and well-tested.

pkg/codegen/server_urls.go — error from extParseGoFieldName should be propagated, not swallowed

Important Files Changed

Filename Overview
pkg/codegen/server_urls.go Adds x-go-name support for server URL naming; error from extParseGoFieldName is silently swallowed (inconsistent with all other x-go-name call sites that propagate the error)
examples/generate/serverurls/api.yaml Adds a new server entry demonstrating x-go-name usage; looks correct
examples/generate/serverurls/gen_test.go Adds a simple test asserting the x-go-name-derived constant has the correct URL value

Reviews (1): Last reviewed commit: "fix: add x-go-name for server urls" | Re-trigger Greptile

Comment thread pkg/codegen/server_urls.go
dhpollack and others added 2 commits April 8, 2026 18:57
do not swallow the extGoName error from automated review bot

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@mromaszewicz mromaszewicz merged commit 9aeaed3 into oapi-codegen:main Apr 8, 2026
17 checks passed
@mromaszewicz
Copy link
Copy Markdown
Member

Thanks.

@dhpollack
Copy link
Copy Markdown
Contributor Author

dhpollack commented Apr 8, 2026

Fyi, your bot responded that the original implementation was actually correct. I looked at the code and think the original suggestion to not swallow the error seems to be used and the follow-up is incorrect.

@dhpollack
Copy link
Copy Markdown
Contributor Author

I can create a follow-up to this if you need me to

@mromaszewicz
Copy link
Copy Markdown
Member

Nah, it's ok. It's not a place where it's important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants