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

Support for gin RouterGroup #17

Open
lukepatrick opened this issue Mar 15, 2018 · 10 comments
Open

Support for gin RouterGroup #17

lukepatrick opened this issue Mar 15, 2018 · 10 comments
Labels

Comments

@lukepatrick
Copy link

lukepatrick commented Mar 15, 2018

Giving swaggo a spin. It appears not to pull annotation information from a RouterGroup.

e.g.

main:

// @Summary Information about Foo APIs
// ...
// ...

func main(){

// ...
router := gin.New()
router.Use(gin.Recovery())

group := router.Group("/v1")
group.Use(gin.Logger(), cors)

p := bar.Project()
group.GET("/foo", p.List)
group.GET("/foo/:id", p.Get)

router.Run(host)

// ...

}

'Project'

//
// @Summary Get List
// @Description get List
// @Produce  json
// @Success 200 "ok"
// @Router /v1/foo/[get]
func (bar Project) List(c *gin.Context) {
	projects, err := bar.GetProjects()
	if err != nil {
		c.JSON(http.StatusNotFound, struct{}{})
		return
	}
	c.JSON(http.StatusOK, projects)
}

do a swag init, get a swagger.yaml

basePath: localhost:8080/
info:
  contact:
    email: support@swagger.io
    name: API Support
    url: http://www.swagger.io/support
  description: GET method
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  termsOfService: http://swagger.io/terms/
  title: Foo APIs
  version: "1.0"
paths: {}
@kgrvamsi
Copy link

@easonlin404 i see the same issue when i'm trying to create a project group for the api's.Do you think you have a quick patch for this to get fixed?

@easonlin404
Copy link
Member

@lukepatrick @kgrvamsi Actually swag only use annotation information to get swagger doc. And where location your 'Project' code ? swag Not supported for cross-package models. Only search in project root folder.

@lukepatrick
Copy link
Author

Not exactly cross-package. A modular app layout. "microservices" perhaps.
something like:
\
\app-api\ - api interface code, where a api/http binary is generated (gin code likely here)
\app-foo\ - other app needs
\pkg\ - core shared code, functions called by api or foo or other packages ('project' example)

@easonlin404
Copy link
Member

@lukepatrick Can you help to create a sample repo to reproduce this issue? I will check it.

@lukepatrick
Copy link
Author

Sure, let me put something together

@lukepatrick
Copy link
Author

actually, here is a link to an opensource project that covers my issue
https://github.com/Azure/brigade
and the api is here:
https://github.com/Azure/brigade/blob/master/brigade-api/cmd/brigade-api/main.go

@pei0804
Copy link
Member

pei0804 commented Mar 27, 2018

I check this issue after swag issue done.

@danikalmar
Copy link

Any updates on this? We use gin groups to version (add a version path parameter) our api, but we can only set one base path atm (we would need two).

@sv-22
Copy link

sv-22 commented Feb 19, 2022

yeah, we also use groups. This is a biggie actually.

@gaozhidf
Copy link

gaozhidf commented Feb 1, 2023

gin-swagger has the example about multiple api endpoints
ref: https://github.com/swaggo/gin-swagger/tree/master/example/multiple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants