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

net/goai: issue The openAPI document api.json generated by gf has a problem with the properties={} parameter setting in each field. #3660

Closed
qinains opened this issue Jun 22, 2024 · 3 comments · Fixed by #3662
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@qinains
Copy link

qinains commented Jun 22, 2024

Go version

go version go1.22.0 windows/amd64

GoFrame version

2.7.1

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

  1. 修改openAPI的UI
    编辑:internal\cmd\cmd.go
const MySwaggerUITemplate = `
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>test</title>
  </head>
  <body>
    <div id="openapi-ui-container" spec-url="{SwaggerUIDocUrl}" theme="light"></div>
    <script src="https://cdn.jsdelivr.net/npm/openapi-ui-dist@latest/lib/openapi-ui.umd.js"></script>
  </body>
</html>
`
s.SetSwaggerUITemplate(MySwaggerUITemplate)

// 启动Http Server
s.Run()
  1. api文件如下:
    api/v1/file.go
package v1

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
)

type FileUploadReq struct {
	g.Meta `path:"/file" method:"post" mime:"multipart/form-data" tags:"工具" summary:"上传文件"`
	File   *ghttp.UploadFile `json:"file" type:"file" dc:"选择上传文件"`
}
type FileUploadRes struct {
	Name string `json:"name" dc:"文件名称"`
	Url  string `json:"url"  dc:"访问URL,可能只是URI"`
}
  1. 启动server:gf run main.go

What did you see happen?

生成的api.json文件的FileUploadReq部分为

"focus-single.api.v1.FileUploadReq": {
    "properties": {
        "file": {
            "description": "选择上传文件",
            "format": "*ghttp.UploadFile",
            "properties": {},
            "type": "file"
        }
    },
    "type": "object"
},

文件上传组件显示不正常:
微信截图_20240622163427

What did you expect to see?

生成的api.json文件的FileUploadReq部分应该为

"focus-single.api.v1.FileUploadReq": {
    "properties": {
        "file": {
            "description": "选择上传文件",
            "format": "*ghttp.UploadFile",
            "type": "file"
        }
    },
    "type": "object"
},

需要把“"properties": {},”去除。去除之后,才能在这个UI(<script src="https://cdn.jsdelivr.net/npm/openapi-ui-dist@latest/lib/openapi-ui.umd.js"></script>)中显示才正常。其他类型也是,需要在xxxReq中把生成的空的“"properties": {},”去除。

微信截图_20240622163346

@qinains qinains added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jun 22, 2024
@Issues-translate-bot Issues-translate-bot changed the title net/goai: issue gf生成的openAPI文档api.json,每个字段都有properties={}参数设置有问题 net/goai: issue The openAPI document api.json generated by gf has a problem with the properties={} parameter setting in each field. Jun 22, 2024
hailaz added a commit that referenced this issue Jun 25, 2024
@hailaz
Copy link
Member

hailaz commented Jun 25, 2024

试试
go get -v github.com/gogf/gf/v2@2422c82

#3662

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


try
go get -v github.com/gogf/gf/v2@2422c82

#3662

@gqcn gqcn closed this as completed in e8a2629 Jun 25, 2024
@qinains
Copy link
Author

qinains commented Jun 25, 2024

Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants