-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Describe the bug
While using a custom types with generic parameters, swag command generates type as primitive type and can't generate enums for that type.
For example, assume that we have these types:
type Status[T any] string
type FooStatus struct{}
And we have these enumerations for FooStatus:
const (
FooActive Status[FooStatus] = "active"
FooDeleted Status[FooStatus] = "deleted"
)
And the generator only gets the underlying primitive type. But can not generate a enum for FooStatus
To Reproduce
Minimal example to reproduce:
package main
import "net/http"
type Status[T any] string
type Foo struct{}
const (
FooActive Status[Foo] = "active"
FooInactive Status[Foo] = "inactive"
)
type Model struct {
ID int `json:"id"`
Status Status[Foo] `json:"status"`
}
// @description This is a sample handler
// @tags example
// @accept json
// @produce json
// @success 200 {object} Model
// @router / [get]
func handler(w http.ResponseWriter, r *http.Request) {
var m Model
_ = m
w.WriteHeader(http.StatusOK)
}
// @title Sample API
// @version 1.0
// @description This is a sample API documentation
// @host localhost:8080
// @BasePath /
func main() {
http.HandleFunc("/", handler)
_ = http.ListenAndServe(":8080", nil)
}Expected behavior
basePath: /
definitions:
main.Model:
properties:
id:
type: integer
status:
$ref: '#/definitions/main.Status'
type: object
main.Status:
enum:
- active
- inactive
type: string
x-enum-varnames:
- FooActive
- FooInactive
host: localhost:8080
info:
contact: {}
description: This is a sample API documentation
title: Sample API
version: "1.0"
paths:
/:
get:
consumes:
- application/json
description: This is a sample handler
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/main.Model'
tags:
- example
swagger: "2.0"Screenshots
No screenshots
Your swag version
v1.16.4
Your go version
go version go1.25.4 darwin/arm64
Desktop (please complete the following information):
- OS: MacOS
- Browser: []
- Version: 26.1 (25B78)
Additional context
These kind of enumeration I am using to create a single type for my entire application and use it in different domains.
Metadata
Metadata
Assignees
Labels
No labels