Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It seems that external structs are not recognized when executing swag init. #33

Open
yunkon-kim opened this issue Dec 10, 2023 · 13 comments · Fixed by #34
Open

It seems that external structs are not recognized when executing swag init. #33

yunkon-kim opened this issue Dec 10, 2023 · 13 comments · Fixed by #34
Assignees

Comments

@yunkon-kim
Copy link
Member

yunkon-kim commented Dec 10, 2023

It seems that external structs are not recognized when executing swag init.

What I've done

  1. Get CM-Honeybee's infra package
go get -u github.com/cloud-barista/cm-honeybee/model/infra

go: downloading github.com/cloud-barista/cm-honeybee v0.0.0-20231208055314-9d736a30aa55
go: downloading github.com/libvirt/libvirt-go-xml v7.4.0+incompatible
go: downloading github.com/NeowayLabs/drm v0.0.0-20190824133025-4939fc0ad345
go: downloading github.com/jollaman999/utils v1.0.10
go: downloading golang.org/x/net v0.19.0
go: downloading golang.org/x/tools v0.16.0
go: downloading github.com/google/uuid v1.4.0
go: downloading github.com/labstack/echo/v4 v4.11.3
go: downloading github.com/labstack/gommon v0.4.1
go: downloading github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec
go: downloading golang.org/x/crypto v0.16.0
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading modernc.org/libc v1.37.0
go: downloading modernc.org/mathutil v1.6.0
go: downloading modernc.org/memory v1.7.2
go: downloading modernc.org/sqlite v1.27.0
go: added github.com/NeowayLabs/drm v0.0.0-20190824133025-4939fc0ad345
go: added github.com/cloud-barista/cm-honeybee v0.0.0-20231208055314-9d736a30aa55
go: added github.com/jollaman999/utils v1.0.10
go: upgraded github.com/labstack/echo/v4 v4.11.2 => v4.11.3
go: upgraded github.com/labstack/gommon v0.4.0 => v0.4.1
go: added github.com/libvirt/libvirt-go-xml v7.4.0+incompatible
go: upgraded golang.org/x/crypto v0.14.0 => v0.16.0
go: upgraded golang.org/x/net v0.17.0 => v0.19.0
go: upgraded golang.org/x/tools v0.7.0 => v0.16.0
  1. Import a package
package controller

import (
	"fmt"
	"net/http"

	"github.com/cloud-barista/cm-honeybee/model/infra"
	"github.com/labstack/echo/v4"
)
  1. Embedding Infra struct to RecommendInfraRequest (i.e, request body)
type RecommendInfraRequest struct {
	infra.Infra
}
Click to see full source code
// 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)

}
  1. Execute swag init

I encountered the below message.

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.
Click to see full message
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'
@yunkon-kim yunkon-kim self-assigned this Dec 10, 2023
@yunkon-kim
Copy link
Member Author

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
}

@yunkon-kim yunkon-kim linked a pull request Dec 13, 2023 that will close this issue
@yunkon-kim
Copy link
Member Author

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.

@yunkon-kim
Copy link
Member Author

@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

@yunkon-kim
Copy link
Member Author

yunkon-kim commented Dec 13, 2023

참고 - 이슈가 있는 두 항목을 주석 처리후, swag init시 이슈 없음

type Infra struct {
	Compute Compute `json:"compute"`
	// Network network.Network `json:"network"`
	// GPU GPU `json:"gpu"`
}

참고 - Swagger UI

image

@yunkon-kim
Copy link
Member Author

yunkon-kim commented May 23, 2024

사전 수행사항:

: 온프레미스 모델 동기화 스크립트(get-onprem-models.sh) 사용하여 cm-honeybee의 모델 파일들을 cm-beetle로 동기화

이슈 1

: swag init 시 다음 에러 발생

Error parsing type definition 'controller.RecommendInfraRequest': : cannot find type definition: onpremmodel.Infra

: (원인) 아래와 같이 모델 pkg를 import 및 alias 적용 한 경우 이를 참조하지 못하기 때문
: infraonpremmodel로 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 적용이 불가할 것으로 판단됨

이슈 2

: 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

@ish-hcc
Copy link
Contributor

ish-hcc commented May 24, 2024

해당 커밋에 의해 말씀하신 문제 수정되었습니다. 감사합니다.
cloud-barista/cm-honeybee@0963d03

