From 39596fd0e7231eb53cdac2eee722213877431301 Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Sat, 4 Aug 2018 18:02:45 +0500 Subject: [PATCH 01/15] Add example of swagger annotations --- api.go | 87 +++++++++++++++++++++++++++++++++++++++ apidef/api_definitions.go | 2 + 2 files changed, 89 insertions(+) diff --git a/api.go b/api.go index 1b1fa3e6b48e..a375d8fb3e48 100644 --- a/api.go +++ b/api.go @@ -1,3 +1,27 @@ +// Tyk Gateway API +// +// Code below describes Tyk Gateway API +// +// Schemes: http, https +// Host: localhost +// BasePath: /tyk/ +// +// Consumes: +// - application/json +// +// Produces: +// - application/json +// +// Security: +// - api_key: +// +// SecurityDefinitions: +// api_key: +// type: apiKey +// name: X-Tyk-Authorization +// in: header +// +// swagger:meta package main import ( @@ -27,6 +51,8 @@ import ( ) // apiModifyKeySuccess represents when a Key modification was successful +// +// swagger:response type apiModifyKeySuccess struct { Key string `json:"key"` Status string `json:"status"` @@ -35,8 +61,12 @@ type apiModifyKeySuccess struct { } // apiStatusMessage represents an API status message +// +// swagger:response type apiStatusMessage struct { + // Status can be either `ok` or `error` Status string `json:"status"` + // Response details Message string `json:"message"` } @@ -687,6 +717,50 @@ func handleDeleteAPI(apiID string) (interface{}, int) { return response, http.StatusOK } +// swagger:route GET /apis apis listApis +// +// List APIs +// Only if used without dashboard +//--- +// responses: +// 200: +// description: List of API definitions +// schema: +// type: array +// items: +// "$ref": "#/definitions/APIDefinition" + +// swagger:route POST /apis apis createApi +// +// Create API +// +// responses: +// '200': +// description: API created +// schema: +// "$ref": "#/responses/apiModifyKeySuccess" +// examples: +// status: "ok" +// action: "created" +// key: "{...API JSON definition...}" +// '400': +// description: Malformed data +// schema: +// "$ref": "#/responses/apiStatusMessage" +// examples: +// status: "error" +// message: "Malformed API data" + +// swagger:route GET /apis/{apiID} apis getApi +// +// Get API +// Only if used without dashboard +// +// Responses: +// 200: +// description: API definition +// schema: +// $ref: "#/definitions/APIDefinition" func apiHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] @@ -1036,6 +1110,12 @@ func handleDeleteOrgKey(orgID string) (interface{}, int) { return statusObj, http.StatusOK } +// swagger:route GET /reload/group reloadGroup +// +// Reload all gateways in cluser +// +// Responses: +// 200: apiStatusMessage func groupResetHandler(w http.ResponseWriter, r *http.Request) { log.WithFields(logrus.Fields{ "prefix": "api", @@ -1056,6 +1136,13 @@ func groupResetHandler(w http.ResponseWriter, r *http.Request) { // was in the URL parameters, it will block until the reload is done. // Otherwise, it won't block and fn will be called once the reload is // finished. +// +// swagger:route GET /reload reload +// +// Reload single gateway instance +// +// Responses: +// 200: apiStatusMessage func resetHandler(fn func()) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var wg sync.WaitGroup diff --git a/apidef/api_definitions.go b/apidef/api_definitions.go index 23715cd4b989..1035727e3e3f 100644 --- a/apidef/api_definitions.go +++ b/apidef/api_definitions.go @@ -323,6 +323,8 @@ type OpenIDOptions struct { } // APIDefinition represents the configuration for a single proxied API and it's versions. +// +// swagger:model type APIDefinition struct { Id bson.ObjectId `bson:"_id,omitempty" json:"id,omitempty"` Name string `bson:"name" json:"name"` From 62a9670a0a1ccdccfe91f6c991ff1a7ce83ec3c0 Mon Sep 17 00:00:00 2001 From: marksou Date: Tue, 28 Aug 2018 12:48:10 +0100 Subject: [PATCH 02/15] Added deleteApi section and also added gateway version --- api.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api.go b/api.go index a375d8fb3e48..673deb2f3f08 100644 --- a/api.go +++ b/api.go @@ -1,6 +1,7 @@ // Tyk Gateway API // // Code below describes Tyk Gateway API +// version: 1.7.0 // // Schemes: http, https // Host: localhost @@ -761,6 +762,27 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // description: API definition // schema: // $ref: "#/definitions/APIDefinition" + +// swagger:route DELETE /apis/{apiID} apis deleteApi +// +// Delete API +// Only if used without dashboard +// +// Responses: +// '200': +// description: API deleted +// schema: +// $ref: "#/responses/apiStatusMessage" +// examples: +// status: "ok" +// message: "API deleted" +// '400': +// description: No API ID specified +// schema: +// $ref: "#/responses/apiStatusMessage" +// examples: +// status: "error" +// message: "API ID not specified" func apiHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] From 25c1d5242fc5a709f4ca038390c9e68dfbc7230d Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Tue, 28 Aug 2018 19:11:50 +0300 Subject: [PATCH 03/15] Fix goswagger annotations to work with examples --- api.go | 154 +++++++++++++++++++++++++++++++++++------------- user/session.go | 1 + 2 files changed, 113 insertions(+), 42 deletions(-) diff --git a/api.go b/api.go index 673deb2f3f08..f6b0a61ca797 100644 --- a/api.go +++ b/api.go @@ -66,7 +66,7 @@ type apiModifyKeySuccess struct { // swagger:response type apiStatusMessage struct { // Status can be either `ok` or `error` - Status string `json:"status"` + Status string `json:"status"` // Response details Message string `json:"message"` } @@ -718,10 +718,11 @@ func handleDeleteAPI(apiID string) (interface{}, int) { return response, http.StatusOK } -// swagger:route GET /apis apis listApis +// swagger:operation GET /apis apis listApis // // List APIs // Only if used without dashboard +// //--- // responses: // 200: @@ -731,58 +732,61 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // items: // "$ref": "#/definitions/APIDefinition" -// swagger:route POST /apis apis createApi +// swagger:operation POST /apis apis createApi // // Create API // -// responses: -// '200': -// description: API created -// schema: -// "$ref": "#/responses/apiModifyKeySuccess" -// examples: -// status: "ok" -// action: "created" -// key: "{...API JSON definition...}" -// '400': -// description: Malformed data -// schema: -// "$ref": "#/responses/apiStatusMessage" -// examples: -// status: "error" -// message: "Malformed API data" - -// swagger:route GET /apis/{apiID} apis getApi +//--- +// responses: +// 200: +// description: API created +// schema: +// "$ref": "#/responses/apiModifyKeySuccess" +// examples: +// status: "ok" +// action: "created" +// key: "{...API JSON definition...}" +// 400: +// description: Malformed data +// schema: +// "$ref": "#/responses/apiStatusMessage" +// examples: +// status: "error" +// message: "Malformed API data" + +// swagger:operation GET /apis/{apiID} apis getApi // // Get API // Only if used without dashboard // -// Responses: -// 200: -// description: API definition -// schema: -// $ref: "#/definitions/APIDefinition" +//--- +// responses: +// 200: +// description: API definition +// schema: +// $ref: "#/definitions/APIDefinition" -// swagger:route DELETE /apis/{apiID} apis deleteApi +// swagger:operation DELETE /apis/{apiID} apis deleteApi // // Delete API // Only if used without dashboard // -// Responses: -// '200': -// description: API deleted -// schema: -// $ref: "#/responses/apiStatusMessage" -// examples: -// status: "ok" -// message: "API deleted" -// '400': -// description: No API ID specified -// schema: -// $ref: "#/responses/apiStatusMessage" -// examples: -// status: "error" -// message: "API ID not specified" +//--- +// responses: +// 200: +// description: API deleted +// schema: +// $ref: "#/responses/apiStatusMessage" +// examples: +// status: "ok" +// message: "API deleted" +// 400: +// description: No API ID specified +// schema: +// $ref: "#/responses/apiStatusMessage" +// examples: +// status: "error" +// message: "API ID not specified" func apiHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] @@ -820,6 +824,72 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { doJSONWrite(w, code, obj) } +// swagger:operation GET /keys keys listKeys +// +// List Keys +// +//--- +// responses: +// 200: +// description: List of API keys +// schema: +// type: array +// items: +// type: string + +// swagger:operation POST /keys keys createKey +// +// Create Key +// +//--- +// responses: +// 200: +// description: Key created +// schema: +// "$ref": "#/responses/apiModifyKeySuccess" +// examples: +// status: "ok" +// action: "created" +// key: "{...KEY JSON definition...}" +// 400: +// description: Malformed data +// schema: +// "$ref": "#/responses/apiStatusMessage" +// examples: +// status: "error" +// message: "Malformed Key data" + +// swagger:operation GET /keys/{keyID} keys getKey +// +// Get Key +// +//--- +// responses: +// 200: +// description: Key object +// schema: +// $ref: "#/definitions/SessionState" + +// swagger:operation DELETE /keys/{keyID} keys deleteKey +// +// Delete Key +// +//--- +// responses: +// 200: +// description: Key deleted +// schema: +// $ref: "#/responses/apiStatusMessage" +// examples: +// status: "ok" +// message: "Key deleted" +// 400: +// description: No Key ID specified +// schema: +// $ref: "#/responses/apiStatusMessage" +// examples: +// status: "error" +// message: "Key ID not specified" func keyHandler(w http.ResponseWriter, r *http.Request) { keyName := mux.Vars(r)["keyName"] apiID := r.URL.Query().Get("api_id") diff --git a/user/session.go b/user/session.go index 6ce9115f89b9..4739ee2291c3 100644 --- a/user/session.go +++ b/user/session.go @@ -44,6 +44,7 @@ type AccessDefinition struct { // SessionState objects represent a current API session, mainly used for rate limiting. // There's a data structure that's based on this and it's used for Protocol Buffer support, make sure to update "coprocess/proto/coprocess_session_state.proto" and generate the bindings using: cd coprocess/proto && ./update_bindings.sh +// swagger:model type SessionState struct { LastCheck int64 `json:"last_check" msg:"last_check"` Allowance float64 `json:"allowance" msg:"allowance"` From 4191d0a6e67daa97c18dfa539d8e378aea8f43c3 Mon Sep 17 00:00:00 2001 From: marksou Date: Thu, 30 Aug 2018 12:35:32 +0100 Subject: [PATCH 04/15] Update API, Keys and Reload Swagger sections --- api.go | 122 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 100 insertions(+), 22 deletions(-) diff --git a/api.go b/api.go index f6b0a61ca797..99a90054a8e2 100644 --- a/api.go +++ b/api.go @@ -1,7 +1,7 @@ // Tyk Gateway API // -// Code below describes Tyk Gateway API -// version: 1.7.0 +// The code below describes the Tyk Gateway API +// Version: 1.7.0 // // Schemes: http, https // Host: localhost @@ -718,10 +718,10 @@ func handleDeleteAPI(apiID string) (interface{}, int) { return response, http.StatusOK } -// swagger:operation GET /apis apis listApis +// swagger:operation GET /apis APIs listApis // // List APIs -// Only if used without dashboard +// Only if used without the Tyk Dashboard // //--- // responses: @@ -732,7 +732,7 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // items: // "$ref": "#/definitions/APIDefinition" -// swagger:operation POST /apis apis createApi +// swagger:operation POST /apis APIs createApi // // Create API // @@ -754,24 +754,38 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // status: "error" // message: "Malformed API data" -// swagger:operation GET /apis/{apiID} apis getApi +// swagger:operation GET /apis/{apiID} APIs getApi // // Get API -// Only if used without dashboard +// Only if used without the Tyk Dashboard // //--- +// parameters: +// - in: path +// name: apiID +// required: true +// type: integer +// minimum: 1 +// description: The API ID // responses: // 200: // description: API definition // schema: // $ref: "#/definitions/APIDefinition" -// swagger:operation DELETE /apis/{apiID} apis deleteApi +// swagger:operation DELETE /apis/{apiID} APIs deleteApi // // Delete API -// Only if used without dashboard +// Only if used without the Tyk Dashboard // //--- +// parameters: +// - in: path +// name: apiID +// required: true +// type: integer +// minimum: 1 +// description: The API ID // responses: // 200: // description: API deleted @@ -824,27 +838,27 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { doJSONWrite(w, code, obj) } -// swagger:operation GET /keys keys listKeys +// swagger:operation GET /keys Keys listKeys // -// List Keys +// List All Keys // //--- // responses: // 200: -// description: List of API keys +// description: List of all API keys // schema: // type: array // items: // type: string -// swagger:operation POST /keys keys createKey +// swagger:operation POST /keys Keys createKey // -// Create Key +// Create a new Key // //--- // responses: // 200: -// description: Key created +// description: New Key created // schema: // "$ref": "#/responses/apiModifyKeySuccess" // examples: @@ -859,22 +873,86 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // status: "error" // message: "Malformed Key data" -// swagger:operation GET /keys/{keyID} keys getKey +// swagger:operation POST /keys Keys addKey // -// Get Key +// Add an existing Key // //--- // responses: // 200: +// description: New Key added +// schema: +// "$ref": "#/responses/apiModifyKeySuccess" +// examples: +// status: "ok" +// action: "created" +// key: "{...KEY JSON definition...}" +// 400: +// description: Malformed data +// schema: +// "$ref": "#/responses/apiStatusMessage" +// examples: +// status: "error" +// message: "Malformed Key data" + +// swagger:operation PUT /keys/{keyID} Keys updateKey +// +// Update a Key +// +//--- +// parameters: +// - in: path +// name: keyID +// required: true +// type: integer +// minimum: 1 +// description: The Key ID +// responses: +// 200: +// description: Key updated +// schema: +// "$ref": "#/responses/apiModifyKeySuccess" +// examples: +// status: "ok" +// action: "updated" +// 400: +// description: No or incorrect Key ID specified +// schema: +// "$ref": "#/responses/apiStatusMessage" +// examples: +// status: "error" +// message: "Key ID not specified" + +// swagger:operation GET /keys/{keyID} Keys getKey +// +// Get a Key +// +//--- +// parameters: +// - in: path +// name: keyID +// required: true +// type: integer +// minimum: 1 +// description: The Key ID +// responses: +// 200: // description: Key object // schema: // $ref: "#/definitions/SessionState" -// swagger:operation DELETE /keys/{keyID} keys deleteKey +// swagger:operation DELETE /keys/{keyID} Keys deleteKey // // Delete Key // //--- +// parameters: +// - in: path +// name: keyID +// required: true +// type: integer +// minimum: 1 +// description: The Key ID // responses: // 200: // description: Key deleted @@ -1202,9 +1280,9 @@ func handleDeleteOrgKey(orgID string) (interface{}, int) { return statusObj, http.StatusOK } -// swagger:route GET /reload/group reloadGroup +// swagger:route GET /reload/group Reload reloadGroup // -// Reload all gateways in cluser +// Reloads all the Tyk Gateways in a cluster // // Responses: // 200: apiStatusMessage @@ -1229,9 +1307,9 @@ func groupResetHandler(w http.ResponseWriter, r *http.Request) { // Otherwise, it won't block and fn will be called once the reload is // finished. // -// swagger:route GET /reload reload +// swagger:route GET /reload Reload reload // -// Reload single gateway instance +// Reloads a single Tyk Gateway instance // // Responses: // 200: apiStatusMessage From 52662e10f6b3d382bef74cfe59d99e328594184a Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Thu, 6 Sep 2018 22:11:08 +0300 Subject: [PATCH 05/15] Add swagger docs for oAuth and cache invalidation --- api.go | 165 +++++++++++++++++++++++++++++++++++++++++++++++ oauth_manager.go | 2 + 2 files changed, 167 insertions(+) diff --git a/api.go b/api.go index 99a90054a8e2..53d006e39401 100644 --- a/api.go +++ b/api.go @@ -1467,6 +1467,8 @@ func createKeyHandler(w http.ResponseWriter, r *http.Request) { } // NewClientRequest is an outward facing JSON object translated from osin OAuthClients +// +// swagger:model type NewClientRequest struct { ClientID string `json:"client_id"` ClientRedirectURI string `json:"redirect_uri"` @@ -1481,6 +1483,25 @@ func oauthClientStorageID(clientID string) string { return prefixClient + clientID } +// swagger:operation POST /oauth/clients/create oauth createOAuthClient +// +// Create oAuth client +// +//--- +// requestBody: +// content: +// application/json: +// schema: +// "$ref": "#/definitions/NewClientRequest" +// examples: +// client_id: test +// api_id: id +// policy_id: policy +// responses: +// 200: +// description: Client created +// schema: +// "$ref": "#/responses/OAuthClient" func createOauthClient(w http.ResponseWriter, r *http.Request) { var newOauthClient NewClientRequest if err := json.NewDecoder(r.Body).Decode(&newOauthClient); err != nil { @@ -1695,6 +1716,38 @@ func updateOauthClient(keyName, apiID string, r *http.Request) (interface{}, int return replyData, http.StatusOK } +// swagger:operation DELETE /oauth/refresh/{keyName} oauth invalidateOAuthRefresh +// +// Invalidate oAuth refresh token +// +//--- +// parameters: +// - in: query +// name: api_id +// required: true +// schema: +// type: string +// description: API id +// - in: path +// name: keyName +// required: true +// schema: +// type: string +// description: Refresh token +// requestBody: +// content: +// application/json: +// schema: +// "$ref": "#/definitions/NewClientRequest" +// examples: +// client_id: test +// api_id: id +// policy_id: policy +// responses: +// 200: +// description: Deleted +// schema: +// "$ref": "#/responses/apiModifyKeySuccess" func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { apiID := r.URL.Query().Get("api_id") if apiID == "" { @@ -1762,6 +1815,76 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { doJSONWrite(w, http.StatusOK, success) } +// swagger:operation GET /oauth/clients/{apiID} oauth listOAuthClients +// +// List oAuth client +// +//--- +// parameters: +// - in: path +// name: apiID +// required: true +// schema: +// type: string +// description: API ID +// responses: +// 200: +// description: Get client details or list of clients +// schema: +// type: array +// items: +// "$ref": "#/responses/NewClientRequest" + +// swagger:operation GET /oauth/clients/{apiID}/{keyName} oauth getOAuthClient +// +// Get oAuth client +// +//--- +// parameters: +// - in: path +// name: apiID +// required: true +// schema: +// type: string +// description: API ID +// - in: path +// name: keyName +// required: true +// schema: +// type: string +// description: Client ID +// responses: +// 200: +// description: Get client details or list of clients +// schema: +// "$ref": "#/responses/NewClientRequest" + +// swagger:operation DELETE /oauth/clients/{apiID}/{keyName} oauth deleteOAuthClient +// +// Delete oAuth client +// +//--- +// parameters: +// - in: path +// name: apiID +// required: true +// schema: +// type: string +// description: API ID +// - in: path +// name: keyName +// required: true +// schema: +// type: string +// description: Client ID +// responses: +// 200: +// description: oAuth client deleted +// schema: +// "$ref": "#/responses/apiModifyKeySuccess" +// examples: +// status: "ok" +// action: "deleted" func oAuthClientHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] keyName := mux.Vars(r)["keyName"] @@ -1788,6 +1911,31 @@ func oAuthClientHandler(w http.ResponseWriter, r *http.Request) { doJSONWrite(w, code, obj) } +// swagger:operation GET /oauth/clients/{apiID}/{keyName}/tokens oauth getOAuthClientTokens +// +// Get oAuth client tokens +// +//--- +// parameters: +// - in: path +// name: apiID +// required: true +// schema: +// type: string +// description: API ID +// - in: path +// name: keyName +// required: true +// schema: +// type: string +// description: Client ID +// responses: +// 200: +// description: Get list of tokens +// schema: +// type: array +// items: +// type: string func oAuthClientTokensHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] keyName := mux.Vars(r)["keyName"] @@ -1990,6 +2138,23 @@ func userRatesCheck(w http.ResponseWriter, r *http.Request) { doJSONWrite(w, http.StatusOK, returnSession) } +// swagger:operation DELETE /cache/{apiID} cache invalidateCache +// +// Invalidate cache +// +//--- +// parameters: +// - in: path +// name: apiID +// required: true +// schema: +// type: string +// description: API ID +// responses: +// 200: +// description: Invalidate cache +// schema: +// "$ref": "#/responses/apiOk" func invalidateCacheHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] diff --git a/oauth_manager.go b/oauth_manager.go index 11f7a6d9982b..24e6f305d74f 100644 --- a/oauth_manager.go +++ b/oauth_manager.go @@ -40,6 +40,8 @@ Effort required by Resource Owner: */ // OAuthClient is a representation within an APISpec of a client +// +// swagger:model type OAuthClient struct { ClientID string `json:"id"` ClientSecret string `json:"secret"` From 1891d36135ee7daca9c590392a574250e01c4b2e Mon Sep 17 00:00:00 2001 From: Leonid Bugaev Date: Fri, 7 Sep 2018 14:46:39 +0300 Subject: [PATCH 06/15] Fix swagger issue --- api.go | 2 +- oauth_manager.go | 2 -- user/session.go | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index 53d006e39401..98a7c8a3c624 100644 --- a/api.go +++ b/api.go @@ -1501,7 +1501,7 @@ func oauthClientStorageID(clientID string) string { // 200: // description: Client created // schema: -// "$ref": "#/responses/OAuthClient" +// "$ref": "#/responses/NewClientRequest" func createOauthClient(w http.ResponseWriter, r *http.Request) { var newOauthClient NewClientRequest if err := json.NewDecoder(r.Body).Decode(&newOauthClient); err != nil { diff --git a/oauth_manager.go b/oauth_manager.go index 24e6f305d74f..11f7a6d9982b 100644 --- a/oauth_manager.go +++ b/oauth_manager.go @@ -40,8 +40,6 @@ Effort required by Resource Owner: */ // OAuthClient is a representation within an APISpec of a client -// -// swagger:model type OAuthClient struct { ClientID string `json:"id"` ClientSecret string `json:"secret"` diff --git a/user/session.go b/user/session.go index 4739ee2291c3..b13dfe059205 100644 --- a/user/session.go +++ b/user/session.go @@ -44,6 +44,7 @@ type AccessDefinition struct { // SessionState objects represent a current API session, mainly used for rate limiting. // There's a data structure that's based on this and it's used for Protocol Buffer support, make sure to update "coprocess/proto/coprocess_session_state.proto" and generate the bindings using: cd coprocess/proto && ./update_bindings.sh +// // swagger:model type SessionState struct { LastCheck int64 `json:"last_check" msg:"last_check"` From daebccae9ee4f8a831109dea2246ee88eeb747c4 Mon Sep 17 00:00:00 2001 From: marksou Date: Fri, 7 Sep 2018 12:57:37 +0100 Subject: [PATCH 07/15] updates before new pull --- api.go | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/api.go b/api.go index 98a7c8a3c624..68c00ed1be79 100644 --- a/api.go +++ b/api.go @@ -764,7 +764,7 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // - in: path // name: apiID // required: true -// type: integer +// type: string // minimum: 1 // description: The API ID // responses: @@ -783,7 +783,7 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // - in: path // name: apiID // required: true -// type: integer +// type: string // minimum: 1 // description: The API ID // responses: @@ -904,7 +904,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // - in: path // name: keyID // required: true -// type: integer +// type: string // minimum: 1 // description: The Key ID // responses: @@ -932,7 +932,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // - in: path // name: keyID // required: true -// type: integer +// type: string // minimum: 1 // description: The Key ID // responses: @@ -950,7 +950,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // - in: path // name: keyID // required: true -// type: integer +// type: string // minimum: 1 // description: The Key ID // responses: @@ -1483,9 +1483,9 @@ func oauthClientStorageID(clientID string) string { return prefixClient + clientID } -// swagger:operation POST /oauth/clients/create oauth createOAuthClient +// swagger:operation POST /oauth/clients/create OAuth createOAuthClient // -// Create oAuth client +// Create an OAuth client // //--- // requestBody: @@ -1727,7 +1727,7 @@ func updateOauthClient(keyName, apiID string, r *http.Request) (interface{}, int // required: true // schema: // type: string -// description: API id +// description: The API id // - in: path // name: keyName // required: true @@ -1815,9 +1815,9 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { doJSONWrite(w, http.StatusOK, success) } -// swagger:operation GET /oauth/clients/{apiID} oauth listOAuthClients +// swagger:operation GET /oauth/clients/{apiID} OAuth listOAuthClients // -// List oAuth client +// List oAuth clients // //--- // parameters: @@ -1826,18 +1826,18 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // required: true // schema: // type: string -// description: API ID +// description: The API ID // responses: // 200: -// description: Get client details or list of clients +// description: Get OAuth client details or a list of OAuth clients // schema: // type: array // items: // "$ref": "#/responses/NewClientRequest" -// swagger:operation GET /oauth/clients/{apiID}/{keyName} oauth getOAuthClient +// swagger:operation GET /oauth/clients/{apiID}/{keyName} OAuth getOAuthClient // -// Get oAuth client +// Get OAuth client // //--- // parameters: @@ -1852,10 +1852,10 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // required: true // schema: // type: string -// description: Client ID +// description: The Client ID // responses: // 200: -// description: Get client details or list of clients +// description: Get OAuth client details or a list of OAuth clients // schema: // "$ref": "#/responses/NewClientRequest" @@ -1870,16 +1870,16 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // required: true // schema: // type: string -// description: API ID +// description: The API ID // - in: path // name: keyName // required: true // schema: // type: string -// description: Client ID +// description: The Client ID // responses: // 200: -// description: oAuth client deleted +// description: OAuth client deleted // schema: // "$ref": "#/responses/apiModifyKeySuccess" // examples: @@ -1911,9 +1911,9 @@ func oAuthClientHandler(w http.ResponseWriter, r *http.Request) { doJSONWrite(w, code, obj) } -// swagger:operation GET /oauth/clients/{apiID}/{keyName}/tokens oauth getOAuthClientTokens +// swagger:operation GET /oauth/clients/{apiID}/{keyName}/tokens OAuth getOAuthClientTokens // -// Get oAuth client tokens +// Get OAuth client tokens // //--- // parameters: @@ -1922,16 +1922,16 @@ func oAuthClientHandler(w http.ResponseWriter, r *http.Request) { // required: true // schema: // type: string -// description: API ID +// description: The API ID // - in: path // name: keyName // required: true // schema: // type: string -// description: Client ID +// description: The Client ID // responses: // 200: -// description: Get list of tokens +// description: Get a list of tokens // schema: // type: array // items: @@ -2138,7 +2138,7 @@ func userRatesCheck(w http.ResponseWriter, r *http.Request) { doJSONWrite(w, http.StatusOK, returnSession) } -// swagger:operation DELETE /cache/{apiID} cache invalidateCache +// swagger:operation DELETE /cache/{apiID} Cache invalidateCache // // Invalidate cache // @@ -2149,7 +2149,7 @@ func userRatesCheck(w http.ResponseWriter, r *http.Request) { // required: true // schema: // type: string -// description: API ID +// description: The API ID // responses: // 200: // description: Invalidate cache From 462019d450c7acd8bee795af44a46746e550f6d3 Mon Sep 17 00:00:00 2001 From: marksou Date: Fri, 7 Sep 2018 16:47:34 +0100 Subject: [PATCH 08/15] Updated OAuth and Invalidate Cache sections --- api.go | 149 +++++++++++++++++++++++++++------------------------------ 1 file changed, 70 insertions(+), 79 deletions(-) diff --git a/api.go b/api.go index 68c00ed1be79..a8df65837dc6 100644 --- a/api.go +++ b/api.go @@ -765,7 +765,6 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // name: apiID // required: true // type: string -// minimum: 1 // description: The API ID // responses: // 200: @@ -784,7 +783,6 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // name: apiID // required: true // type: string -// minimum: 1 // description: The API ID // responses: // 200: @@ -860,7 +858,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // 200: // description: New Key created // schema: -// "$ref": "#/responses/apiModifyKeySuccess" +// $ref: "#/responses/apiModifyKeySuccess" // examples: // status: "ok" // action: "created" @@ -868,7 +866,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // 400: // description: Malformed data // schema: -// "$ref": "#/responses/apiStatusMessage" +// $ref: "#/responses/apiStatusMessage" // examples: // status: "error" // message: "Malformed Key data" @@ -882,7 +880,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // 200: // description: New Key added // schema: -// "$ref": "#/responses/apiModifyKeySuccess" +// $ref: "#/responses/apiModifyKeySuccess" // examples: // status: "ok" // action: "created" @@ -890,7 +888,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // 400: // description: Malformed data // schema: -// "$ref": "#/responses/apiStatusMessage" +// $ref: "#/responses/apiStatusMessage" // examples: // status: "error" // message: "Malformed Key data" @@ -905,7 +903,6 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // name: keyID // required: true // type: string -// minimum: 1 // description: The Key ID // responses: // 200: @@ -918,7 +915,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // 400: // description: No or incorrect Key ID specified // schema: -// "$ref": "#/responses/apiStatusMessage" +// $ref: "#/responses/apiStatusMessage" // examples: // status: "error" // message: "Key ID not specified" @@ -933,7 +930,6 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // name: keyID // required: true // type: string -// minimum: 1 // description: The Key ID // responses: // 200: @@ -951,7 +947,6 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // name: keyID // required: true // type: string -// minimum: 1 // description: The Key ID // responses: // 200: @@ -1492,7 +1487,7 @@ func oauthClientStorageID(clientID string) string { // content: // application/json: // schema: -// "$ref": "#/definitions/NewClientRequest" +// $ref: "#/definitions/NewClientRequest" // examples: // client_id: test // api_id: id @@ -1501,7 +1496,7 @@ func oauthClientStorageID(clientID string) string { // 200: // description: Client created // schema: -// "$ref": "#/responses/NewClientRequest" +// $ref: "#/definitions/NewClientRequest" func createOauthClient(w http.ResponseWriter, r *http.Request) { var newOauthClient NewClientRequest if err := json.NewDecoder(r.Body).Decode(&newOauthClient); err != nil { @@ -1718,22 +1713,20 @@ func updateOauthClient(keyName, apiID string, r *http.Request) (interface{}, int // swagger:operation DELETE /oauth/refresh/{keyName} oauth invalidateOAuthRefresh // -// Invalidate oAuth refresh token +// Invalidate OAuth refresh token // //--- // parameters: -// - in: query -// name: api_id -// required: true -// schema: -// type: string -// description: The API id -// - in: path -// name: keyName -// required: true -// schema: -// type: string -// description: Refresh token +// - in: query +// name: api_id +// required: true +// type: string +// description: The API id +// - in: path +// name: keyName +// required: true +// type: string +// description: Refresh token // requestBody: // content: // application/json: @@ -1747,7 +1740,7 @@ func updateOauthClient(keyName, apiID string, r *http.Request) (interface{}, int // 200: // description: Deleted // schema: -// "$ref": "#/responses/apiModifyKeySuccess" +// "$ref": "#/definitions/apiModifyKeySuccess" func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { apiID := r.URL.Query().Get("api_id") if apiID == "" { @@ -1817,23 +1810,22 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // swagger:operation GET /oauth/clients/{apiID} OAuth listOAuthClients // -// List oAuth clients +// List OAuth clients // //--- // parameters: -// - in: path -// name: apiID -// required: true -// schema: -// type: string -// description: The API ID +// - in: path +// name: apiID +// required: true +// type: string +// description: The API ID // responses: // 200: // description: Get OAuth client details or a list of OAuth clients // schema: // type: array // items: -// "$ref": "#/responses/NewClientRequest" +// "$ref": "#/definitions/NewClientRequest" // swagger:operation GET /oauth/clients/{apiID}/{keyName} OAuth getOAuthClient // @@ -1841,42 +1833,40 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // //--- // parameters: -// - in: path -// name: apiID -// required: true -// schema: -// type: string -// description: API ID -// - in: path -// name: keyName -// required: true -// schema: -// type: string -// description: The Client ID +// - in: path +// name: apiID +// required: true +// type: string +// minimum: 1 +// description: The API ID +// - in: path +// name: keyName +// required: true +// type: string +// description: The Client ID // responses: // 200: // description: Get OAuth client details or a list of OAuth clients // schema: -// "$ref": "#/responses/NewClientRequest" +// "$ref": "#/definitions/NewClientRequest" -// swagger:operation DELETE /oauth/clients/{apiID}/{keyName} oauth deleteOAuthClient +// swagger:operation DELETE /oauth/clients/{apiID}/{keyName} OAuth deleteOAuthClient // // Delete oAuth client // //--- // parameters: -// - in: path -// name: apiID -// required: true -// schema: -// type: string -// description: The API ID -// - in: path -// name: keyName -// required: true -// schema: -// type: string -// description: The Client ID +// - in: path +// name: apiID +// required: true +// type: string +// minimum: 1 +// description: The API ID +// - in: path +// name: keyName +// required: true +// type: string +// description: The Client ID // responses: // 200: // description: OAuth client deleted @@ -1917,18 +1907,17 @@ func oAuthClientHandler(w http.ResponseWriter, r *http.Request) { // //--- // parameters: -// - in: path -// name: apiID -// required: true -// schema: -// type: string -// description: The API ID -// - in: path -// name: keyName -// required: true -// schema: -// type: string -// description: The Client ID +// - in: path +// name: apiID +// required: true +// type: string +// minimum: 1 +// description: The API ID +// - in: path +// name: keyName +// required: true +// type: string +// description: The Client ID // responses: // 200: // description: Get a list of tokens @@ -2144,17 +2133,19 @@ func userRatesCheck(w http.ResponseWriter, r *http.Request) { // //--- // parameters: -// - in: path -// name: apiID -// required: true -// schema: -// type: string -// description: The API ID +// - in: path +// name: apiID +// required: true +// type: string +// description: The API ID // responses: // 200: // description: Invalidate cache // schema: -// "$ref": "#/responses/apiOk" +// $ref: "#/responses/apiStatusMessage" +// examples: +// status: "ok" +// message: "cache invalidated" func invalidateCacheHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] From c828f2a88c7d87d8383cf93a55d7a1727303808b Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Tue, 19 Feb 2019 10:19:17 +0100 Subject: [PATCH 09/15] generation works now little working version passes generation and validation --- api.go | 226 ++++++++++++++++++++--------------------------------- swagger.go | 21 +++++ tracing.go | 12 +-- 3 files changed, 109 insertions(+), 150 deletions(-) create mode 100644 swagger.go diff --git a/api.go b/api.go index a8df65837dc6..7f58a9cf6136 100644 --- a/api.go +++ b/api.go @@ -1,7 +1,7 @@ // Tyk Gateway API // // The code below describes the Tyk Gateway API -// Version: 1.7.0 +// Version: 2.8.0 // // Schemes: http, https // Host: localhost @@ -53,8 +53,9 @@ import ( // apiModifyKeySuccess represents when a Key modification was successful // -// swagger:response +// swagger:response apiModifyKeySuccess type apiModifyKeySuccess struct { + // in:body Key string `json:"key"` Status string `json:"status"` Action string `json:"action"` @@ -63,9 +64,8 @@ type apiModifyKeySuccess struct { // apiStatusMessage represents an API status message // -// swagger:response +// swagger:response apiStatusMessage type apiStatusMessage struct { - // Status can be either `ok` or `error` Status string `json:"status"` // Response details Message string `json:"message"` @@ -742,17 +742,10 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // description: API created // schema: // "$ref": "#/responses/apiModifyKeySuccess" -// examples: -// status: "ok" -// action: "created" -// key: "{...API JSON definition...}" // 400: // description: Malformed data // schema: // "$ref": "#/responses/apiStatusMessage" -// examples: -// status: "error" -// message: "Malformed API data" // swagger:operation GET /apis/{apiID} APIs getApi // @@ -789,16 +782,10 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // description: API deleted // schema: // $ref: "#/responses/apiStatusMessage" -// examples: -// status: "ok" -// message: "API deleted" // 400: // description: No API ID specified // schema: // $ref: "#/responses/apiStatusMessage" -// examples: -// status: "error" -// message: "API ID not specified" func apiHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] @@ -838,7 +825,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // swagger:operation GET /keys Keys listKeys // -// List All Keys +// List all keys // //--- // responses: @@ -851,25 +838,18 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // swagger:operation POST /keys Keys createKey // -// Create a new Key +// Create a new key // //--- // responses: // 200: // description: New Key created // schema: -// $ref: "#/responses/apiModifyKeySuccess" -// examples: -// status: "ok" -// action: "created" -// key: "{...KEY JSON definition...}" +// "$ref": "#/responses/apiModifyKeySuccess" // 400: // description: Malformed data // schema: -// $ref: "#/responses/apiStatusMessage" -// examples: -// status: "error" -// message: "Malformed Key data" +// "$ref": "#/responses/apiStatusMessage" // swagger:operation POST /keys Keys addKey // @@ -880,18 +860,11 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // 200: // description: New Key added // schema: -// $ref: "#/responses/apiModifyKeySuccess" -// examples: -// status: "ok" -// action: "created" -// key: "{...KEY JSON definition...}" +// "$ref": "#/responses/apiModifyKeySuccess" // 400: // description: Malformed data // schema: -// $ref: "#/responses/apiStatusMessage" -// examples: -// status: "error" -// message: "Malformed Key data" +// "$ref": "#/responses/apiStatusMessage" // swagger:operation PUT /keys/{keyID} Keys updateKey // @@ -909,20 +882,14 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // description: Key updated // schema: // "$ref": "#/responses/apiModifyKeySuccess" -// examples: -// status: "ok" -// action: "updated" // 400: // description: No or incorrect Key ID specified // schema: -// $ref: "#/responses/apiStatusMessage" -// examples: -// status: "error" -// message: "Key ID not specified" +// "$ref": "#/responses/apiStatusMessage" // swagger:operation GET /keys/{keyID} Keys getKey // -// Get a Key +// Get a key // //--- // parameters: @@ -939,7 +906,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // swagger:operation DELETE /keys/{keyID} Keys deleteKey // -// Delete Key +// Delete a key // //--- // parameters: @@ -953,16 +920,10 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // description: Key deleted // schema: // $ref: "#/responses/apiStatusMessage" -// examples: -// status: "ok" -// message: "Key deleted" // 400: // description: No Key ID specified // schema: // $ref: "#/responses/apiStatusMessage" -// examples: -// status: "error" -// message: "Key ID not specified" func keyHandler(w http.ResponseWriter, r *http.Request) { keyName := mux.Vars(r)["keyName"] apiID := r.URL.Query().Get("api_id") @@ -1275,12 +1236,14 @@ func handleDeleteOrgKey(orgID string) (interface{}, int) { return statusObj, http.StatusOK } -// swagger:route GET /reload/group Reload reloadGroup -// -// Reloads all the Tyk Gateways in a cluster -// -// Responses: -// 200: apiStatusMessage +// swagger:operation GET /reload/group Reload reloadGroup +// --- +// summary: Reloads all the Tyk Gateways in a cluster +// responses: +// "200": +// description: All gateways in a cluster were successfully refreshed +// schema: +// "$ref": "#/responses/apiStatusMessage" func groupResetHandler(w http.ResponseWriter, r *http.Request) { log.WithFields(logrus.Fields{ "prefix": "api", @@ -1463,7 +1426,7 @@ func createKeyHandler(w http.ResponseWriter, r *http.Request) { // NewClientRequest is an outward facing JSON object translated from osin OAuthClients // -// swagger:model +// swagger:model NewClientRequest type NewClientRequest struct { ClientID string `json:"client_id"` ClientRedirectURI string `json:"redirect_uri"` @@ -1483,20 +1446,17 @@ func oauthClientStorageID(clientID string) string { // Create an OAuth client // //--- -// requestBody: -// content: -// application/json: -// schema: -// $ref: "#/definitions/NewClientRequest" -// examples: -// client_id: test -// api_id: id -// policy_id: policy +// parameters: +// - in: body +// name: client_info +// required: true +// schema: +// "$ref": "#/definitions/NewClientRequest" // responses: // 200: // description: Client created // schema: -// $ref: "#/definitions/NewClientRequest" +// "$ref": "#/definitions/NewClientRequest" func createOauthClient(w http.ResponseWriter, r *http.Request) { var newOauthClient NewClientRequest if err := json.NewDecoder(r.Body).Decode(&newOauthClient); err != nil { @@ -1713,34 +1673,25 @@ func updateOauthClient(keyName, apiID string, r *http.Request) (interface{}, int // swagger:operation DELETE /oauth/refresh/{keyName} oauth invalidateOAuthRefresh // -// Invalidate OAuth refresh token +// Invalidate oAuth refresh token // //--- // parameters: -// - in: query -// name: api_id -// required: true -// type: string -// description: The API id -// - in: path -// name: keyName -// required: true -// type: string -// description: Refresh token -// requestBody: -// content: -// application/json: -// schema: -// "$ref": "#/definitions/NewClientRequest" -// examples: -// client_id: test -// api_id: id -// policy_id: policy +// - in: query +// name: api_id +// required: true +// type: string +// description: The API id +// - in: path +// name: keyName +// required: true +// type: string +// description: Refresh token // responses: // 200: // description: Deleted // schema: -// "$ref": "#/definitions/apiModifyKeySuccess" +// "$ref": "#/responses/apiModifyKeySuccess" func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { apiID := r.URL.Query().Get("api_id") if apiID == "" { @@ -1810,15 +1761,15 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // swagger:operation GET /oauth/clients/{apiID} OAuth listOAuthClients // -// List OAuth clients +// List oAuth clients // //--- // parameters: -// - in: path -// name: apiID -// required: true -// type: string -// description: The API ID +// - in: path +// name: apiID +// required: true +// type: string +// description: The API ID // responses: // 200: // description: Get OAuth client details or a list of OAuth clients @@ -1833,48 +1784,43 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // //--- // parameters: -// - in: path -// name: apiID -// required: true -// type: string -// minimum: 1 -// description: The API ID -// - in: path -// name: keyName -// required: true -// type: string -// description: The Client ID +// - in: path +// name: apiID +// required: true +// type: string +// description: API ID +// - in: path +// name: keyName +// required: true +// type: string +// description: The Client ID // responses: // 200: // description: Get OAuth client details or a list of OAuth clients // schema: // "$ref": "#/definitions/NewClientRequest" -// swagger:operation DELETE /oauth/clients/{apiID}/{keyName} OAuth deleteOAuthClient +// swagger:operation DELETE /oauth/clients/{apiID}/{keyName} oauth deleteOAuthClient // // Delete oAuth client // //--- // parameters: -// - in: path -// name: apiID -// required: true -// type: string -// minimum: 1 -// description: The API ID -// - in: path -// name: keyName -// required: true -// type: string -// description: The Client ID +// - in: path +// name: apiID +// required: true +// type: string +// description: The API ID +// - in: path +// name: keyName +// required: true +// type: string +// description: The Client ID // responses: // 200: // description: OAuth client deleted // schema: // "$ref": "#/responses/apiModifyKeySuccess" -// examples: -// status: "ok" -// action: "deleted" func oAuthClientHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] keyName := mux.Vars(r)["keyName"] @@ -1907,17 +1853,16 @@ func oAuthClientHandler(w http.ResponseWriter, r *http.Request) { // //--- // parameters: -// - in: path -// name: apiID -// required: true -// type: string -// minimum: 1 -// description: The API ID -// - in: path -// name: keyName -// required: true -// type: string -// description: The Client ID +// - in: path +// name: apiID +// required: true +// type: string +// description: The API ID +// - in: path +// name: keyName +// required: true +// type: string +// description: The Client ID // responses: // 200: // description: Get a list of tokens @@ -2133,19 +2078,16 @@ func userRatesCheck(w http.ResponseWriter, r *http.Request) { // //--- // parameters: -// - in: path -// name: apiID -// required: true -// type: string -// description: The API ID +// - in: path +// name: apiID +// required: true +// type: string +// description: The API ID // responses: // 200: // description: Invalidate cache // schema: -// $ref: "#/responses/apiStatusMessage" -// examples: -// status: "ok" -// message: "cache invalidated" +// "$ref": "#/responses/apiStatusMessage" func invalidateCacheHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] diff --git a/swagger.go b/swagger.go new file mode 100644 index 000000000000..1cfd95bb8d0e --- /dev/null +++ b/swagger.go @@ -0,0 +1,21 @@ +package main + +import ( + "github.com/TykTechnologies/tyk/apidef" + "github.com/TykTechnologies/tyk/user" +) + +// parameterBodies +// swagger:response parameterBodies +type swaggerParameterBodies struct { + // in: body + APIStatusMessage apiStatusMessage + // in: body + APIModifyKeySuccess apiModifyKeySuccess + // in: body + NewClientRequest NewClientRequest + // in: body + APIDefinition apidef.APIDefinition + // in: body + SessionState user.SessionState +} diff --git a/tracing.go b/tracing.go index c8a1c3dc267d..efcbcef858a0 100644 --- a/tracing.go +++ b/tracing.go @@ -29,25 +29,21 @@ func (tr *traceHttpRequest) toRequest() *http.Request { return r } -// Tracing HTTP request -// -// swagger:model +// TraceRequest is for tracing an HTTP request +// swagger:model TraceRequest type traceRequest struct { Request *traceHttpRequest `json:"request"` Spec *apidef.APIDefinition `json:"spec"` } -// Tracing HTTP response -// -// swagger:model +// TraceResponse is for tracing an HTTP response +// swagger:model TraceResponse type traceResponse struct { Message string `json:"message"` Response string `json:"response"` Logs string `json:"logs"` } -// swagger:operation POST /trace trace trace -// // Tracing request // Used to test API definition by sending sample request, // and analysisng output of both response and logs From d3fcd62b274ede7081ce9340f7cd93971cc0eb48 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Tue, 19 Feb 2019 18:09:26 +0100 Subject: [PATCH 10/15] add summary to all endpoints --- api.go | 79 ++++++++++++++++++---------------------------------------- 1 file changed, 24 insertions(+), 55 deletions(-) diff --git a/api.go b/api.go index 7f58a9cf6136..5dc63174432a 100644 --- a/api.go +++ b/api.go @@ -720,10 +720,8 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // swagger:operation GET /apis APIs listApis // -// List APIs -// Only if used without the Tyk Dashboard -// //--- +// summary: List APIs. // responses: // 200: // description: List of API definitions @@ -734,9 +732,8 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // swagger:operation POST /apis APIs createApi // -// Create API -// //--- +// summary: Create an API // responses: // 200: // description: API created @@ -749,10 +746,8 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // swagger:operation GET /apis/{apiID} APIs getApi // -// Get API -// Only if used without the Tyk Dashboard -// //--- +// summary: Get an API. // parameters: // - in: path // name: apiID @@ -767,10 +762,8 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // swagger:operation DELETE /apis/{apiID} APIs deleteApi // -// Delete API -// Only if used without the Tyk Dashboard -// //--- +// summary: Delete an API. // parameters: // - in: path // name: apiID @@ -825,9 +818,8 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // swagger:operation GET /keys Keys listKeys // -// List all keys -// //--- +// summary: List all keys attached to an API // responses: // 200: // description: List of all API keys @@ -838,9 +830,8 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // swagger:operation POST /keys Keys createKey // -// Create a new key -// //--- +// summary: Create a new API key // responses: // 200: // description: New Key created @@ -851,26 +842,10 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // schema: // "$ref": "#/responses/apiStatusMessage" -// swagger:operation POST /keys Keys addKey -// -// Add an existing Key -// -//--- -// responses: -// 200: -// description: New Key added -// schema: -// "$ref": "#/responses/apiModifyKeySuccess" -// 400: -// description: Malformed data -// schema: -// "$ref": "#/responses/apiStatusMessage" - // swagger:operation PUT /keys/{keyID} Keys updateKey // -// Update a Key -// //--- +// summary: Update an API key // parameters: // - in: path // name: keyID @@ -889,9 +864,8 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // swagger:operation GET /keys/{keyID} Keys getKey // -// Get a key -// //--- +// summary: Retrieve an API key // parameters: // - in: path // name: keyID @@ -906,9 +880,8 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // swagger:operation DELETE /keys/{keyID} Keys deleteKey // -// Delete a key -// //--- +// summary: Delete ann API key // parameters: // - in: path // name: keyID @@ -1265,12 +1238,15 @@ func groupResetHandler(w http.ResponseWriter, r *http.Request) { // Otherwise, it won't block and fn will be called once the reload is // finished. // -// swagger:route GET /reload Reload reload +// swagger:operation GET /reload Reload a gateway instance // -// Reloads a single Tyk Gateway instance -// -// Responses: -// 200: apiStatusMessage +// --- +// summary: Reloads a single Tyk Gateway instance +// responses: +// "200": +// description: All gateways in a cluster were successfully refreshed +// schema: +// "$ref": "#/responses/apiStatusMessage" func resetHandler(fn func()) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var wg sync.WaitGroup @@ -1443,9 +1419,8 @@ func oauthClientStorageID(clientID string) string { // swagger:operation POST /oauth/clients/create OAuth createOAuthClient // -// Create an OAuth client -// //--- +// summary: Create a new OAuth client // parameters: // - in: body // name: client_info @@ -1673,9 +1648,8 @@ func updateOauthClient(keyName, apiID string, r *http.Request) (interface{}, int // swagger:operation DELETE /oauth/refresh/{keyName} oauth invalidateOAuthRefresh // -// Invalidate oAuth refresh token -// //--- +// summary: Invalidate oAuth refresh token // parameters: // - in: query // name: api_id @@ -1761,9 +1735,8 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // swagger:operation GET /oauth/clients/{apiID} OAuth listOAuthClients // -// List oAuth clients -// //--- +// summary: List all Oauth clients // parameters: // - in: path // name: apiID @@ -1780,9 +1753,8 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // swagger:operation GET /oauth/clients/{apiID}/{keyName} OAuth getOAuthClient // -// Get OAuth client -// //--- +// summary: Retrieve an oAuth client // parameters: // - in: path // name: apiID @@ -1802,9 +1774,8 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // swagger:operation DELETE /oauth/clients/{apiID}/{keyName} oauth deleteOAuthClient // -// Delete oAuth client -// //--- +// summary: Delete an oAuth client // parameters: // - in: path // name: apiID @@ -1849,9 +1820,8 @@ func oAuthClientHandler(w http.ResponseWriter, r *http.Request) { // swagger:operation GET /oauth/clients/{apiID}/{keyName}/tokens OAuth getOAuthClientTokens // -// Get OAuth client tokens -// //--- +// summary: Get the tokens of an oAuth client // parameters: // - in: path // name: apiID @@ -2074,9 +2044,8 @@ func userRatesCheck(w http.ResponseWriter, r *http.Request) { // swagger:operation DELETE /cache/{apiID} Cache invalidateCache // -// Invalidate cache -// //--- +// summary: Invalidate the cache of a given api by it's ID // parameters: // - in: path // name: apiID From c92a1d3df5a5fc7f6d21a56e617a3114c2cf278d Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Tue, 19 Feb 2019 19:59:18 +0100 Subject: [PATCH 11/15] s/swagger:response/swagger:model to make sure the conversion from 2.0 to 3.0 validates without any error --- api.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/api.go b/api.go index 5dc63174432a..7f7656250368 100644 --- a/api.go +++ b/api.go @@ -53,7 +53,7 @@ import ( // apiModifyKeySuccess represents when a Key modification was successful // -// swagger:response apiModifyKeySuccess +// swagger:model apiModifyKeySuccess type apiModifyKeySuccess struct { // in:body Key string `json:"key"` @@ -64,7 +64,7 @@ type apiModifyKeySuccess struct { // apiStatusMessage represents an API status message // -// swagger:response apiStatusMessage +// swagger:model apiStatusMessage type apiStatusMessage struct { Status string `json:"status"` // Response details @@ -738,11 +738,11 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // 200: // description: API created // schema: -// "$ref": "#/responses/apiModifyKeySuccess" +// "$ref": "#/definitions/apiModifyKeySuccess" // 400: // description: Malformed data // schema: -// "$ref": "#/responses/apiStatusMessage" +// "$ref": "#/definitions/apiStatusMessage" // swagger:operation GET /apis/{apiID} APIs getApi // @@ -774,11 +774,11 @@ func handleDeleteAPI(apiID string) (interface{}, int) { // 200: // description: API deleted // schema: -// $ref: "#/responses/apiStatusMessage" +// $ref: "#/definitions/apiStatusMessage" // 400: // description: No API ID specified // schema: -// $ref: "#/responses/apiStatusMessage" +// $ref: "#/definitions/apiStatusMessage" func apiHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] @@ -836,11 +836,11 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // 200: // description: New Key created // schema: -// "$ref": "#/responses/apiModifyKeySuccess" +// "$ref": "#/definitions/apiModifyKeySuccess" // 400: // description: Malformed data // schema: -// "$ref": "#/responses/apiStatusMessage" +// "$ref": "#/definitions/apiStatusMessage" // swagger:operation PUT /keys/{keyID} Keys updateKey // @@ -856,11 +856,11 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // 200: // description: Key updated // schema: -// "$ref": "#/responses/apiModifyKeySuccess" +// "$ref": "#/definitions/apiModifyKeySuccess" // 400: // description: No or incorrect Key ID specified // schema: -// "$ref": "#/responses/apiStatusMessage" +// "$ref": "#/definitions/apiStatusMessage" // swagger:operation GET /keys/{keyID} Keys getKey // @@ -892,11 +892,11 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // 200: // description: Key deleted // schema: -// $ref: "#/responses/apiStatusMessage" +// $ref: "#/definitions/apiStatusMessage" // 400: // description: No Key ID specified // schema: -// $ref: "#/responses/apiStatusMessage" +// $ref: "#/definitions/apiStatusMessage" func keyHandler(w http.ResponseWriter, r *http.Request) { keyName := mux.Vars(r)["keyName"] apiID := r.URL.Query().Get("api_id") @@ -1216,7 +1216,7 @@ func handleDeleteOrgKey(orgID string) (interface{}, int) { // "200": // description: All gateways in a cluster were successfully refreshed // schema: -// "$ref": "#/responses/apiStatusMessage" +// "$ref": "#/definitions/apiStatusMessage" func groupResetHandler(w http.ResponseWriter, r *http.Request) { log.WithFields(logrus.Fields{ "prefix": "api", @@ -1246,7 +1246,7 @@ func groupResetHandler(w http.ResponseWriter, r *http.Request) { // "200": // description: All gateways in a cluster were successfully refreshed // schema: -// "$ref": "#/responses/apiStatusMessage" +// "$ref": "#/definitions/apiStatusMessage" func resetHandler(fn func()) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var wg sync.WaitGroup @@ -1665,7 +1665,7 @@ func updateOauthClient(keyName, apiID string, r *http.Request) (interface{}, int // 200: // description: Deleted // schema: -// "$ref": "#/responses/apiModifyKeySuccess" +// "$ref": "#/definitions/apiModifyKeySuccess" func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { apiID := r.URL.Query().Get("api_id") if apiID == "" { @@ -1791,7 +1791,7 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) { // 200: // description: OAuth client deleted // schema: -// "$ref": "#/responses/apiModifyKeySuccess" +// "$ref": "#/definitions/apiModifyKeySuccess" func oAuthClientHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] keyName := mux.Vars(r)["keyName"] @@ -2056,7 +2056,7 @@ func userRatesCheck(w http.ResponseWriter, r *http.Request) { // 200: // description: Invalidate cache // schema: -// "$ref": "#/responses/apiStatusMessage" +// "$ref": "#/definitions/apiStatusMessage" func invalidateCacheHandler(w http.ResponseWriter, r *http.Request) { apiID := mux.Vars(r)["apiID"] From 663bbd26050b2fdf7a862af84636d7e50e969602 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Tue, 19 Feb 2019 22:11:42 +0100 Subject: [PATCH 12/15] add swagger validation to CI --- .travis.yml | 7 + gateway-swagger.yaml | 1825 ++++++++++++++++++++++++++++++++++++++++++ utils/ci-swagger.sh | 33 + 3 files changed, 1865 insertions(+) create mode 100644 gateway-swagger.yaml create mode 100755 utils/ci-swagger.sh diff --git a/.travis.yml b/.travis.yml index 903084dbb570..293c937b078d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,10 @@ addons: - python3.5 - python3-pip - libluajit-5.1-dev + ### Needed to convert the swagger 2.0 file to openapi 3.0 + ### The swagger docs are actually written as per the 2.0 spec as there is no + ### support for openapi 3.0 in Go - at least for now. + - npm matrix: include: @@ -31,13 +35,16 @@ install: - go install ./... # As of 1.9, ./... no longer includes ./vendor/... - go install ./vendor/{golang.org/x/tools/cmd/goimports,github.com/wadey/gocovmerge,github.com/mattn/goveralls} + - go get github.com/go-swagger/go-swagger/cmd/swagger script: - sudo pip3 install google - sudo pip3 install protobuf + - sudo npm install -g api-spec-converter - go build -tags 'coprocess python' - go build -tags 'coprocess lua' - go build -tags 'coprocess grpc' + - ./utils/ci-swagger.sh - ./utils/ci-test.sh - if [[ $LATEST_GO ]]; then goveralls -coverprofile=<(gocovmerge *.cov); fi - ./utils/ci-benchmark.sh diff --git a/gateway-swagger.yaml b/gateway-swagger.yaml new file mode 100644 index 000000000000..f5b3c3477fd8 --- /dev/null +++ b/gateway-swagger.yaml @@ -0,0 +1,1825 @@ +openapi: 3.0.0 +info: + description: The code below describes the Tyk Gateway API + title: Tyk Gateway API + version: 2.8.0 +servers: + - url: 'http://localhost/tyk/' + - url: 'https://localhost/tyk/' +paths: + /apis: + get: + responses: + '200': + content: + application/json: + schema: + items: + $ref: '#/components/schemas/APIDefinition' + type: array + description: List of API definitions + tags: + - APIs + operationId: listApis + summary: List APIs. + post: + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/apiModifyKeySuccess' + description: API created + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/apiStatusMessage' + description: Malformed data + tags: + - APIs + operationId: createApi + summary: Create an API + '/apis/{apiID}': + delete: + parameters: + - description: The API ID + in: path + name: apiID + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/apiStatusMessage' + description: API deleted + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/apiStatusMessage' + description: No API ID specified + tags: + - APIs + operationId: deleteApi + summary: Delete an API. + get: + parameters: + - description: The API ID + in: path + name: apiID + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/APIDefinition' + description: API definition + tags: + - APIs + operationId: getApi + summary: Get an API. + '/cache/{apiID}': + delete: + parameters: + - description: The API ID + in: path + name: apiID + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/apiStatusMessage' + description: Invalidate cache + tags: + - Cache + operationId: invalidateCache + summary: Invalidate the cache of a given api by it's ID + /keys: + get: + responses: + '200': + content: + application/json: + schema: + items: + type: string + type: array + description: List of all API keys + tags: + - Keys + operationId: listKeys + summary: List all keys attached to an API + post: + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/apiModifyKeySuccess' + description: New Key created + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/apiStatusMessage' + description: Malformed data + tags: + - Keys + operationId: createKey + summary: Create a new API key + '/keys/{keyID}': + delete: + parameters: + - description: The Key ID + in: path + name: keyID + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/apiStatusMessage' + description: Key deleted + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/apiStatusMessage' + description: No Key ID specified + tags: + - Keys + operationId: deleteKey + summary: Delete ann API key + get: + parameters: + - description: The Key ID + in: path + name: keyID + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/SessionState' + description: Key object + tags: + - Keys + operationId: getKey + summary: Retrieve an API key + put: + parameters: + - description: The Key ID + in: path + name: keyID + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/apiModifyKeySuccess' + description: Key updated + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/apiStatusMessage' + description: No or incorrect Key ID specified + tags: + - Keys + operationId: updateKey + summary: Update an API key + /oauth/clients/create: + post: + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/NewClientRequest' + description: Client created + tags: + - OAuth + operationId: createOAuthClient + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/NewClientRequest' + required: true + summary: Create a new OAuth client + '/oauth/clients/{apiID}': + get: + parameters: + - description: The API ID + in: path + name: apiID + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + items: + $ref: '#/components/schemas/NewClientRequest' + type: array + description: Get OAuth client details or a list of OAuth clients + tags: + - OAuth + operationId: listOAuthClients + summary: List all Oauth clients + '/oauth/clients/{apiID}/{keyName}': + delete: + parameters: + - description: The API ID + in: path + name: apiID + required: true + schema: + type: string + - description: The Client ID + in: path + name: keyName + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/apiModifyKeySuccess' + description: OAuth client deleted + tags: + - oauth + operationId: deleteOAuthClient + summary: Delete an oAuth client + get: + parameters: + - description: API ID + in: path + name: apiID + required: true + schema: + type: string + - description: The Client ID + in: path + name: keyName + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/NewClientRequest' + description: Get OAuth client details or a list of OAuth clients + tags: + - OAuth + operationId: getOAuthClient + summary: Retrieve an oAuth client + '/oauth/clients/{apiID}/{keyName}/tokens': + get: + parameters: + - description: The API ID + in: path + name: apiID + required: true + schema: + type: string + - description: The Client ID + in: path + name: keyName + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + items: + type: string + type: array + description: Get a list of tokens + tags: + - OAuth + operationId: getOAuthClientTokens + summary: Get the tokens of an oAuth client + '/oauth/refresh/{keyName}': + delete: + parameters: + - description: The API id + in: query + name: api_id + required: true + schema: + type: string + - description: Refresh token + in: path + name: keyName + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/apiModifyKeySuccess' + description: Deleted + tags: + - oauth + operationId: invalidateOAuthRefresh + summary: Invalidate oAuth refresh token + /reload: + get: + responses: + '200': + description: All gateways in a cluster were successfully refreshed + tags: + - Reload + - a + - gateway + operationId: instance + summary: Reloads a single Tyk Gateway instance + /reload/group: + get: + responses: + '200': + description: All gateways in a cluster were successfully refreshed + tags: + - Reload + operationId: reloadGroup + summary: Reloads all the Tyk Gateways in a cluster +components: + responses: + parameterBodies: + content: + application/json: + schema: + $ref: '#/components/schemas/SessionState' + description: parameterBodies + schemas: + APIDefinition: + properties: + tags: + items: + type: string + type: array + x-go-name: Tags + CORS: + properties: + allow_credentials: + type: boolean + x-go-name: AllowCredentials + allowed_headers: + items: + type: string + type: array + x-go-name: AllowedHeaders + allowed_methods: + items: + type: string + type: array + x-go-name: AllowedMethods + allowed_origins: + items: + type: string + type: array + x-go-name: AllowedOrigins + debug: + type: boolean + x-go-name: Debug + enable: + type: boolean + x-go-name: Enable + exposed_headers: + items: + type: string + type: array + x-go-name: ExposedHeaders + max_age: + format: int64 + type: integer + x-go-name: MaxAge + options_passthrough: + type: boolean + x-go-name: OptionsPassthrough + type: object + active: + type: boolean + x-go-name: Active + allowed_ips: + items: + type: string + type: array + x-go-name: AllowedIPs + api_id: + type: string + x-go-name: APIID + auth: + $ref: '#/components/schemas/Auth' + auth_provider: + $ref: '#/components/schemas/AuthProviderMeta' + base_identity_provided_by: + $ref: '#/components/schemas/AuthTypeEnum' + basic_auth: + properties: + cache_ttl: + format: int64 + type: integer + x-go-name: CacheTTL + disable_caching: + type: boolean + x-go-name: DisableCaching + type: object + x-go-name: BasicAuth + blacklisted_ips: + items: + type: string + type: array + x-go-name: BlacklistedIPs + cache_options: + $ref: '#/components/schemas/CacheOptions' + certificates: + items: + type: string + type: array + x-go-name: Certificates + client_certificates: + items: + type: string + type: array + x-go-name: ClientCertificates + config_data: + additionalProperties: + type: object + type: object + x-go-name: ConfigData + custom_middleware: + $ref: '#/components/schemas/MiddlewareSection' + custom_middleware_bundle: + type: string + x-go-name: CustomMiddlewareBundle + definition: + properties: + key: + type: string + x-go-name: Key + location: + type: string + x-go-name: Location + strip_path: + type: boolean + x-go-name: StripPath + type: object + x-go-name: VersionDefinition + disable_quota: + type: boolean + x-go-name: DisableQuota + disable_rate_limit: + type: boolean + x-go-name: DisableRateLimit + do_not_track: + type: boolean + x-go-name: DoNotTrack + domain: + type: string + x-go-name: Domain + dont_set_quota_on_create: + type: boolean + x-go-name: DontSetQuotasOnCreate + enable_batch_request_support: + type: boolean + x-go-name: EnableBatchRequestSupport + enable_context_vars: + type: boolean + x-go-name: EnableContextVars + enable_coprocess_auth: + type: boolean + x-go-name: EnableCoProcessAuth + enable_ip_blacklisting: + type: boolean + x-go-name: EnableIpBlacklisting + enable_ip_whitelisting: + type: boolean + x-go-name: EnableIpWhiteListing + enable_jwt: + type: boolean + x-go-name: EnableJWT + enable_signature_checking: + type: boolean + x-go-name: EnableSignatureChecking + event_handlers: + $ref: '#/components/schemas/EventHandlerMetaConfig' + expire_analytics_after: + format: int64 + type: integer + x-go-name: ExpireAnalyticsAfter + global_rate_limit: + $ref: '#/components/schemas/GlobalRateLimit' + hmac_allowed_algorithms: + items: + type: string + type: array + x-go-name: HmacAllowedAlgorithms + hmac_allowed_clock_skew: + format: double + type: number + x-go-name: HmacAllowedClockSkew + id: + $ref: '#/components/schemas/ObjectId' + internal: + type: boolean + x-go-name: Internal + jwt_client_base_field: + type: string + x-go-name: JWTClientIDBaseField + jwt_expires_at_validation_skew: + format: uint64 + type: integer + x-go-name: JWTExpiresAtValidationSkew + jwt_identity_base_field: + type: string + x-go-name: JWTIdentityBaseField + jwt_issued_at_validation_skew: + format: uint64 + type: integer + x-go-name: JWTIssuedAtValidationSkew + jwt_not_before_validation_skew: + format: uint64 + type: integer + x-go-name: JWTNotBeforeValidationSkew + jwt_policy_field_name: + type: string + x-go-name: JWTPolicyFieldName + jwt_scope_claim_name: + type: string + x-go-name: JWTScopeClaimName + jwt_scope_to_policy_mapping: + additionalProperties: + type: string + type: object + x-go-name: JWTScopeToPolicyMapping + jwt_signing_method: + type: string + x-go-name: JWTSigningMethod + jwt_skip_kid: + type: boolean + x-go-name: JWTSkipKid + jwt_source: + type: string + x-go-name: JWTSource + name: + type: string + x-go-name: Name + notifications: + $ref: '#/components/schemas/NotificationsManager' + oauth_meta: + properties: + allowed_access_types: + items: + $ref: '#/components/schemas/AccessRequestType' + type: array + x-go-name: AllowedAccessTypes + allowed_authorize_types: + items: + $ref: '#/components/schemas/AuthorizeRequestType' + type: array + x-go-name: AllowedAuthorizeTypes + auth_login_redirect: + type: string + x-go-name: AuthorizeLoginRedirect + type: object + x-go-name: Oauth2Meta + openid_options: + $ref: '#/components/schemas/OpenIDOptions' + org_id: + type: string + x-go-name: OrgID + pinned_public_keys: + additionalProperties: + type: string + type: object + x-go-name: PinnedPublicKeys + proxy: + properties: + check_host_against_uptime_tests: + type: boolean + x-go-name: CheckHostAgainstUptimeTests + disable_strip_slash: + type: boolean + x-go-name: DisableStripSlash + enable_load_balancing: + type: boolean + x-go-name: EnableLoadBalancing + listen_path: + type: string + x-go-name: ListenPath + preserve_host_header: + type: boolean + x-go-name: PreserveHostHeader + service_discovery: + $ref: '#/components/schemas/ServiceDiscoveryConfiguration' + strip_listen_path: + type: boolean + x-go-name: StripListenPath + target_list: + items: + type: string + type: array + x-go-name: Targets + target_url: + type: string + x-go-name: TargetURL + transport: + properties: + proxy_url: + type: string + x-go-name: ProxyURL + ssl_ciphers: + items: + type: string + type: array + x-go-name: SSLCipherSuites + ssl_insecure_skip_verify: + type: boolean + x-go-name: SSLInsecureSkipVerify + ssl_min_version: + format: uint16 + type: integer + x-go-name: SSLMinVersion + type: object + x-go-name: Transport + type: object + x-go-name: Proxy + response_processors: + items: + $ref: '#/components/schemas/ResponseProcessor' + type: array + x-go-name: ResponseProcessors + session_lifetime: + format: int64 + type: integer + x-go-name: SessionLifetime + session_provider: + $ref: '#/components/schemas/SessionProviderMeta' + slug: + type: string + x-go-name: Slug + strip_auth_data: + type: boolean + x-go-name: StripAuthData + tag_headers: + items: + type: string + type: array + x-go-name: TagHeaders + upstream_certificates: + additionalProperties: + type: string + type: object + x-go-name: UpstreamCertificates + uptime_tests: + properties: + check_list: + items: + $ref: '#/components/schemas/HostCheckObject' + type: array + x-go-name: CheckList + config: + properties: + expire_utime_after: + format: int64 + type: integer + x-go-name: ExpireUptimeAnalyticsAfter + recheck_wait: + format: int64 + type: integer + x-go-name: RecheckWait + service_discovery: + $ref: '#/components/schemas/ServiceDiscoveryConfiguration' + type: object + x-go-name: Config + type: object + x-go-name: UptimeTests + use_basic_auth: + type: boolean + x-go-name: UseBasicAuth + use_keyless: + type: boolean + x-go-name: UseKeylessAccess + use_mutual_tls_auth: + type: boolean + x-go-name: UseMutualTLSAuth + use_oauth2: + type: boolean + x-go-name: UseOauth2 + use_openid: + type: boolean + x-go-name: UseOpenID + use_standard_auth: + type: boolean + x-go-name: UseStandardAuth + version_data: + properties: + default_version: + type: string + x-go-name: DefaultVersion + not_versioned: + type: boolean + x-go-name: NotVersioned + versions: + additionalProperties: + $ref: '#/components/schemas/VersionInfo' + type: object + x-go-name: Versions + type: object + x-go-name: VersionData + title: >- + APIDefinition represents the configuration for a single proxied API and + it's versions. + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + APILimit: + description: APILimit stores quota and rate limit on ACL level (per API) + properties: + per: + format: double + type: number + x-go-name: Per + quota_max: + format: int64 + type: integer + x-go-name: QuotaMax + quota_remaining: + format: int64 + type: integer + x-go-name: QuotaRemaining + quota_renewal_rate: + format: int64 + type: integer + x-go-name: QuotaRenewalRate + quota_renews: + format: int64 + type: integer + x-go-name: QuotaRenews + rate: + format: double + type: number + x-go-name: Rate + set_by_policy: + type: boolean + x-go-name: SetByPolicy + throttle_interval: + format: double + type: number + x-go-name: ThrottleInterval + throttle_retry_limit: + format: int64 + type: integer + x-go-name: ThrottleRetryLimit + type: object + x-go-package: github.com/TykTechnologies/tyk/user + AccessDefinition: + description: AccessDefinition defines which versions of an API a key has access to + properties: + allowed_urls: + items: + $ref: '#/components/schemas/AccessSpec' + type: array + x-go-name: AllowedURLs + api_id: + type: string + x-go-name: APIID + api_name: + type: string + x-go-name: APIName + limit: + $ref: '#/components/schemas/APILimit' + versions: + items: + type: string + type: array + x-go-name: Versions + type: object + x-go-package: github.com/TykTechnologies/tyk/user + AccessRequestType: + description: AccessRequestType is the type for OAuth param `grant_type` + type: string + x-go-package: github.com/TykTechnologies/tyk/vendor/github.com/lonelycode/osin + AccessSpec: + description: >- + AccessSpecs define what URLS a user has access to an what methods are + enabled + properties: + methods: + items: + type: string + type: array + x-go-name: Methods + url: + type: string + x-go-name: URL + type: object + x-go-package: github.com/TykTechnologies/tyk/user + Auth: + properties: + auth_header_name: + type: string + x-go-name: AuthHeaderName + cookie_name: + type: string + x-go-name: CookieName + param_name: + type: string + x-go-name: ParamName + use_certificate: + type: boolean + x-go-name: UseCertificate + use_cookie: + type: boolean + x-go-name: UseCookie + use_param: + type: boolean + x-go-name: UseParam + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + AuthProviderCode: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + AuthProviderMeta: + properties: + meta: + additionalProperties: + type: object + type: object + x-go-name: Meta + name: + $ref: '#/components/schemas/AuthProviderCode' + storage_engine: + $ref: '#/components/schemas/StorageEngineCode' + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + AuthTypeEnum: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + AuthorizeRequestType: + description: AuthorizeRequestType is the type for OAuth param `response_type` + type: string + x-go-package: github.com/TykTechnologies/tyk/vendor/github.com/lonelycode/osin + CacheOptions: + properties: + cache_all_safe_requests: + type: boolean + x-go-name: CacheAllSafeRequests + cache_control_ttl_header: + type: string + x-go-name: CacheControlTTLHeader + cache_response_codes: + items: + format: int64 + type: integer + type: array + x-go-name: CacheOnlyResponseCodes + cache_timeout: + format: int64 + type: integer + x-go-name: CacheTimeout + enable_cache: + type: boolean + x-go-name: EnableCache + enable_upstream_cache_control: + type: boolean + x-go-name: EnableUpstreamCacheControl + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + CircuitBreakerMeta: + properties: + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + return_to_service_after: + format: int64 + type: integer + x-go-name: ReturnToServiceAfter + samples: + format: int64 + type: integer + x-go-name: Samples + threshold_percent: + format: double + type: number + x-go-name: ThresholdPercent + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + EndPointMeta: + properties: + method_actions: + additionalProperties: + $ref: '#/components/schemas/EndpointMethodMeta' + type: object + x-go-name: MethodActions + path: + type: string + x-go-name: Path + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + EndpointMethodAction: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + EndpointMethodMeta: + properties: + action: + $ref: '#/components/schemas/EndpointMethodAction' + code: + format: int64 + type: integer + x-go-name: Code + data: + type: string + x-go-name: Data + headers: + additionalProperties: + type: string + type: object + x-go-name: Headers + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + EventHandlerMetaConfig: + properties: + events: + x-go-name: Events + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + ExtendedPathsSet: + properties: + black_list: + items: + $ref: '#/components/schemas/EndPointMeta' + type: array + x-go-name: BlackList + cache: + items: + type: string + type: array + x-go-name: Cached + circuit_breakers: + items: + $ref: '#/components/schemas/CircuitBreakerMeta' + type: array + x-go-name: CircuitBreaker + do_not_track_endpoints: + items: + $ref: '#/components/schemas/TrackEndpointMeta' + type: array + x-go-name: DoNotTrackEndpoints + hard_timeouts: + items: + $ref: '#/components/schemas/HardTimeoutMeta' + type: array + x-go-name: HardTimeouts + ignored: + items: + $ref: '#/components/schemas/EndPointMeta' + type: array + x-go-name: Ignored + internal: + items: + $ref: '#/components/schemas/InternalMeta' + type: array + x-go-name: Internal + method_transforms: + items: + $ref: '#/components/schemas/MethodTransformMeta' + type: array + x-go-name: MethodTransforms + size_limits: + items: + $ref: '#/components/schemas/RequestSizeMeta' + type: array + x-go-name: SizeLimit + track_endpoints: + items: + $ref: '#/components/schemas/TrackEndpointMeta' + type: array + x-go-name: TrackEndpoints + transform: + items: + $ref: '#/components/schemas/TemplateMeta' + type: array + x-go-name: Transform + transform_headers: + items: + $ref: '#/components/schemas/HeaderInjectionMeta' + type: array + x-go-name: TransformHeader + transform_jq: + items: + $ref: '#/components/schemas/TransformJQMeta' + type: array + x-go-name: TransformJQ + transform_jq_response: + items: + $ref: '#/components/schemas/TransformJQMeta' + type: array + x-go-name: TransformJQResponse + transform_response: + items: + $ref: '#/components/schemas/TemplateMeta' + type: array + x-go-name: TransformResponse + transform_response_headers: + items: + $ref: '#/components/schemas/HeaderInjectionMeta' + type: array + x-go-name: TransformResponseHeader + url_rewrites: + items: + $ref: '#/components/schemas/URLRewriteMeta' + type: array + x-go-name: URLRewrite + validate_json: + items: + $ref: '#/components/schemas/ValidatePathMeta' + type: array + x-go-name: ValidateJSON + virtual: + items: + $ref: '#/components/schemas/VirtualMeta' + type: array + x-go-name: Virtual + white_list: + items: + $ref: '#/components/schemas/EndPointMeta' + type: array + x-go-name: WhiteList + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + GlobalRateLimit: + properties: + per: + format: double + type: number + x-go-name: Per + rate: + format: double + type: number + x-go-name: Rate + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + HardTimeoutMeta: + properties: + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + timeout: + format: int64 + type: integer + x-go-name: TimeOut + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + HashType: + type: string + x-go-package: github.com/TykTechnologies/tyk/user + HeaderInjectionMeta: + properties: + act_on: + type: boolean + x-go-name: ActOnResponse + add_headers: + additionalProperties: + type: string + type: object + x-go-name: AddHeaders + delete_headers: + items: + type: string + type: array + x-go-name: DeleteHeaders + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + HostCheckObject: + properties: + body: + type: string + x-go-name: Body + headers: + additionalProperties: + type: string + type: object + x-go-name: Headers + method: + type: string + x-go-name: Method + url: + type: string + x-go-name: CheckURL + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + IdExtractorSource: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + IdExtractorType: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + InternalMeta: + properties: + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + MethodTransformMeta: + properties: + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + to_method: + type: string + x-go-name: ToMethod + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + MiddlewareDefinition: + properties: + name: + type: string + x-go-name: Name + path: + type: string + x-go-name: Path + require_session: + type: boolean + x-go-name: RequireSession + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + MiddlewareDriver: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + MiddlewareIdExtractor: + properties: + extract_from: + $ref: '#/components/schemas/IdExtractorSource' + extract_with: + $ref: '#/components/schemas/IdExtractorType' + extractor_config: + additionalProperties: + type: object + type: object + x-go-name: ExtractorConfig + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + MiddlewareSection: + properties: + auth_check: + $ref: '#/components/schemas/MiddlewareDefinition' + driver: + $ref: '#/components/schemas/MiddlewareDriver' + id_extractor: + $ref: '#/components/schemas/MiddlewareIdExtractor' + post: + items: + $ref: '#/components/schemas/MiddlewareDefinition' + type: array + x-go-name: Post + post_key_auth: + items: + $ref: '#/components/schemas/MiddlewareDefinition' + type: array + x-go-name: PostKeyAuth + pre: + items: + $ref: '#/components/schemas/MiddlewareDefinition' + type: array + x-go-name: Pre + response: + items: + $ref: '#/components/schemas/MiddlewareDefinition' + type: array + x-go-name: Response + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + NewClientRequest: + description: >- + NewClientRequest is an outward facing JSON object translated from osin + OAuthClients + properties: + api_id: + type: string + x-go-name: APIID + client_id: + type: string + x-go-name: ClientID + description: + type: string + x-go-name: Description + meta_data: + type: object + x-go-name: MetaData + policy_id: + type: string + x-go-name: PolicyID + redirect_uri: + type: string + x-go-name: ClientRedirectURI + secret: + type: string + x-go-name: ClientSecret + type: object + x-go-package: github.com/TykTechnologies/tyk + NotificationsManager: + description: 'TODO: Make this more generic' + properties: + oauth_on_keychange_url: + type: string + x-go-name: OAuthKeyChangeURL + shared_secret: + type: string + x-go-name: SharedSecret + title: >- + NotificationsManager handles sending notifications to OAuth endpoints to + notify the provider of key changes. + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + OIDProviderConfig: + properties: + client_ids: + additionalProperties: + type: string + type: object + x-go-name: ClientIDs + issuer: + type: string + x-go-name: Issuer + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + ObjectId: + description: 'http://www.mongodb.org/display/DOCS/Object+IDs' + title: >- + ObjectId is a unique ID identifying a BSON value. It must be exactly 12 + bytes + + long. MongoDB objects by default have such a property set in their "_id" + + property. + type: string + x-go-package: github.com/TykTechnologies/tyk/vendor/gopkg.in/mgo.v2/bson + OpenIDOptions: + properties: + providers: + items: + $ref: '#/components/schemas/OIDProviderConfig' + type: array + x-go-name: Providers + segregate_by_client: + type: boolean + x-go-name: SegregateByClient + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + Regexp: + description: Regexp is a wrapper around regexp.Regexp but with caching + properties: + FromCache: + type: boolean + type: object + x-go-package: github.com/TykTechnologies/tyk/regexp + RequestInputType: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + RequestSizeMeta: + properties: + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + size_limit: + format: int64 + type: integer + x-go-name: SizeLimit + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + ResponseProcessor: + properties: + name: + type: string + x-go-name: Name + options: + type: object + x-go-name: Options + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + RoutingTrigger: + properties: + 'on': + $ref: '#/components/schemas/RoutingTriggerOnType' + options: + $ref: '#/components/schemas/RoutingTriggerOptions' + rewrite_to: + type: string + x-go-name: RewriteTo + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + RoutingTriggerOnType: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + RoutingTriggerOptions: + properties: + header_matches: + additionalProperties: + $ref: '#/components/schemas/StringRegexMap' + type: object + x-go-name: HeaderMatches + path_part_matches: + additionalProperties: + $ref: '#/components/schemas/StringRegexMap' + type: object + x-go-name: PathPartMatches + payload_matches: + $ref: '#/components/schemas/StringRegexMap' + query_val_matches: + additionalProperties: + $ref: '#/components/schemas/StringRegexMap' + type: object + x-go-name: QueryValMatches + request_context_matches: + additionalProperties: + $ref: '#/components/schemas/StringRegexMap' + type: object + x-go-name: RequestContextMatches + session_meta_matches: + additionalProperties: + $ref: '#/components/schemas/StringRegexMap' + type: object + x-go-name: SessionMetaMatches + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + ServiceDiscoveryConfiguration: + properties: + cache_timeout: + format: int64 + type: integer + x-go-name: CacheTimeout + data_path: + type: string + x-go-name: DataPath + endpoint_returns_list: + type: boolean + x-go-name: EndpointReturnsList + parent_data_path: + type: string + x-go-name: ParentDataPath + port_data_path: + type: string + x-go-name: PortDataPath + query_endpoint: + type: string + x-go-name: QueryEndpoint + target_path: + type: string + x-go-name: TargetPath + use_discovery_service: + type: boolean + x-go-name: UseDiscoveryService + use_nested_query: + type: boolean + x-go-name: UseNestedQuery + use_target_list: + type: boolean + x-go-name: UseTargetList + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + SessionProviderCode: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + SessionProviderMeta: + properties: + meta: + additionalProperties: + type: object + type: object + x-go-name: Meta + name: + $ref: '#/components/schemas/SessionProviderCode' + storage_engine: + $ref: '#/components/schemas/StorageEngineCode' + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + SessionState: + description: >- + There's a data structure that's based on this and it's used for Protocol + Buffer support, make sure to update + "coprocess/proto/coprocess_session_state.proto" and generate the + bindings using: cd coprocess/proto && ./update_bindings.sh + properties: + tags: + items: + type: string + type: array + x-go-name: Tags + access_rights: + additionalProperties: + $ref: '#/components/schemas/AccessDefinition' + type: object + x-go-name: AccessRights + alias: + type: string + x-go-name: Alias + allowance: + format: double + type: number + x-go-name: Allowance + apply_policies: + items: + type: string + type: array + x-go-name: ApplyPolicies + apply_policy_id: + type: string + x-go-name: ApplyPolicyID + basic_auth_data: + properties: + hash_type: + $ref: '#/components/schemas/HashType' + password: + type: string + x-go-name: Password + type: object + x-go-name: BasicAuthData + certificate: + type: string + x-go-name: Certificate + data_expires: + format: int64 + type: integer + x-go-name: DataExpires + enable_detail_recording: + type: boolean + x-go-name: EnableDetailedRecording + expires: + format: int64 + type: integer + x-go-name: Expires + hmac_enabled: + type: boolean + x-go-name: HMACEnabled + hmac_string: + type: string + x-go-name: HmacSecret + id_extractor_deadline: + format: int64 + type: integer + x-go-name: IdExtractorDeadline + is_inactive: + type: boolean + x-go-name: IsInactive + jwt_data: + properties: + secret: + type: string + x-go-name: Secret + type: object + x-go-name: JWTData + last_check: + format: int64 + type: integer + x-go-name: LastCheck + last_updated: + type: string + x-go-name: LastUpdated + meta_data: + additionalProperties: + type: object + type: object + x-go-name: MetaData + monitor: + properties: + trigger_limits: + items: + format: double + type: number + type: array + x-go-name: TriggerLimits + type: object + x-go-name: Monitor + oauth_client_id: + type: string + x-go-name: OauthClientID + oauth_keys: + additionalProperties: + type: string + type: object + x-go-name: OauthKeys + org_id: + type: string + x-go-name: OrgID + per: + format: double + type: number + x-go-name: Per + quota_max: + format: int64 + type: integer + x-go-name: QuotaMax + quota_remaining: + format: int64 + type: integer + x-go-name: QuotaRemaining + quota_renewal_rate: + format: int64 + type: integer + x-go-name: QuotaRenewalRate + quota_renews: + format: int64 + type: integer + x-go-name: QuotaRenews + rate: + format: double + type: number + x-go-name: Rate + session_lifetime: + format: int64 + type: integer + x-go-name: SessionLifetime + throttle_interval: + format: double + type: number + x-go-name: ThrottleInterval + throttle_retry_limit: + format: int64 + type: integer + x-go-name: ThrottleRetryLimit + title: >- + SessionState objects represent a current API session, mainly used for + rate limiting. + type: object + x-go-package: github.com/TykTechnologies/tyk/user + StorageEngineCode: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + StringRegexMap: + properties: + match_rx: + type: string + x-go-name: MatchPattern + reverse: + type: boolean + x-go-name: Reverse + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + TemplateData: + properties: + enable_session: + type: boolean + x-go-name: EnableSession + input_type: + $ref: '#/components/schemas/RequestInputType' + template_mode: + $ref: '#/components/schemas/TemplateMode' + template_source: + type: string + x-go-name: TemplateSource + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + TemplateMeta: + properties: + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + template_data: + $ref: '#/components/schemas/TemplateData' + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + TemplateMode: + type: string + x-go-package: github.com/TykTechnologies/tyk/apidef + TrackEndpointMeta: + properties: + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + TransformJQMeta: + properties: + filter: + type: string + x-go-name: Filter + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + URLRewriteMeta: + properties: + MatchRegexp: + $ref: '#/components/schemas/Regexp' + match_pattern: + type: string + x-go-name: MatchPattern + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + rewrite_to: + type: string + x-go-name: RewriteTo + triggers: + items: + $ref: '#/components/schemas/RoutingTrigger' + type: array + x-go-name: Triggers + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + ValidatePathMeta: + properties: + error_response_code: + description: >- + Allows override of default 422 Unprocessible Entity response code + for validation errors. + format: int64 + type: integer + x-go-name: ErrorResponseCode + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + schema: + additionalProperties: + type: object + type: object + x-go-name: Schema + schema_b64: + type: string + x-go-name: SchemaB64 + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + VersionInfo: + properties: + paths: + properties: + black_list: + items: + type: string + type: array + x-go-name: BlackList + ignored: + items: + type: string + type: array + x-go-name: Ignored + white_list: + items: + type: string + type: array + x-go-name: WhiteList + type: object + x-go-name: Paths + expires: + type: string + x-go-name: Expires + extended_paths: + $ref: '#/components/schemas/ExtendedPathsSet' + global_headers: + additionalProperties: + type: string + type: object + x-go-name: GlobalHeaders + global_headers_remove: + items: + type: string + type: array + x-go-name: GlobalHeadersRemove + global_size_limit: + format: int64 + type: integer + x-go-name: GlobalSizeLimit + name: + type: string + x-go-name: Name + override_target: + type: string + x-go-name: OverrideTarget + use_extended_paths: + type: boolean + x-go-name: UseExtendedPaths + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + VirtualMeta: + properties: + function_source_type: + type: string + x-go-name: FunctionSourceType + function_source_uri: + type: string + x-go-name: FunctionSourceURI + method: + type: string + x-go-name: Method + path: + type: string + x-go-name: Path + proxy_on_error: + type: boolean + x-go-name: ProxyOnError + response_function_name: + type: string + x-go-name: ResponseFunctionName + use_session: + type: boolean + x-go-name: UseSession + type: object + x-go-package: github.com/TykTechnologies/tyk/apidef + apiModifyKeySuccess: + description: apiModifyKeySuccess represents when a Key modification was successful + properties: + action: + type: string + x-go-name: Action + key: + description: 'in:body' + type: string + x-go-name: Key + key_hash: + type: string + x-go-name: KeyHash + status: + type: string + x-go-name: Status + type: object + x-go-package: github.com/TykTechnologies/tyk + apiStatusMessage: + description: apiStatusMessage represents an API status message + properties: + message: + description: Response details + type: string + x-go-name: Message + status: + type: string + x-go-name: Status + type: object + x-go-package: github.com/TykTechnologies/tyk + securitySchemes: + api_key: + in: header + name: X-Tyk-Authorization + type: apiKey +security: + - api_key: [] + diff --git a/utils/ci-swagger.sh b/utils/ci-swagger.sh new file mode 100755 index 000000000000..4fd17b1c97fc --- /dev/null +++ b/utils/ci-swagger.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +swagger2fileName="swagger2.yaml" +openAPIspecfileName="gateway-swagger.yaml" + +fatal() { + echo "$@" >&2 + exit 1 +} + +swagger generate spec -o "$swagger2fileName" + +if [ $? -ne 0 ]; then + fatal "could not generate swagger2.0 spec to the specified path, $swagger2fileName" +fi + +swagger validate "$swagger2fileName" + +if [ $? -ne 0 ]; then + fatal "swagger spec is invalid... swagger spec is located at $swagger2fileName" +fi + +api-spec-converter --from=swagger_2 --to=openapi_3 --syntax=yaml "$swagger2fileName" > "$openAPIspecfileName" + +if [ $? -ne 0 ]; then + fatal "could not convert swagger2.0 spec to opeenapi 3.0" +fi + +## clean up +rm "$swagger2fileName" + +## Ideally, CI should push $openAPIspecfileName to GitHub +## but for now, it can be committed by users and pushed alonside their changes. From b271b1a7ba2af9e3abe17cc83a840189e95f56f9 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Tue, 19 Feb 2019 22:13:19 +0100 Subject: [PATCH 13/15] HTTPS before HTTP --- api.go | 2 +- gateway-swagger.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index 7f7656250368..4d41ee7d242e 100644 --- a/api.go +++ b/api.go @@ -3,7 +3,7 @@ // The code below describes the Tyk Gateway API // Version: 2.8.0 // -// Schemes: http, https +// Schemes: https, http // Host: localhost // BasePath: /tyk/ // diff --git a/gateway-swagger.yaml b/gateway-swagger.yaml index f5b3c3477fd8..c97b570e75b1 100644 --- a/gateway-swagger.yaml +++ b/gateway-swagger.yaml @@ -4,8 +4,8 @@ info: title: Tyk Gateway API version: 2.8.0 servers: - - url: 'http://localhost/tyk/' - url: 'https://localhost/tyk/' + - url: 'http://localhost/tyk/' paths: /apis: get: From 7e7ea2fe7a484e5cca3787445c15e2b5d4257449 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Tue, 19 Feb 2019 22:28:15 +0100 Subject: [PATCH 14/15] upgrade npm to prevent ssl errors use latest nodejs to try to solve CERT_UNTRUSTED errors --- .travis.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 293c937b078d..35ad5dd41610 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,10 +15,6 @@ addons: - python3.5 - python3-pip - libluajit-5.1-dev - ### Needed to convert the swagger 2.0 file to openapi 3.0 - ### The swagger docs are actually written as per the 2.0 spec as there is no - ### support for openapi 3.0 in Go - at least for now. - - npm matrix: include: @@ -40,7 +36,13 @@ install: script: - sudo pip3 install google - sudo pip3 install protobuf - - sudo npm install -g api-spec-converter + ### Needed to convert the swagger 2.0 file to openapi 3.0 + ### The swagger docs are actually written as per the 2.0 spec as there is no + ### support for openapi 3.0 in Go - at least for now. + ### https://github.com/nodesource/distributions/blob/master/README.md#debinstall + - curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash - + - sudo -E apt-get -yq --no-install-suggests --no-install-recommends $(travis_apt_get_options) install nodejs + - sudo npm install -g api-spec-converter --unsafe-perm=true --allow-root - go build -tags 'coprocess python' - go build -tags 'coprocess lua' - go build -tags 'coprocess grpc' From d9ffca69b4ca31c9783f9422999a9296e1f0044b Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Wed, 20 Feb 2019 10:51:00 +0100 Subject: [PATCH 15/15] add script to generate and update openapi3.0 docs --- utils/ci-swagger.sh | 35 ++++++-------------------------- utils/generate-swagger.sh | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 29 deletions(-) create mode 100755 utils/generate-swagger.sh diff --git a/utils/ci-swagger.sh b/utils/ci-swagger.sh index 4fd17b1c97fc..84b9f10d68dc 100755 --- a/utils/ci-swagger.sh +++ b/utils/ci-swagger.sh @@ -1,33 +1,10 @@ #!/bin/bash -swagger2fileName="swagger2.yaml" -openAPIspecfileName="gateway-swagger.yaml" - -fatal() { - echo "$@" >&2 - exit 1 -} - -swagger generate spec -o "$swagger2fileName" - -if [ $? -ne 0 ]; then - fatal "could not generate swagger2.0 spec to the specified path, $swagger2fileName" -fi - -swagger validate "$swagger2fileName" - -if [ $? -ne 0 ]; then - fatal "swagger spec is invalid... swagger spec is located at $swagger2fileName" -fi - -api-spec-converter --from=swagger_2 --to=openapi_3 --syntax=yaml "$swagger2fileName" > "$openAPIspecfileName" - -if [ $? -ne 0 ]; then - fatal "could not convert swagger2.0 spec to opeenapi 3.0" -fi - -## clean up -rm "$swagger2fileName" +ciUtilsDirectory=$(dirname "$0") +source "$ciUtilsDirectory/generate-swagger.sh" ## Ideally, CI should push $openAPIspecfileName to GitHub -## but for now, it can be committed by users and pushed alonside their changes. +## but for now, `generate-swagger.sh` can be run by users locally and committed +## then pushed alonside their changes. +rm "$openAPIspecfileName" + diff --git a/utils/generate-swagger.sh b/utils/generate-swagger.sh new file mode 100755 index 000000000000..d3cea48520d4 --- /dev/null +++ b/utils/generate-swagger.sh @@ -0,0 +1,42 @@ +#!/bin/bash + + +swagger2fileName="swagger2.yaml" +openAPIspecfileName="gateway-swagger.yaml" + +fatal() { + echo "$@" >&2 + exit 1 +} + +mustExists() { + hash $1 > /dev/null 2>&1 + if [ $? -ne 0 ]; then + fatal "command not found: $1. Run $2" + fi +} + +mustExists "swagger" "go get github.com/go-swagger/go-swagger/cmd/swagger" +mustExists "api-spec-converter" "npm install -g api-spec-converter" + +swagger generate spec -o "$swagger2fileName" + +if [ $? -ne 0 ]; then + fatal "could not generate swagger2.0 spec to the specified path, $swagger2fileName" +fi + +swagger validate "$swagger2fileName" + +if [ $? -ne 0 ]; then + fatal "swagger spec is invalid... swagger spec is located at $swagger2fileName" +fi + +api-spec-converter --from=swagger_2 --to=openapi_3 --syntax=yaml "$swagger2fileName" > "$openAPIspecfileName" + +if [ $? -ne 0 ]; then + fatal "could not convert swagger2.0 spec to opeenapi 3.0" +fi + +## clean up +rm "$swagger2fileName" +