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

feat: add swagger annotations for open API router #3885

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
955 changes: 683 additions & 272 deletions api/manager/docs.go

Large diffs are not rendered by default.

955 changes: 683 additions & 272 deletions api/manager/swagger.json

Large diffs are not rendered by default.

558 changes: 416 additions & 142 deletions api/manager/swagger.yaml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import (
// @contact.url https://d7y.io
// @license.name Apache 2.0
// @host localhost:8080
// @BasePath /api/v1
// @BasePath /
// @tag.name api
// @tag.description API router (/api/v1)
// @tag.name oapi
// @tag.description open API router (/oapi/v1)
func main() {
cmd.Execute()
}
10 changes: 5 additions & 5 deletions manager/handlers/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /applications [post]
// @Router /api/v1/applications [post]
func (h *Handlers) CreateApplication(ctx *gin.Context) {
var json types.CreateApplicationRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
Expand All @@ -63,7 +63,7 @@ func (h *Handlers) CreateApplication(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /applications/{id} [delete]
// @Router /api/v1/applications/{id} [delete]
func (h *Handlers) DestroyApplication(ctx *gin.Context) {
var params types.ApplicationParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -90,7 +90,7 @@ func (h *Handlers) DestroyApplication(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /applications/{id} [patch]
// @Router /api/v1/applications/{id} [patch]
func (h *Handlers) UpdateApplication(ctx *gin.Context) {
var params types.ApplicationParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (h *Handlers) UpdateApplication(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /applications/{id} [get]
// @Router /api/v1/applications/{id} [get]
func (h *Handlers) GetApplication(ctx *gin.Context) {
var params types.ApplicationParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -151,7 +151,7 @@ func (h *Handlers) GetApplication(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /applications [get]
// @Router /api/v1/applications [get]
func (h *Handlers) GetApplications(ctx *gin.Context) {
var query types.GetApplicationsQuery
if err := ctx.ShouldBindQuery(&query); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions manager/handlers/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /buckets [post]
// @Router /api/v1/buckets [post]
func (h *Handlers) CreateBucket(ctx *gin.Context) {
var json types.CreateBucketRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
Expand All @@ -65,7 +65,7 @@ func (h *Handlers) CreateBucket(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /buckets/{id} [delete]
// @Router /api/v1/buckets/{id} [delete]
func (h *Handlers) DestroyBucket(ctx *gin.Context) {
var params types.BucketParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -91,7 +91,7 @@ func (h *Handlers) DestroyBucket(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /buckets/{id} [get]
// @Router /api/v1/buckets/{id} [get]
func (h *Handlers) GetBucket(ctx *gin.Context) {
var params types.BucketParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -117,7 +117,7 @@ func (h *Handlers) GetBucket(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /buckets [get]
// @Router /api/v1/buckets [get]
func (h *Handlers) GetBuckets(ctx *gin.Context) {
buckets, err := h.service.GetBuckets(ctx.Request.Context())
if err != nil {
Expand Down
15 changes: 10 additions & 5 deletions manager/handlers/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import (
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /clusters [post]
// @Router /api/v1/clusters [post]
// @Router /oapi/v1/clusters [post]
func (h *Handlers) CreateCluster(ctx *gin.Context) {
var json types.CreateClusterRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
Expand All @@ -63,7 +64,8 @@ func (h *Handlers) CreateCluster(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /clusters/{id} [delete]
// @Router /api/v1/clusters/{id} [delete]
// @Router /oapi/v1/clusters/{id} [delete]
func (h *Handlers) DestroyCluster(ctx *gin.Context) {
var params types.ClusterParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -90,7 +92,8 @@ func (h *Handlers) DestroyCluster(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /clusters/{id} [patch]
// @Router /api/v1/clusters/{id} [patch]
// @Router /oapi/v1/clusters/{id} [patch]
func (h *Handlers) UpdateCluster(ctx *gin.Context) {
var params types.ClusterParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -123,7 +126,8 @@ func (h *Handlers) UpdateCluster(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /clusters/{id} [get]
// @Router /api/v1/clusters/{id} [get]
// @Router /oapi/v1/clusters/{id} [get]
func (h *Handlers) GetCluster(ctx *gin.Context) {
var params types.ClusterParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -151,7 +155,8 @@ func (h *Handlers) GetCluster(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /clusters [get]
// @Router /api/v1/clusters [get]
// @Router /oapi/v1/clusters [get]
func (h *Handlers) GetClusters(ctx *gin.Context) {
var query types.GetClustersQuery
if err := ctx.ShouldBindQuery(&query); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions manager/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /configs [post]
// @Router /api/v1/configs [post]
func (h *Handlers) CreateConfig(ctx *gin.Context) {
var json types.CreateConfigRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
Expand All @@ -63,7 +63,7 @@ func (h *Handlers) CreateConfig(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /configs/{id} [delete]
// @Router /api/v1/configs/{id} [delete]
func (h *Handlers) DestroyConfig(ctx *gin.Context) {
var params types.ConfigParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -90,7 +90,7 @@ func (h *Handlers) DestroyConfig(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /configs/{id} [patch]
// @Router /api/v1/configs/{id} [patch]
func (h *Handlers) UpdateConfig(ctx *gin.Context) {
var params types.ConfigParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (h *Handlers) UpdateConfig(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /configs/{id} [get]
// @Router /api/v1/configs/{id} [get]
func (h *Handlers) GetConfig(ctx *gin.Context) {
var params types.ConfigParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -151,7 +151,7 @@ func (h *Handlers) GetConfig(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /configs [get]
// @Router /api/v1/configs [get]
func (h *Handlers) GetConfigs(ctx *gin.Context) {
var query types.GetConfigsQuery
if err := ctx.ShouldBindQuery(&query); err != nil {
Expand Down
14 changes: 9 additions & 5 deletions manager/handlers/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /jobs [post]
// @Router /oapi/v1/jobs [post]
func (h *Handlers) CreateJob(ctx *gin.Context) {
var json types.CreateJobRequest
if err := ctx.ShouldBindBodyWith(&json, binding.JSON); err != nil {
Expand Down Expand Up @@ -132,7 +132,8 @@ func (h *Handlers) CreateJob(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /jobs/{id} [delete]
// @Router /api/v1/jobs/{id} [delete]
// @Router /oapi/v1/jobs/{id} [delete]
func (h *Handlers) DestroyJob(ctx *gin.Context) {
var params types.JobParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -159,7 +160,8 @@ func (h *Handlers) DestroyJob(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /jobs/{id} [patch]
// @Router /api/v1/jobs/{id} [patch]
// @Router /oapi/v1/jobs/{id} [patch]
func (h *Handlers) UpdateJob(ctx *gin.Context) {
var params types.JobParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -192,7 +194,8 @@ func (h *Handlers) UpdateJob(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /jobs/{id} [get]
// @Router /api/v1/jobs/{id} [get]
// @Router /oapi/v1/jobs/{id} [get]
func (h *Handlers) GetJob(ctx *gin.Context) {
var params types.JobParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -220,7 +223,8 @@ func (h *Handlers) GetJob(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /jobs [get]
// @Router /api/v1/jobs [get]
// @Router /oapi/v1/jobs [get]
func (h *Handlers) GetJobs(ctx *gin.Context) {
var query types.GetJobsQuery
if err := ctx.ShouldBindQuery(&query); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions manager/handlers/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /oauth [post]
// @Router /api/v1/oauth [post]
func (h *Handlers) CreateOauth(ctx *gin.Context) {
var json types.CreateOauthRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
Expand All @@ -63,7 +63,7 @@ func (h *Handlers) CreateOauth(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /oauth/{id} [delete]
// @Router /api/v1/oauth/{id} [delete]
func (h *Handlers) DestroyOauth(ctx *gin.Context) {
var params types.OauthParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -90,7 +90,7 @@ func (h *Handlers) DestroyOauth(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /oauth/{id} [patch]
// @Router /api/v1/oauth/{id} [patch]
func (h *Handlers) UpdateOauth(ctx *gin.Context) {
var params types.OauthParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (h *Handlers) UpdateOauth(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /oauth/{id} [get]
// @Router /api/v1/oauth/{id} [get]
func (h *Handlers) GetOauth(ctx *gin.Context) {
var params types.OauthParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -151,7 +151,7 @@ func (h *Handlers) GetOauth(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /oauth [get]
// @Router /api/v1/oauth [get]
func (h *Handlers) GetOauths(ctx *gin.Context) {
var query types.GetOauthsQuery
if err := ctx.ShouldBindQuery(&query); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions manager/handlers/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /peers [post]
// @Router /api/v1/peers [post]
func (h *Handlers) CreatePeer(ctx *gin.Context) {
var json types.CreatePeerRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
Expand All @@ -63,7 +63,7 @@ func (h *Handlers) CreatePeer(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /peers/{id} [delete]
// @Router /api/v1/peers/{id} [delete]
func (h *Handlers) DestroyPeer(ctx *gin.Context) {
var params types.PeerParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -89,7 +89,7 @@ func (h *Handlers) DestroyPeer(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /peers/{id} [get]
// @Router /api/v1/peers/{id} [get]
func (h *Handlers) GetPeer(ctx *gin.Context) {
var params types.PeerParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -117,7 +117,7 @@ func (h *Handlers) GetPeer(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /peers [get]
// @Router /api/v1/peers [get]
func (h *Handlers) GetPeers(ctx *gin.Context) {
var query types.GetPeersQuery
if err := ctx.ShouldBindQuery(&query); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion manager/handlers/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
// @Success 200 {object} []rbac.Permission
// @Failure 400
// @Failure 500
// @Router /permissions [get]
// @Router /api/v1/permissions [get]
func (h *Handlers) GetPermissions(g *gin.Engine) func(ctx *gin.Context) {
return func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, h.service.GetPermissions(ctx.Request.Context(), g))
Expand Down
10 changes: 5 additions & 5 deletions manager/handlers/personal_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /personal-access-tokens [post]
// @Router /api/v1/personal-access-tokens [post]
func (h *Handlers) CreatePersonalAccessToken(ctx *gin.Context) {
var json types.CreatePersonalAccessTokenRequest
if err := ctx.ShouldBindJSON(&json); err != nil {
Expand All @@ -63,7 +63,7 @@ func (h *Handlers) CreatePersonalAccessToken(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /personal-access-tokens/{id} [delete]
// @Router /api/v1/personal-access-tokens/{id} [delete]
func (h *Handlers) DestroyPersonalAccessToken(ctx *gin.Context) {
var params types.PersonalAccessTokenParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -90,7 +90,7 @@ func (h *Handlers) DestroyPersonalAccessToken(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /personal-access-tokens/{id} [patch]
// @Router /api/v1/personal-access-tokens/{id} [patch]
func (h *Handlers) UpdatePersonalAccessToken(ctx *gin.Context) {
var params types.PersonalAccessTokenParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (h *Handlers) UpdatePersonalAccessToken(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /personal-access-tokens/{id} [get]
// @Router /api/v1/personal-access-tokens/{id} [get]
func (h *Handlers) GetPersonalAccessToken(ctx *gin.Context) {
var params types.PersonalAccessTokenParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand Down Expand Up @@ -151,7 +151,7 @@ func (h *Handlers) GetPersonalAccessToken(ctx *gin.Context) {
// @Failure 400
// @Failure 404
// @Failure 500
// @Router /personal-access-tokens [get]
// @Router /api/v1/personal-access-tokens [get]
func (h *Handlers) GetPersonalAccessTokens(ctx *gin.Context) {
var query types.GetPersonalAccessTokensQuery
if err := ctx.ShouldBindQuery(&query); err != nil {
Expand Down
Loading
Loading