@powerkimhub
Copy link
Member

powerkimhub commented Jun 9, 2024

@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.

  • `cannot find external type 관련하여,
  • 좀더 복잡한 코드에서도 동일한 해결 방법이 될지는 모르겠지만,
  • 참고해보시기 바랍니다.

[방안]

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 참고
    image


[기타]

  • dependency가 깊다면, 경우에 따라서는 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)
    

@yunkon-kim
Copy link
Member Author

yunkon-kim commented Jun 10, 2024

@powerkimhub

외부 패키지 활용 및 API docs 생성 방안을 공유해주셔서 감사드립니다.

먼저, 소스 컴퓨팅 인프라 형상 정보 메트릭, 소스 모델(온프레미스 모델), 목표 모델(클라우드 모델), API 요청/응답 바디 구조체 등에 실 적용 및 테스트를 진행하고요. 이후에 플랫폼 전체에 확대 적용하는 것으로 추진해보겠습니다. (행사 이후 추진)

공유해주신 아래 내용에 대해 한가지 질문이 있습니다. 기존에 설정되어 있는 GOPATHGOROOT를 특정 디렉토리로 변경해야하는 것으로 보이는데요. 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'

@powerkimhub
Copy link
Member

@yunkon-kim


공유해주신 아래 내용에 대해 한가지 질문이 있습니다. 기존에 설정되어 있는 GOPATHGOROOT를 특정 디렉토리로 변경해야하는 것으로 보이는데요. 10627 디렉토리가 고정되어 있는 디렉토리인지 문의드립니다. 혹시 go get 등으로 패키지를 업데이트 하는 경우에도 동일 디렉토리를 활용해도 괜찮을까요?


  • 특별한 설정은 아니고, 원래 하던 Go path 관련 설정과 동일합니다.
  • 다음 실행시 관련 오류 메시지 없다면, 별도 설정은 필요 없습니다.
    swag init --parseDependency
    
  • 만약 관련 오류 메시지가 발생한다면,
    • swag 실행 환경에 설치된 Go의 GOPATHGOROOT를 설정하시면 되겠습니다.
    • 공유 예시는 Go를 snap으로 설치한 제 실행 환경에서의 단순 설정 예시이며,
    • 원래 사용하시던 GOPATHGOROOT 설정 방법을 사용하시면 되겠습니다.

@yunkon-kim
Copy link
Member Author

@powerkimhub

네 알겠습니다. 설명 감사드립니다.

@yunkon-kim
Copy link
Member Author

yunkon-kim commented Jul 18, 2024

@powerkimhub @seokho-son

CM-Beetle에서 아래 둘을 import 하는 방식으로 테스트를 진행해 봤습니다.

  • CM-Honeybee의 소스 컴퓨팅 인프라 형상 정보 메트릭 관련 pkg 및 structs
  • CB-Tumblebug의 멀티 클라우드 인프라 관련 pkg 및 structs

결론부터 공유드립니다.

  • main.go 상단에 'Swagger general API info' 기재
  • main.go를 프로젝트 Root에 위치 시킴 (아마도, go.mod와 같이 있어야하는 것으로 추측됨)
  • 각 API 요청, 응답을 정확하게 정의해 놓아야할 것으로 판단됨
  • 별도로, pkg import시 CM-Honeybee 및 CB-Tumblebug에서 관리하는 패키지간 영향을 받음
    • 예) 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 상에서 외부 패키지는 일반적으로 출력됙, 내부 패키지가 곤란하게 출력됨
image
image

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 상에서도 개선됨
image
image

: github_com_cloud-barista_cm-beetle_pkg_core_common.SimpleMsg 해소 관련

  • 여러가지 시도해 보았으나 재 정의하는 방법에 대해서만 성공함
  • 외부 패키지와 동일한 구조체가 있이 때문에 (충돌?) 명시하려는 의도로 보임

: 참고 - 재정의/명시

type SimpleMessage struct {
	common.SimpleMsg
}

: 결과 - SimpleMessage 사용
image

: 결과 - common.SimpleMsg 사용
image

@yunkon-kim
Copy link
Member Author

@innodreamer CM-Damselfly 측면에서 한번 살펴봐 주시면 좋을 것 같습니다.

@yunkon-kim
Copy link
Member Author

최근 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants