wI2L / fizz

:lemon: Gin wrapper with OpenAPI 3 spec generation
https://pkg.go.dev/github.com/wI2L/fizz
MIT License
214 stars 52 forks source link

Endpoints with colon(:) #41

Closed hmajid2301 closed 4 years ago

hmajid2301 commented 4 years ago

Hi, is it possible to use endpoints that have a : in the path?

Such as:

If I try:

grp.PUT("/:name:enabled", []fizz.OperationOption{
....
}, tonic.Handler(controllers.DisableGameType, http.StatusOK))

I get the following error

panic: error while generating OpenAPI spec on operation PUT /:name:disable: semantic error for path /game/{name:disable}: declared path parameter name:disable needs to be defined at operation level

Thanks

wI2L commented 4 years ago

Path parameters are handled by the underlying router, Gin. It doesn't seems that you can use the semicolon without encountering issues.

See this issue: https://github.com/gin-gonic/gin/issues/1432

Anyway, you should not use such URLs. Try something explicit like /game/:name/enable, and you'll be fine.

hmajid2301 commented 4 years ago

Yeh I thought I remember reading the colon approach was preferred for actions in some rest guide. But you are correct /enable hardly makes a difference thanks.

https://cloud.google.com/apis/design/custom_methods