Home > Mobile >  unsupported type "invalid type" when using jwk.Key as swagger response type
unsupported type "invalid type" when using jwk.Key as swagger response type

Time:05-24

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

CodePudding user response:

Upgrading to version v0.29.0 solved the issue

  • Related