괴발개발 성장기

Study/Error

[Error] 스웨거에서 cannot find type definition: json.RawMessage 에러 메시지

지니유 2023. 9. 5. 09:16
반응형

# 배경

스웨거(Swagger)에 돌리려고 하는데 아래의 에러 메시지가 발생했다.

 

# 에러 메시지

cannot find type definition: json.RawMessage

 

# 현상

type Banner struct {
	Id                 int64           `json:"id"`
	Type               string          `json:"type"`
	ImageUrl           json.RawMessage `json:"imageUrl" `
	Created            json.RawMessage `json:"created" `
}

struct에 json.RawMessage 타입은 지원하지 않는다. 그럴 때에는 무시하고 지나갈 수 있도록 할 수 있다. (필드를 제외할 수 있다)

swaggerignore:"true"

태그에 추가해주면 된다.

 

type Banner struct {
	Id                 int64           `json:"id"`
	Type               string          `json:"type"`
	ImageUrl           json.RawMessage `json:"imageUrl" swaggerignore:"true"`
	Created            json.RawMessage `json:"created" swaggerignore:"true"`
}

태그를 추가 해주면 에러가 해결된다.

 

 

# 참고

https://github.com/swaggo/swag#use-swaggerignore-tag-to-exclude-a-field

 

GitHub - swaggo/swag: Automatically generate RESTful API documentation with Swagger 2.0 for Go.

Automatically generate RESTful API documentation with Swagger 2.0 for Go. - GitHub - swaggo/swag: Automatically generate RESTful API documentation with Swagger 2.0 for Go.

github.com

 

반응형