From 3b63d83d036d38541cb8ca203a884eedb6a8a504 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 23 Jun 2015 11:35:21 -0700 Subject: [PATCH] document repository API methods --- cmd/drone-server/drone.go | 1 + doc/swagger.yml | 94 ++++++++++++++++++++++++++++++++++++++- pkg/server/server.go | 9 ++++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/cmd/drone-server/drone.go b/cmd/drone-server/drone.go index a90575db..a8099ff1 100644 --- a/cmd/drone-server/drone.go +++ b/cmd/drone-server/drone.go @@ -78,6 +78,7 @@ func main() { api.Use(server.SetSession(session)) api.Use(server.SetUser(session)) api.Use(server.SetRunner(&runner_)) + api.OPTIONS("/*path", func(c *gin.Context) {}) user := api.Group("/user") { diff --git a/doc/swagger.yml b/doc/swagger.yml index 690108b1..673a618a 100644 --- a/doc/swagger.yml +++ b/doc/swagger.yml @@ -46,6 +46,98 @@ paths: description: The repository. schema: $ref: "#/definitions/Repo" + patch: + parameters: + - name: owner + in: path + type: string + - name: name + in: path + type: string + description: Updates the repository. + security: + - accessToken: [] + responses: + "200": + description: The updated repository. + schema: + $ref: "#/definitions/Repo" + delete: + parameters: + - name: owner + in: path + type: string + - name: name + in: path + type: string + description: Deletes the repository. + security: + - accessToken: [] + /repos/{owner}/{name}/watch: + post: + parameters: + - name: owner + in: path + type: string + - name: name + in: path + type: string + description: Watches the named repository. + security: + - accessToken: [] + + /repos/{owner}/{name}/unwatch: + delete: + parameters: + - name: owner + in: path + type: string + - name: name + in: path + type: string + description: Unwatches the repository. + security: + - accessToken: [] + + /repos/{owner}/{name}/builds: + get: + parameters: + - name: owner + in: path + type: string + - name: name + in: path + type: string + description: Returns recent builds for the repository based on name. + security: + - accessToken: [] + responses: + "200": + description: The recent builds. + schema: + type: array + items: + $ref: "#/definitions/Build" + /repos/{owner}/{name}/builds/{number}: + get: + parameters: + - name: owner + in: path + type: string + - name: name + in: path + type: string + - name: number + in: path + type: integer + description: Returns the repository build by number. + security: + - accessToken: [] + responses: + "200": + description: The build. + schema: + $ref: "#/definitions/Build" /user: get: description: Returns the currently authenticated user. @@ -210,4 +302,4 @@ definitions: type: integer format: int64 environment: - type: object \ No newline at end of file + type: object diff --git a/pkg/server/server.go b/pkg/server/server.go index 3ae4e87b..2f19edf4 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -321,6 +321,15 @@ func SetHeaders() gin.HandlerFunc { c.Writer.Header().Add("Strict-Transport-Security", "max-age=31536000") } + if c.Request.Method == "OPTIONS" { + c.Writer.Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS") + c.Writer.Header().Set("Access-Control-Allow-Headers", "Authorization") + c.Writer.Header().Set("Allow", "HEAD,GET,POST,PUT,PATCH,DELETE,OPTIONS") + c.Writer.Header().Set("Content-Type", "application/json") + c.Writer.WriteHeader(200) + return + } + c.Next() } }