Gin's Fizz OpenAPi generator is renaming types
I created a simple api written in gin. I use fizz to generate the openapi 3 spec. This is my post endpoint:
// 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)) }
This is the handler method:
// Creates new user func CreateUser(c *gin.Context, register *models.Register) error { ... return nil }
The problem is that in the generated json spec, the "register" model is shown as "createuserinput":
Is there any way to solve this problem? Or is this normal?
Correct answer
According to implementation, the schema name is generated by the following statement: name := strings.title(op.id) "input"
(see line 23
below):
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 }
You can use fizz.id to customize the operation id, but there is no way to remove the input
suffix. If you really want to generate schema names differently, you'll need to fork the repository and modify the implementation.
The above is the detailed content of Gin's Fizz OpenAPi generator is renaming types. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



OpenSSL, as an open source library widely used in secure communications, provides encryption algorithms, keys and certificate management functions. However, there are some known security vulnerabilities in its historical version, some of which are extremely harmful. This article will focus on common vulnerabilities and response measures for OpenSSL in Debian systems. DebianOpenSSL known vulnerabilities: OpenSSL has experienced several serious vulnerabilities, such as: Heart Bleeding Vulnerability (CVE-2014-0160): This vulnerability affects OpenSSL 1.0.1 to 1.0.1f and 1.0.2 to 1.0.2 beta versions. An attacker can use this vulnerability to unauthorized read sensitive information on the server, including encryption keys, etc.

The article discusses writing unit tests in Go, covering best practices, mocking techniques, and tools for efficient test management.

The article explains how to use the pprof tool for analyzing Go performance, including enabling profiling, collecting data, and identifying common bottlenecks like CPU and memory issues.Character count: 159

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

This article introduces a variety of methods and tools to monitor PostgreSQL databases under the Debian system, helping you to fully grasp database performance monitoring. 1. Use PostgreSQL to build-in monitoring view PostgreSQL itself provides multiple views for monitoring database activities: pg_stat_activity: displays database activities in real time, including connections, queries, transactions and other information. pg_stat_replication: Monitors replication status, especially suitable for stream replication clusters. pg_stat_database: Provides database statistics, such as database size, transaction commit/rollback times and other key indicators. 2. Use log analysis tool pgBadg

Backend learning path: The exploration journey from front-end to back-end As a back-end beginner who transforms from front-end development, you already have the foundation of nodejs,...

The problem of using RedisStream to implement message queues in Go language is using Go language and Redis...
