Skip to content

fix(goctl/swagger): ignore '-' tags in parameters and properties#5544

Open
TanishValesha wants to merge 1 commit into
zeromicro:masterfrom
TanishValesha:fix/goctl-swagger-ignore-dash-tags
Open

fix(goctl/swagger): ignore '-' tags in parameters and properties#5544
TanishValesha wants to merge 1 commit into
zeromicro:masterfrom
TanishValesha:fix/goctl-swagger-ignore-dash-tags

Conversation

@TanishValesha

Copy link
Copy Markdown

Fixes #5427

Summary

  • Fix swagger generation to treat "-" tag names as ignored fields instead of emitting parameters/properties named "-".
  • Prevent invalid/duplicate OpenAPI parameter entries such as repeated (in=query, name="-") caused by multiple form:"-" fields.
  • Add regression tests covering form:"-" in parameters and json:"-" in schema properties.

What changed

  • Updated tools/goctl/api/swagger/parameter.go
    • Added ignore handling for header, path, form, and json tags when tag name is "-".
  • Updated tools/goctl/api/swagger/properties.go
    • Skip schema property generation for json:"-".
  • Added tests:
    • TestParametersFromType_IgnoreDashTagName in tools/goctl/api/swagger/parameter_test.go
    • TestPropertiesFromType_IgnoresJsonDashTag in tools/goctl/api/swagger/swagger_test.go
Swagger generation should treat struct tags like form:"-" and json:"-" as ignored fields.
This prevents emitting parameters/properties named "-" and avoids duplicate (in,name) entries.

Made-with: Cursor
@kevwan kevwan added kind/bug Something isn't working area/goctl Categorizes issue or PR as related to goctl. labels Apr 30, 2026
@kevwan

kevwan commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Review

Good fix for a swagger generation correctness issue (fixes #5427).

Problem: Fields with json:"-", form:"-", etc. are conventionally ignored by Go's encoding packages. However, goctl's swagger generator was emitting them as parameters/properties named "-", which is invalid per OpenAPI spec.

Changes:

  • parameter.go: Skips header, path, form, json tags when the tag name is "-"
  • properties.go: Skips schema property generation for json:"-"
  • Tests added for both cases

Suggestions:

  1. Are query:"-" tags also ignored? The current fix covers form but not query explicitly — check if there's a separate query tag handling path that also needs this.
  2. The change is minimal and targeted. ✅

Code quality: Straightforward conditional checks matching Go's encoding/json convention. The tests cover the primary scenarios.

LGTM — clean fix for a well-defined spec violation.

@TanishValesha

Copy link
Copy Markdown
Author

@kevwan Thanks for the review and sorry for this late reply!
I checked the swagger parameter flow: there isn’t a separate 'query' tag path here. GET query parameters are generated from form tags, so form:"-" is the relevant ignore case for query params in this codebase. The current fix already covers the actual emission path, so there’s no additional query:"-" handling needed.

@TanishValesha

Copy link
Copy Markdown
Author

@kevwan lmk, if there is any problem with merging this PR ?

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

Labels

area/goctl Categorizes issue or PR as related to goctl. kind/bug Something isn't working

2 participants