我创建了一个用 gin 编写的简单 api。我使用 fizz 生成 openapi 3 规范。这是我的 post 端点:
// sets user route group func userroute(grp *fizz.routergroup) { // create new user grp.post("", []fizz.operationoption{ fizz.summary("creates new user and sends verification mail."), ... }, tonic.handler(handlers.createuser, 201)) }
这是处理程序方法:
// Creates new user func CreateUser(c *gin.Context, register *models.Register) error { ... return nil }
问题在于,在生成的 json 规范中,“register”模型显示为“createuserinput”:
有什么办法可以解决这个问题吗?或者这是正常现象吗?
正确答案
根据实现,模式名称由以下语句生成: name := strings.title(op.id) + "input"
(请参见下面的 23
行):
1 // setOperationParams adds the fields of the struct type t 2 // to the given operation. 3 func (g *Generator) setOperationParams(op *Operation, t, parent reflect.Type, allowBody bool, path string) error { 4 if t.Kind() != reflect.Struct { 5 return errors.New("input type is not a struct") 6 } 7 if err := g.buildParamsRecursive(op, t, parent, allowBody); err != nil { 8 return err 9 } 10 // Input fields that are neither path- nor query-bound 11 // have been extracted into the operation's RequestBody 12 // If the RequestBody is not nil, give it a name and 13 // move it to the openapi spec's components/schemas section 14 // Replace the RequestBody's schema with a reference 15 // to the named schema in components/schemas 16 if op.RequestBody != nil { 17 mt := tonic.MediaType() 18 if mt == "" { 19 mt = anyMediaType 20 } 21 sch := op.RequestBody.Content[mt].Schema 22 if sch != nil { 23 name := strings.Title(op.ID) + "Input" 24 g.api.Components.Schemas[name] = sch 25 op.RequestBody.Content[mt].Schema = &SchemaOrRef{Reference: &Reference{ 26 Ref: componentsSchemaPath + name, 27 }} 28 } 29 }
您可以使用 fizz.id 自定义操作 id,但没有办法去掉input
后缀。如果您确实想以不同的方式生成模式名称,则需要分叉存储库并修改实现。
以上是Gin 的 Fizz OpenAPi 生成器正在重命名类型的详细内容。更多信息请关注PHP中文网其他相关文章!

Golang更适合高并发任务,而Python在灵活性上更有优势。1.Golang通过goroutine和channel高效处理并发。2.Python依赖threading和asyncio,受GIL影响,但提供多种并发方式。选择应基于具体需求。

Golang和C 在性能上的差异主要体现在内存管理、编译优化和运行时效率等方面。1)Golang的垃圾回收机制方便但可能影响性能,2)C 的手动内存管理和编译器优化在递归计算中表现更为高效。

selectgolangforhighpperformanceandcorrency,ifealforBackendServicesSandNetwork程序; selectpypypythonforrapiddevelopment,dataScience和machinelearningDuetoitsverserverserverserversator versator anderticality andextility andextentensivelibraries。

Golang和Python各有优势:Golang适合高性能和并发编程,Python适用于数据科学和Web开发。 Golang以其并发模型和高效性能着称,Python则以简洁语法和丰富库生态系统着称。

Golang和Python分别在哪些方面更易用和学习曲线更平缓?Golang更适合高并发和高性能需求,学习曲线对有C语言背景的开发者较平缓。Python更适合数据科学和快速原型设计,学习曲线对初学者非常平缓。

Golang和C 在性能竞赛中的表现各有优势:1)Golang适合高并发和快速开发,2)C 提供更高性能和细粒度控制。选择应基于项目需求和团队技术栈。

Golang适合快速开发和并发编程,而C 更适合需要极致性能和底层控制的项目。1)Golang的并发模型通过goroutine和channel简化并发编程。2)C 的模板编程提供泛型代码和性能优化。3)Golang的垃圾回收方便但可能影响性能,C 的内存管理复杂但控制精细。

GoimpactsdevelopmentPositationalityThroughSpeed,效率和模拟性。1)速度:gocompilesquicklyandrunseff,ifealforlargeprojects.2)效率:效率:ITScomprehenSevestAndArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdEcceSteral Depentencies,增强开发的简单性:3)SimpleflovelmentIcties:3)简单性。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

Atom编辑器mac版下载
最流行的的开源编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器