Closed yunkon-kim closed 3 weeks ago
I tried the type alias below but encountered the same error.
Type alias
// Type Aliases to recognize external structs
type Infra = infra.Infra
type RecommendInfraRequest struct {
Infra
}
Until a repository that manages only models is set up, the get-source-models.sh
script will be used.
Then, we could replace the script with git submodule
.
@niconicodex 안녕하세요.
이후 CM-Honeybee에서 Swagger documenation을 적용하실 때에도 아래 이슈가 동일하게 발생할 것 같아 공유를 드립니다.
외부 저장소 package 를 임포트한 후, 해당 package의 struct를 사용하실 경우에 발생하는 이슈입니다.
Go 에서는 이슈가 되지 않으나, swag init
시에 프로젝트 내에 실제 소스파일이 없어 발생하는 이슈로 판단됩니다. 참고하시기 바랍니다.
2023/12/13 17:46:43 Error parsing type definition 'network.LibvirtDomain': interfaces: cannot find type definition: libvirtxml.DomainInterface
2023/12/13 17:46:43 Error parsing type definition 'network.LibvirtNet': domains: LibvirtDomain: interfaces: cannot find type definition: libvirtxml.DomainInterface
2023/12/13 17:46:43 Error parsing type definition 'network.VirtualNetwork': libvirt_net: LibvirtNet: domains: LibvirtDomain: interfaces: cannot find type definition: libvirtxml.DomainInterface
2023/12/13 17:46:43 Error parsing type definition 'network.Network': virtual_network: VirtualNetwork: libvirt_net: LibvirtNet: domains: LibvirtDomain: interfaces: cannot find type definition: libvirtxml.DomainInterface
2023/12/13 17:46:43 Error parsing type definition 'infra.Infra': network: network.Network: virtual_network: VirtualNetwork: libvirt_net: LibvirtNet: domains: LibvirtDomain: interfaces: cannot find type definition: libvirtxml.DomainInterface
2023/12/13 17:46:43 Error parsing type definition 'controller.RecommendInfraRequest': : infra.Infra: network: network.Network: virtual_network: VirtualNetwork: libvirt_net: LibvirtNet: domains: LibvirtDomain: interfaces: cannot find type definition: libvirtxml.DomainInterface
참고 - 이슈가 있는 두 항목을 주석 처리후, swag init
시 이슈 없음
type Infra struct {
Compute Compute `json:"compute"`
// Network network.Network `json:"network"`
// GPU GPU `json:"gpu"`
}
참고 - Swagger UI
: 온프레미스 모델 동기화 스크립트(get-onprem-models.sh) 사용하여 cm-honeybee의 모델 파일들을 cm-beetle로 동기화
: swag init
시 다음 에러 발생
Error parsing type definition 'controller.RecommendInfraRequest': : cannot find type definition: onpremmodel.Infra
: (원인) 아래와 같이 모델 pkg를 import 및 alias 적용 한 경우 이를 참조하지 못하기 때문
: infra
를 onpremmodel
로 alias
import (
onpremmodel "github.com/cloud-barista/cm-beetle/pkg/api/rest/model/onprem/infra"
)
type RecommendInfraRequest struct {
onpremmodel.Infra
}
type RecommendInfraResponse struct {
cloudmodel.TbMcisDynamicReq
}
// RecommendInfra godoc
// @Summary Recommend an appropriate infrastructure for cloud migration
// @Description It recommends a cloud infrastructure most similar to the input. Infrastructure includes network, storage, compute, and so on.
// @Tags [Recommendation] Infrastructure
// @Accept json
// @Produce json
// @Param UserInfrastructure body RecommendInfraRequest true "Specify network, disk, compute, security group, virtual machine, etc."
// @Success 200 {object} RecommendInfraResponse "Successfully recommended an appropriate infrastructure for cloud migration"
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /recommendation/infra [post]
func RecommendInfra(c echo.Context) error {
...
}
📌 의견: : API로 제공되는 모델에 대해서는 pkg import시 alias 적용이 불가할 것으로 판단됨
: swag init
시 다음 에러 발생
Error parsing type definition 'infra.GPU': nvidia: cannot find type definition: nvidia.NVIDIA
Error parsing type definition 'infra.Infra': gpu: GPU: nvidia: cannot find type definition: nvidia.NVIDIA
Error parsing type definition 'controller.RecommendInfraRequest': : infra.Infra: gpu: GPU: nvidia: cannot find type definition: nvidia.NVIDIA
: (원인) 해당 스트럭트가 동기화 되지 않았기 때문
package infra
import (
"github.com/cloud-barista/cm-honeybee/agent/gpu/drm"
"github.com/cloud-barista/cm-honeybee/agent/gpu/nvidia"
)
type GPU struct {
NVIDIA []nvidia.NVIDIA `json:"nvidia"`
DRM []drm.DRM `json:"drm"`
}
📌 의견: : GPU 관련 모델도 model/onprem 또는 하위 경로 상에 위치해야할 것으로 보임 (from) https://github.com/cloud-barista/cm-honeybee/tree/main/agent/gpu (to) https://github.com/cloud-barista/cm-honeybee/tree/main/agent/pkg/api/rest/model/onprem
해당 커밋에 의해 말씀하신 문제 수정되었습니다. 감사합니다. https://github.com/cloud-barista/cm-honeybee/commit/0963d03537a4bd0eaaf504cb30965b3137a79834
@yunkon-kim @seokho-son
[개요]
make swag
2023/12/10 23:07:05 Error parsing type definition 'controller.RecommendInfraRequest': : cannot find type definition: infra.Infra 2023/12/10 23:07:05 Skipping 'controller.RecommendInfraRequest', recursion detected.
[방안]
swag init --parseDependency
Go mod 환경에서는 다음과 같은 오류 발생했었으며, 오류 메시지 상관 없이 swag 동작에는 문제가 없었지만,
... 중략
go/build: go list reflect: fork/exec /snap/go/10489/bin/go: no such file or directory
... 중략
다음 설정 후 실행하면 에러 메시지도 안보입니다.
# 환경 확인
go env |grep GOPATH
GOPATH='/home/ubuntu/go'
go env | grep GOROOT
GOROOT='/snap/go/10627'
# 환경 설정
export GOPATH='/home/ubuntu/go'
export GOROOT='/snap/go/10627'
[세부]
main.go: external struct인 irs.KeyValue 참조 예제
package main
import (
"net/http"
"github.com/gin-gonic/gin"
_ "swagger_test/docs" // Swagger docs dir.
ginSwagger "github.com/swaggo/gin-swagger"
swaggerFiles "github.com/swaggo/files"
irs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
)
// Data struct defines the structure for storing a name and an external key value.
// @Description The structure for storing name and associated key value.
// @schemaprops externalKeyValue=KeyValue
type Data struct {
Name string `json:"name" example:"Example Name"`
ExternalKeyValue irs.KeyValue `json:"externalKeyValue"` <================
}
// @Summary Add new data
// @Description Add a new data with name and key value.
// @ID add-data
// @Accept json
// @Produce json
// @Param data body Data true "Data structure"
// @Success 200 {object} Data
// @Router /data [post]
func postData(c *gin.Context) {
var newData Data
if err := c.ShouldBindJSON(&newData); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
// Code to add new data to database or in-memory data structure
c.JSON(http.StatusOK, newData)
}
// @title Example API
// @version 1.0
// @description This is a sample server for a data management system.
// @host localhost:8080
// @basePath /v1
func main() {
router := gin.Default()
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
router.POST("/data", postData)
router.Run(":8080")
}
swag init 실행
swag init --parseDependency
2024/06/09 11:28:49 Generate swagger docs....
2024/06/09 11:28:49 Generate general API Info, search dir:./
2024/06/09 11:28:53 Generating main.Data
2024/06/09 11:28:53 Generating resources.KeyValue
2024/06/09 11:28:53 create docs.go at docs/docs.go
2024/06/09 11:28:53 create swagger.json at docs/swagger.json
2024/06/09 11:28:53 create swagger.yaml at docs/swagger.yaml
API Docs 결과 page 참고
[기타]
Dependency Level
을 조절해야 할수도 있을 듯합니다.
swag init -h |grep parseDependency
--parseDependencyLevel value, --pdl value Parse go files inside dependency folder, 0 disabled, 1 only parse models, 2 only parse operations, 3 parse all (default: 0)
--parseDependency, --pd Parse go files inside dependency folder, disabled by default (default: false)
@powerkimhub
외부 패키지 활용 및 API docs 생성 방안을 공유해주셔서 감사드립니다.
먼저, 소스 컴퓨팅 인프라 형상 정보 메트릭, 소스 모델(온프레미스 모델), 목표 모델(클라우드 모델), API 요청/응답 바디 구조체 등에 실 적용 및 테스트를 진행하고요. 이후에 플랫폼 전체에 확대 적용하는 것으로 추진해보겠습니다. (행사 이후 추진)
공유해주신 아래 내용에 대해 한가지 질문이 있습니다. 기존에 설정되어 있는 GOPATH
와 GOROOT
를 특정 디렉토리로 변경해야하는 것으로 보이는데요. 10627 디렉토리가 고정되어 있는 디렉토리인지 문의드립니다. 혹시 go get
등으로 패키지를 업데이트 하는 경우에도 동일 디렉토리를 활용해도 괜찮을까요?
다음 설정 후 실행하면 에러 메시지도 안보입니다.
# 환경 확인 go env |grep GOPATH GOPATH='/home/ubuntu/go' go env | grep GOROOT GOROOT='/snap/go/10627'
# 환경 설정 export GOPATH='/home/ubuntu/go' export GOROOT='/snap/go/10627'
@yunkon-kim
공유해주신 아래 내용에 대해 한가지 질문이 있습니다. 기존에 설정되어 있는
GOPATH
와GOROOT
를 특정 디렉토리로 변경해야하는 것으로 보이는데요. 10627 디렉토리가 고정되어 있는 디렉토리인지 문의드립니다. 혹시go get
등으로 패키지를 업데이트 하는 경우에도 동일 디렉토리를 활용해도 괜찮을까요?
swag init --parseDependency
GOPATH
와 GOROOT
를 설정하시면 되겠습니다.GOPATH
와 GOROOT
설정 방법을 사용하시면 되겠습니다. @powerkimhub
네 알겠습니다. 설명 감사드립니다.
@powerkimhub @seokho-son
CM-Beetle에서 아래 둘을 import 하는 방식으로 테스트를 진행해 봤습니다.
결론부터 공유드립니다.
main.go
상단에 'Swagger general API info' 기재main.go
를 프로젝트 Root에 위치 시킴 (아마도, go.mod
와 같이 있어야하는 것으로 추측됨)go get -u xxx
시 의도치 않게 pkg가 밀려들어오거나, 업데이트되는 상황이 발생 (리스크?)이후는 테스트 결과입니다. 살펴보시면 될 것 같습니다.
사전에, CM-Beetle에서는 'Swagger general API info'를 server.go
상단에 기재하고 있음을 말씀드립니다.
: 참고 - Swagger general API info
// @title CM-Beetle REST API
// @version latest
// @description CM-Beetle REST API
// @contact.name API Support
// @contact.url http://cloud-barista.github.io
// @contact.email contact-to-cloud-barista@googlegroups.com
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @BasePath /beetle
// @securityDefinitions.basic BasicAuth
이를 바탕으로 몇 가지 케이스를 통해 현황을 공유드립니다.
server.go
, go.mod
, main.go
의 위치에 따라 문서가 다른 결과를 보이고 있습니다.
Case 1: 외부 pkg import 방식으로 수정, --parseDependency
옵션 추가, swag init
수행
: 관련 디렉토리 및 파일 구조
.
├── cmd
│ └── cm-beetle
│ └── main.go
├── go.mod
├── go.sum
├── go.work
├── go.work.sum
└── pkg
└── api
└── rest
├── common
├── controller
├── middlewares
├── model
├── route
└── server.go
: swag init
명령어
~/go/bin/swag i \
--parseDependency \
--generalInfo ./pkg/api/rest/server.go \
--dir ./ \
--output ./api
: 결과 - import 된 패키지 포함하여 API 문서 생성 성공, CM-Beetle 내부의 패키지에 대해서는 _
가 나타나기 시작 (곤란함...)
2024/07/18 10:35:46 Generate swagger docs....
2024/07/18 10:35:46 Generate general API Info, search dir:./
2024/07/18 10:35:46 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /home/ubuntu/dev/cloud-barista/cm-beetle
2024/07/18 10:35:50 Generating pkg_api_rest_common.SimpleMessage
2024/07/18 10:35:50 Generating github_com_cloud-barista_cm-beetle_pkg_core_common.SimpleMsg
2024/07/18 10:35:50 Generating pkg_api_rest_controller.MigrateInfraRequest
2024/07/18 10:35:50 Generating mcis.TbMcisDynamicReq
2024/07/18 10:35:50 Generating mcis.TbVmDynamicReq
2024/07/18 10:35:50 Generating pkg_api_rest_controller.MigrateInfraResponse
2024/07/18 10:35:50 Generating github_com_cloud-barista_cm-beetle_pkg_api_rest_model_beetle.Response
2024/07/18 10:35:50 Generating github_com_cloud-barista_cm-beetle_pkg_core_common.RestGetAllNsResponse
2024/07/18 10:35:50 Generating github_com_cloud-barista_cm-beetle_pkg_core_common.NsInfo
2024/07/18 10:35:50 Generating github_com_cloud-barista_cm-beetle_pkg_core_common.NsReq
2024/07/18 10:35:50 Generating pkg_api_rest_controller.RecommendInfraRequest
2024/07/18 10:35:50 Generating infra.Infra
2024/07/18 10:35:50 Generating infra.Compute
2024/07/18 10:35:50 Generating infra.System
2024/07/18 10:35:50 Generating infra.OS
2024/07/18 10:35:50 Generating infra.Kernel
2024/07/18 10:35:50 Generating infra.Node
2024/07/18 10:35:50 Generating infra.ComputeResource
2024/07/18 10:35:50 Generating infra.CPU
2024/07/18 10:35:50 Generating infra.Memory
2024/07/18 10:35:50 Generating infra.Disk
2024/07/18 10:35:50 Generating infra.Connection
2024/07/18 10:35:50 Generating infra.Keypair
2024/07/18 10:35:50 Generating network.Network
2024/07/18 10:35:50 Generating network.Host
2024/07/18 10:35:50 Generating network.NIC
2024/07/18 10:35:50 Generating network.DNS
2024/07/18 10:35:50 Generating network.Route
2024/07/18 10:35:50 Generating network.FirewallRule
2024/07/18 10:35:50 Generating network.CSP
2024/07/18 10:35:50 Generating network.VPC
2024/07/18 10:35:50 Generating network.Subnet
2024/07/18 10:35:50 Generating network.NLB
2024/07/18 10:35:50 Generating network.SecurityGroup
2024/07/18 10:35:50 Generating infra.GPU
2024/07/18 10:35:50 Generating infra.NVIDIA
2024/07/18 10:35:50 Generating infra.NVIDIADeviceAttribute
2024/07/18 10:35:50 Generating infra.NVIDIAPerformance
2024/07/18 10:35:50 Generating infra.DRM
2024/07/18 10:35:50 Generating infra.Storage
2024/07/18 10:35:50 Generating infra.MountPoint
2024/07/18 10:35:50 Generating infra.MountedInformation
2024/07/18 10:35:50 Generating pkg_api_rest_controller.RecommendInfraResponse
2024/07/18 10:35:50 Generating pkg_api_rest_controller.GetUsersResponse
2024/07/18 10:35:50 Generating github_com_cloud-barista_cm-beetle_pkg_api_rest_model.MyUser
2024/07/18 10:35:50 Generating pkg_api_rest_controller.GetUserResponse
2024/07/18 10:35:50 Generating pkg_api_rest_controller.CreateUserRequest
2024/07/18 10:35:50 Generating pkg_api_rest_controller.UpdateUserRequest
2024/07/18 10:35:50 Generating pkg_api_rest_controller.UpdateUserResponse
2024/07/18 10:35:50 Generating pkg_api_rest_controller.PatchUserRequest
2024/07/18 10:35:50 Generating pkg_api_rest_controller.PatchUserResponse
2024/07/18 10:35:50 create docs.go at api/docs.go
2024/07/18 10:35:50 create swagger.json at api/swagger.json
2024/07/18 10:35:50 create swagger.yaml at api/swagger.yaml
:결과 - UI 상에서 외부 패키지는 일반적으로 출력됙, 내부 패키지가 곤란하게 출력됨
Case 2: server.go
상단의 'Swagger general API info'를 main.go
로 이동, swag init
수행
: 관련 디렉토리 및 파일 구조 Case 1과 동일
: swag init
명령어
~/go/bin/swag i \
--parseDependency \
--generalInfo ./cmd/cm-beetle/main.go \
--dir ./ \
--output ./api
: 결과 - Case 1과 동일 (생략)
Case 3: main.go
을 Project root로 이동, swag init
수행
: 관련 디렉토리 및 파일 구조
.
├── cmd
│ └── cm-beetle
├── main.go
├── go.mod
├── go.sum
├── go.work
├── go.work.sum
└── pkg
└── api
└── rest
├── common
├── controller
├── middlewares
├── model
├── route
└── server.go
: swag init
명령어
~/go/bin/swag i \
--parseDependency \
--generalInfo ./main.go \
--dir ./ \
--output ./api
: 결과 - 일부 개선됨, CM-Beetle 내부의 패키지에 대해서는 _
가 나타나는 상황이 줄어듬,
: 2024/07/18 10:48:11 Generating github_com_cloud-barista_cm-beetle_pkg_core_common.SimpleMsg
등은 여전히 개선되지 않음
2024/07/18 10:48:05 Generate swagger docs....
2024/07/18 10:48:05 Generate general API Info, search dir:./
2024/07/18 10:48:11 Generating common.SimpleMessage
2024/07/18 10:48:11 Generating github_com_cloud-barista_cm-beetle_pkg_core_common.SimpleMsg
2024/07/18 10:48:11 Generating controller.MigrateInfraRequest
2024/07/18 10:48:11 Generating mcis.TbMcisDynamicReq
2024/07/18 10:48:11 Generating mcis.TbVmDynamicReq
2024/07/18 10:48:11 Generating controller.MigrateInfraResponse
2024/07/18 10:48:11 Generating model.Response
2024/07/18 10:48:11 Generating common.RestGetAllNsResponse
2024/07/18 10:48:11 Generating github_com_cloud-barista_cm-beetle_pkg_core_common.NsInfo
2024/07/18 10:48:11 Generating github_com_cloud-barista_cm-beetle_pkg_core_common.NsReq
2024/07/18 10:48:11 Generating controller.RecommendInfraRequest
2024/07/18 10:48:11 Generating infra.Infra
2024/07/18 10:48:11 Generating infra.Compute
2024/07/18 10:48:11 Generating infra.System
2024/07/18 10:48:11 Generating infra.OS
2024/07/18 10:48:11 Generating infra.Kernel
2024/07/18 10:48:11 Generating infra.Node
2024/07/18 10:48:11 Generating infra.ComputeResource
2024/07/18 10:48:11 Generating infra.CPU
2024/07/18 10:48:11 Generating infra.Memory
2024/07/18 10:48:11 Generating infra.Disk
2024/07/18 10:48:11 Generating infra.Connection
2024/07/18 10:48:11 Generating infra.Keypair
2024/07/18 10:48:11 Generating network.Network
2024/07/18 10:48:11 Generating network.Host
2024/07/18 10:48:11 Generating network.NIC
2024/07/18 10:48:11 Generating network.DNS
2024/07/18 10:48:11 Generating network.Route
2024/07/18 10:48:11 Generating network.FirewallRule
2024/07/18 10:48:11 Generating network.CSP
2024/07/18 10:48:11 Generating network.VPC
2024/07/18 10:48:11 Generating network.Subnet
2024/07/18 10:48:11 Generating network.NLB
2024/07/18 10:48:11 Generating network.SecurityGroup
2024/07/18 10:48:11 Generating infra.GPU
2024/07/18 10:48:11 Generating infra.NVIDIA
2024/07/18 10:48:11 Generating infra.NVIDIADeviceAttribute
2024/07/18 10:48:11 Generating infra.NVIDIAPerformance
2024/07/18 10:48:11 Generating infra.DRM
2024/07/18 10:48:11 Generating infra.Storage
2024/07/18 10:48:11 Generating infra.MountPoint
2024/07/18 10:48:11 Generating infra.MountedInformation
2024/07/18 10:48:11 Generating controller.RecommendInfraResponse
2024/07/18 10:48:11 Generating controller.GetUsersResponse
2024/07/18 10:48:11 Generating model.MyUser
2024/07/18 10:48:11 Generating controller.GetUserResponse
2024/07/18 10:48:11 Generating controller.CreateUserRequest
2024/07/18 10:48:11 Generating controller.UpdateUserRequest
2024/07/18 10:48:11 Generating controller.UpdateUserResponse
2024/07/18 10:48:11 Generating controller.PatchUserRequest
2024/07/18 10:48:11 Generating controller.PatchUserResponse
2024/07/18 10:48:11 create docs.go at api/docs.go
2024/07/18 10:48:11 create swagger.json at api/swagger.json
2024/07/18 10:48:11 create swagger.yaml at api/swagger.yaml
:결과 - UI 상에서도 개선됨
: github_com_cloud-barista_cm-beetle_pkg_core_common.SimpleMsg
해소 관련
: 참고 - 재정의/명시
type SimpleMessage struct {
common.SimpleMsg
}
: 결과 - SimpleMessage 사용
: 결과 - common.SimpleMsg 사용
@innodreamer CM-Damselfly 측면에서 한번 살펴봐 주시면 좋을 것 같습니다.
최근 pkg들을 정리한 이후, 내부 패키지 및 구조체의 명칭에 _
가 붙었던 증상이 해소되어 공유차원에서 남겨 놓습니다.
증상 참고: github_com_cloud-barista_cm-beetle_pkg_core_common.SimpleMsg
현황: CB-Tumblebug 및 cm-model 저장소의 pkg 를 import해서 활용 중이고, 결과가 아래와 같습니다.
Generating Swagger API documentation...
2024/09/09 19:02:13 Generate swagger docs....
2024/09/09 19:02:13 Generate general API Info, search dir:./
2024/09/09 19:02:21 Generating common.SimpleMessage
2024/09/09 19:02:21 Generating common.SimpleMsg
2024/09/09 19:02:21 Generating controller.MigrateInfraRequest
2024/09/09 19:02:21 Generating model.TbMciDynamicReq
2024/09/09 19:02:21 Generating model.TbVmDynamicReq
2024/09/09 19:02:21 Generating controller.MigrateInfraResponse
2024/09/09 19:02:21 Generating model.Response
2024/09/09 19:02:21 Generating controller.RecommendInfraRequest
2024/09/09 19:02:21 Generating onprem.OnPremInfra
2024/09/09 19:02:21 Generating onprem.NetworkProperty
2024/09/09 19:02:21 Generating onprem.ServerProperty
2024/09/09 19:02:21 Generating onprem.CpuProperty
2024/09/09 19:02:21 Generating onprem.MemoryProperty
2024/09/09 19:02:21 Generating onprem.DiskProperty
2024/09/09 19:02:21 Generating onprem.NetworkInterfaceProperty
2024/09/09 19:02:21 Generating onprem.OsProperty
2024/09/09 19:02:21 Generating controller.RecommendInfraResponse
2024/09/09 19:02:21 Generating recommendation.RecommendedInfraInfo
2024/09/09 19:02:21 Generating controller.GetUsersResponse
2024/09/09 19:02:21 Generating model.MyUser
2024/09/09 19:02:21 Generating controller.GetUserResponse
2024/09/09 19:02:21 Generating controller.CreateUserRequest
2024/09/09 19:02:21 Generating controller.UpdateUserRequest
2024/09/09 19:02:21 Generating controller.UpdateUserResponse
2024/09/09 19:02:21 Generating controller.PatchUserRequest
2024/09/09 19:02:21 Generating controller.PatchUserResponse
2024/09/09 19:02:21 create docs.go at api/docs.go
2024/09/09 19:02:21 create swagger.json at api/swagger.json
2024/09/09 19:02:21 create swagger.yaml at api/swagger.yaml
Generated Swagger API documentation!
@powerkimhub @seokho-son @innodreamer @ish-hcc
관련 사항이 충분한 테스트 되었고, 모델(Go struct) import 및 swag init 방법도 자리를 잡아가고 있어 Close 합니다.
It seems that external structs are not recognized when executing
swag init
.What I've done
import ( "fmt" "net/http"
)
Click to see full source code
```go // Package common is to handle REST API for common funcitonalities package controller import ( "fmt" "net/http" "github.com/cloud-barista/cm-honeybee/model/infra" "github.com/labstack/echo/v4" ) type Infrastructure struct { Network string Disk string Compute string SecurityGroup string VirtualMachine string } type RecommendInfraRequest struct { infra.Infra } type RecommendInfraResponse struct { Infrastructure } // RecommendInfra godoc // @Summary Recommend an appropriate infrastructure for cloud migration // @Description It recommends a cloud infrastructure most similar to the input. Infrastructure includes network, storage, compute, and so on. // @Tags [Recommendation] Infrastructure // @Accept json // @Produce json // @Param UserInfrastructure body RecommendInfraRequest true "Specify network, disk, compute, security group, virtual machine, etc." // @Success 200 {object} RecommendInfraResponse "Successfully recommended an appropriate infrastructure for cloud migration" // @Failure 404 {object} common.SimpleMsg // @Failure 500 {object} common.SimpleMsg // @Router /recommendation/infra [post] func RecommendInfra(c echo.Context) error { // Input req := &RecommendInfraRequest{} if err := c.Bind(req); err != nil { return err } fmt.Print(req) fmt.Print(req.Compute) fmt.Print(req.Network) fmt.Print(req.GPU) res := &RecommendInfraResponse{} // Process // Ouput // if err != nil { // common.CBLog.Error(err) // mapA := map[string]string{"message": err.Error()} // return c.JSON(http.StatusInternalServerError, &mapA) // } return c.JSON(http.StatusOK, res) } ```swag init
I encountered the below message.
Click to see full message
```bash make swag cd pkg/ && make swag make[1]: Entering directory '/mnt/d/dev/cloud-barista/cm-beetle/pkg' ~/go/bin/swag i -g ./api/rest/server/server.go -o ./api/rest/docs 2023/12/10 23:07:05 Generate swagger docs.... 2023/12/10 23:07:05 Generate general API Info, search dir:./ 2023/12/10 23:07:05 warning: failed to get package name in dir: ./, error: execute go list command, exit status 1, stdout:, stderr:no Go files in /mnt/d/dev/cloud-barista/cm-beetle/pkg 2023/12/10 23:07:05 Generating common.ConfigInfo 2023/12/10 23:07:05 Generating common.SimpleMsg 2023/12/10 23:07:05 Generating common.RestGetAllConfigResponse 2023/12/10 23:07:05 Generating common.ConfigReq 2023/12/10 23:07:05 Generating common.JSONResult 2023/12/10 23:07:05 Generating common.RestGetAllNsResponse 2023/12/10 23:07:05 Generating common.NsInfo 2023/12/10 23:07:05 Generating common.IdList 2023/12/10 23:07:05 Generating common.NsReq 2023/12/10 23:07:05 Generating controller.MigrateInfraRequest 2023/12/10 23:07:05 Generating model.TbMcisDynamicReq 2023/12/10 23:07:05 Generating model.TbVmDynamicReq 2023/12/10 23:07:05 Generating controller.MigrateInfraResponse 2023/12/10 23:07:05 Generating model.TbMcisInfo 2023/12/10 23:07:05 Generating model.StatusCountInfo 2023/12/10 23:07:05 Generating model.TbVmInfo 2023/12/10 23:07:05 Generating common.GeoLocation 2023/12/10 23:07:05 Generating model.RegionInfo 2023/12/10 23:07:05 Generating common.ConnConfig 2023/12/10 23:07:05 Generating model.SpiderVMInfo 2023/12/10 23:07:05 Generating common.IID 2023/12/10 23:07:05 Generating common.KeyValue 2023/12/10 23:07:05 Generating controller.MigrateNetworkRequest 2023/12/10 23:07:05 Generating model.DummyNetwork 2023/12/10 23:07:05 Generating model.Network 2023/12/10 23:07:05 Generating model.Subnet 2023/12/10 23:07:05 Generating controller.MigrateNetworkResponse 2023/12/10 23:07:05 Generating controller.MigrateStorageRequest 2023/12/10 23:07:05 Generating model.DummyStorage 2023/12/10 23:07:05 Generating model.Storage 2023/12/10 23:07:05 Generating controller.MigrateStorageResponse 2023/12/10 23:07:05 Generating controller.MigrateInstanceRequest 2023/12/10 23:07:05 Generating model.DummyInstance 2023/12/10 23:07:05 Generating model.Instance 2023/12/10 23:07:05 Generating controller.MigrateInstanceResponse 2023/12/10 23:07:05 Generating controller.RecommendInfraRequest 2023/12/10 23:07:05 Error parsing type definition 'controller.RecommendInfraRequest': : cannot find type definition: infra.Infra 2023/12/10 23:07:05 Skipping 'controller.RecommendInfraRequest', recursion detected. 2023/12/10 23:07:05 Generating controller.RecommendInfraResponse 2023/12/10 23:07:05 Generating controller.Infrastructure 2023/12/10 23:07:05 Generating controller.GetUsersResponse 2023/12/10 23:07:05 Generating model.MyUser 2023/12/10 23:07:05 Generating controller.GetUserResponse 2023/12/10 23:07:05 Generating controller.CreateUserRequest 2023/12/10 23:07:05 Generating controller.UpdateUserRequest 2023/12/10 23:07:05 Generating controller.UpdateUserResponse 2023/12/10 23:07:05 Generating controller.PatchUserRequest 2023/12/10 23:07:05 Generating controller.PatchUserResponse 2023/12/10 23:07:05 create docs.go at api/rest/docs/docs.go 2023/12/10 23:07:05 create swagger.json at api/rest/docs/swagger.json 2023/12/10 23:07:05 create swagger.yaml at api/rest/docs/swagger.yaml make[1]: Leaving directory '/mnt/d/dev/cloud-barista/cm-beetle/pkg' ```