Skip to content

Conversation

@HermanPlay
Copy link

@HermanPlay HermanPlay commented Oct 12, 2025

Describe the PR
During swag init when using useStructName flag. Fixed the issue where types using in generic were generated with full path instead of only type name.

Relation issue
Expands changes introduced in #2043

Additional context
Assume following code example:

import (
	"github.com/mini-maxit/backend/internal/api/http/httputils"
	"github.com/mini-maxit/backend/package/domain/schemas"
)

// @Success      200 {object} httputils.APIResponse[schemas.WorkerStatus]
func foo() {}

When generating swagger with swag init --st --dir . --ot yaml --st
The resulting type definition in swagger looked something like:

APIResponse-github_com_mini-maxit_backend_package_domain_schemas_WorkerStatus:
  properties:
    data:
      $ref: '#/definitions/WorkerStatus'
    ok:
      type: boolean
  type: object

We see that APIResponse is generated correctly with only struct name, when type used in generic is generated with full path.

After change the definion looks correct, with underling generic type shortened:

APIResponse-WorkerStatus:
  properties:
    data:
      $ref: '#/definitions/WorkerStatus'
    ok:
      type: boolean
  type: object

I know the tests are broken now. However, I cannot think of any better solution right, and help is welcomed and will be highly appreciated

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

Labels

None yet

1 participant