OpenAPITools / OpenAPITools/openapi-generator

[REQ] Generate only interfaces for go-gin server

Open
#17,782 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the go-gin-server generator and inspect the Java Spring generator's existing interfaceOnly behavior for comparison. Done means go-gin-server can generate the requested handler interface without the struct implementation, matching the issue's example output.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.