swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.79k stars 1.21k forks source link

Unable to generate API in linux #1597

Open dreamlu opened 1 year ago

dreamlu commented 1 year ago

Describe the bug Unable to generate API in linux, swagger.json and swagger.yaml api is empty

To Reproduce Steps to reproduce the behavior:

  1. go install github.com/swaggo/swag/cmd/swag@v1.16.1
  2. swag init or
  3. go install github.com/swaggo/swag/cmd/swag@v1.8.12
  4. swag init

Expected behavior generate api in docs/swagger.json

Screenshots image

image

Your swag version v1.16.1

Your go version go 1.20.4

Desktop (please complete the following information):

Additional context v1.7.0 is right image

jamshidi799 commented 1 year ago

hi @dreamlu can you provide your API swagger spec(swagger comments)? I think the problem is you use interface type in your spec.

dreamlu commented 1 year ago

I use this project, master branch: https://github.com/flipped-aurora/gin-vue-admin cd server go mod tidy

` go install github.com/swaggo/swag/cmd/swag@v1.16.1
swag init
or

go install github.com/swaggo/swag/cmd/swag@v1.8.12
swag init
` then, I met this bug in linux, I ask that project issue, they use mac and windows is right

corpix commented 1 year ago

Ok, @dreamlu but, as @jamshidi799 suggests, can you provide your API swagger spec(swagger comments)?

I have the same problem (paths is empty) while generating swagger spec for BFF kind of service. In this service repository root I have a bunch of directories like this:

./
./datauploader/handlers.go
./service1/handlers.go
./service2/handlers.go
...

Where each handlers.go structured like this:

package datauploader

import (
        "net/http"

        // ...
)

type Handlers struct {
        // ...
}

// CreateSignalsUploadsJson mlem mlem mlem
// @Router      /signals/uploads/json [post]
// @Description uploads file with points for current user
// @Tags        data-uploader
// @Accept      multipart/form-data
// @Produce     json
// @Success     202     {object} resputils.StdResp{result=*SignalsUploadWithJsonFormatResponse}
// @Failure     default {object} resputils.ErrResp
// @Security    Auth
func (h *Handlers) CreateSignalsUploadsJson(w http.ResponseWriter, r *http.Request) {
  // ...
}

swag init --parseDependency --parseInternal --parseDepth 4 -o . -ot yaml gives me swagger.yaml with paths: {} for no obvious reason. While swag fmt is working for swag comments.

corpix commented 1 year ago

I have resolved my issue. Looks like swag can't find Go executable, because this https://github.com/corpix/nixpkgs/commit/c0840ea4912ea1d691189c874e537c09f15f1441 fixed the issue (also swag compiled from repository works fine)

dreamlu commented 1 year ago

I use this project, master branch: https://github.com/flipped-aurora/gin-vue-admin cd server go mod tidy

` go install github.com/swaggo/swag/cmd/swag@v1.16.1 swag init or

go install github.com/swaggo/swag/cmd/swag@v1.8.12 swag init ` then, I met this bug in linux, I ask that project issue, they use mac and windows is right

comment: // CreateApi // // @Tags SysApi // @Summary 创建基础api // @Security ApiKeyAuth // @accept application/json // @Produce application/json // @Param data body system.SysApi true "api路径, api中文描述, api组, 方法" // @Success 200 {object} response.Response{msg=string} "创建基础api" // @Router /api/createApi [post] func (s SystemApiApi) CreateApi(c gin.Context) {

main: // @title Swagger Example API // @version 0.0.1 // @description This is a sample Server pets // @securityDefinitions.apikey ApiKeyAuth // @in header // @name x-token // @BasePath / func main() {

but use version swag v1.7.0 is ok related bug:https://github.com/flipped-aurora/gin-vue-admin/issues/1445 maybe this is swag bug os: debain golang: 1.20 swag: v1.7.0 is ok, v1.16.1 and v1.8.12 is has this bug