英文:
unsupported type "invalid type" when using jwk.Key as swagger response type
问题
我有以下的端点:
package token
import (
"crypto/rsa"
"github.com/dhis2-sre/im-user/pkg/config"
"github.com/dhis2-sre/im-user/pkg/token/helper"
"github.com/gin-gonic/gin"
"log"
"net/http"
)
func ProvideHandler(config config.Config) Handler {
publicKey, err := config.Authentication.Keys.GetPublicKey()
if err != nil {
log.Fatalln(err)
}
return Handler{
publicKey,
}
}
type Handler struct {
publicKey *rsa.PublicKey
}
// Jwks godoc
// swagger:route GET /jwks Jwks
//
// 返回一个包含公钥的JWKS,用于验证在/signin处分发的JWT
//
// responses:
// 200: Jwks
// 415: Error
// 500: Error
func (h *Handler) Jwks(c *gin.Context) {
jwks, err := helper.CreateJwks(h.publicKey)
if err != nil {
_ = c.Error(err)
return
}
c.JSON(http.StatusOK, jwks)
}
以及以下的swagger响应定义:
package token
import "github.com/lestrrat-go/jwx/jwk"
// swagger:response Jwks
type _ struct {
//in: body
_ jwk.Key
}
但是当我尝试使用以下命令生成规范时:
swagger generate spec -o swagger/swagger.yaml -x swagger/sdk --scan-models
我得到以下错误:
unsupported type "invalid type"
如果我使用interface{}
而不是jwk.Key
,我可以生成规范而不出错,但显然那不是我想要的类型。
英文:
I have the following endpoint
package token
import (
"crypto/rsa"
"github.com/dhis2-sre/im-user/pkg/config"
"github.com/dhis2-sre/im-user/pkg/token/helper"
"github.com/gin-gonic/gin"
"log"
"net/http"
)
func ProvideHandler(config config.Config) Handler {
publicKey, err := config.Authentication.Keys.GetPublicKey()
if err != nil {
log.Fatalln(err)
}
return Handler{
publicKey,
}
}
type Handler struct {
publicKey *rsa.PublicKey
}
// Jwks godoc
// swagger:route GET /jwks Jwks
//
// Return a JWKS containing the public key which can be used to validate the JWT's dispensed at /signin
//
// responses:
// 200: Jwks
// 415: Error
// 500: Error
func (h *Handler) Jwks(c *gin.Context) {
jwks, err := helper.CreateJwks(h.publicKey)
if err != nil {
_ = c.Error(err)
return
}
c.JSON(http.StatusOK, jwks)
}
Along with the following swagger response definition
package token
import "github.com/lestrrat-go/jwx/jwk"
// swagger:response Jwks
type _ struct {
//in: body
_ jwk.Key
}
But when I try to generate the spec using the below command
swagger generate spec -o swagger/swagger.yaml -x swagger/sdk --scan-models
I get the following error
unsupported type "invalid type"
If I use interface{}
rather than jwk.Key I can generate the spec without errors but obviously that's not the type I want
答案1
得分: 0
升级到版本v0.29.0解决了这个问题。
英文:
Upgrading to version v0.29.0 solved the issue
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论