Skip to content

[REQ] Generate only interfaces for go-gin server #17782

Open
@mfatihercik

Description

@mfatihercik

Is your feature request related to a problem? Please describe.

In the current implementation of go-gin-server, it always creates a struct and adds API operation as a method to the struct. It is not possible to override struct methods.

Current Implementation

type PetAPI struct {
}

// Post /v2/pet
// Add a new pet to the store 
func (api *PetAPI) AddPet(c *gin.Context) {
	// Your handler implementation
	c.JSON(200, gin.H{"status": "OK"})
}

// Delete /v2/pet/:petId
// Deletes a pet 
func (api *PetAPI) DeletePet(c *gin.Context) {
	// Your handler implementation
	c.JSON(200, gin.H{"status": "OK"})
}

// Get /v2/pet/findByStatus
// Finds Pets by status 
func (api *PetAPI) FindPetsByStatus(c *gin.Context) {
	// Your handler implementation
	c.JSON(200, gin.H{"status": "OK"})
}

// Get /v2/pet/findByTags
// Finds Pets by tags 
// Deprecated
func (api *PetAPI) FindPetsByTags(c *gin.Context) {
	// Your handler implementation
	c.JSON(200, gin.H{"status": "OK"})
}

// Get /v2/pet/:petId
// Find pet by ID 
func (api *PetAPI) GetPetById(c *gin.Context) {
	// Your handler implementation
	c.JSON(200, gin.H{"status": "OK"})
}

// Put /v2/pet
// Update an existing pet 
func (api *PetAPI) UpdatePet(c *gin.Context) {
	// Your handler implementation
	c.JSON(200, gin.H{"status": "OK"})
}

// Post /v2/pet/:petId
// Updates a pet in the store with form data 
func (api *PetAPI) UpdatePetWithForm(c *gin.Context) {
	// Your handler implementation
	c.JSON(200, gin.H{"status": "OK"})
}

// Post /v2/pet/:petId/uploadImage
// uploads an image 
func (api *PetAPI) UploadFile(c *gin.Context) {
	// Your handler implementation
	c.JSON(200, gin.H{"status": "OK"})
}

Describe the solution you'd like

If we create an interface type instead of a struct, we can implement an interface method. This allows us to be more flexible regarding implementation place.

The same functionality exists in the Java Spring generator. If interfaceOnly is true, then it generate only interfaces instead of implementation.

New Version:

type PetAPI interface {


    // AddPet Post /v2/pet
    // Add a new pet to the store 
     AddPet(c *gin.Context)

    // DeletePet Delete /v2/pet/:petId
    // Deletes a pet 
     DeletePet(c *gin.Context)

    // FindPetsByStatus Get /v2/pet/findByStatus
    // Finds Pets by status 
     FindPetsByStatus(c *gin.Context)

    // FindPetsByTags Get /v2/pet/findByTags
    // Finds Pets by tags 
    // Deprecated
     FindPetsByTags(c *gin.Context)

    // GetPetById Get /v2/pet/:petId
    // Find pet by ID 
     GetPetById(c *gin.Context)

    // UpdatePet Put /v2/pet
    // Update an existing pet 
     UpdatePet(c *gin.Context)

    // UpdatePetWithForm Post /v2/pet/:petId
    // Updates a pet in the store with form data 
     UpdatePetWithForm(c *gin.Context)

    // UploadFile Post /v2/pet/:petId/uploadImage
    // uploads an image 
     UploadFile(c *gin.Context)

}

Describe alternatives you've considered

Additional context

The same functionality exists in many other generators

List Of generator have the feature(7):

If interfaceOnly is true, then it generate only interfaces instead of implementation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions