2018-04-26 22:55:39 +00:00
require 'swagger/blocks'
module WorkspaceApiDoc
include Swagger :: Blocks
2018-05-17 16:22:43 +00:00
NAME_DESC = 'The name of the workspace. This is the unique identifier for determining which workspace is being accessed.'
BOUNDARY_DESC = 'Comma separated list of IP ranges (in various formats) and IP addresses that users of this workspace are allowed to interact with if limit_to_network is true.'
2018-05-22 19:57:21 +00:00
BOUNDARY_EXAMPLE = '10.10.1.1-50,10.10.1.100,10.10.2.0/24'
2018-05-17 16:22:43 +00:00
DESCRIPTION_DESC = 'Long description that explains the purpose of this workspace.'
2018-05-22 19:57:21 +00:00
OWNER_ID_DESC = 'ID of the user who owns this workspace.'
2018-05-17 16:22:43 +00:00
LIMIT_TO_NETWORK_DESC = 'true to restrict the hosts and services in this workspace to the IP addresses listed in \'boundary\'.'
2018-05-22 19:57:21 +00:00
IMPORT_FINGERPRINT_DESC = 'Identifier that indicates if and where this workspace was imported from.'
2018-05-17 16:22:43 +00:00
2018-04-26 22:55:39 +00:00
# Swagger documentation for workspaces model
swagger_schema :Workspace do
2018-05-17 16:22:43 +00:00
key :required , [ :name ]
2018-05-22 19:57:21 +00:00
property :id , type : :integer , format : :int32 , description : RootApiDoc :: ID_DESC
2018-05-17 16:22:43 +00:00
property :name , type : :string , description : NAME_DESC
property :boundary , type : :string , description : BOUNDARY_DESC , example : BOUNDARY_EXAMPLE
property :description , type : :string , description : DESCRIPTION_DESC
2018-05-22 19:57:21 +00:00
property :owner_id , type : :integer , format : :int32 , description : OWNER_ID_DESC
2018-05-17 16:22:43 +00:00
property :limit_to_network , type : :boolean , description : LIMIT_TO_NETWORK_DESC
2018-05-22 19:57:21 +00:00
property :import_fingerprint , type : :boolean , description : IMPORT_FINGERPRINT_DESC
property :created_at , type : :string , format : :date_time , description : RootApiDoc :: CREATED_AT_DESC
property :updated_at , type : :string , format : :date_time , description : RootApiDoc :: UPDATED_AT_DESC
2018-04-26 22:55:39 +00:00
end
swagger_path '/api/v1/workspaces' do
2018-05-02 19:47:17 +00:00
# Swagger documentation for /api/v1/workspaces GET
2018-04-26 22:55:39 +00:00
operation :get do
key :description , 'Return workspaces that are stored in the database.'
2018-04-30 21:40:07 +00:00
key :tags , [ 'workspace' ]
2018-04-26 22:55:39 +00:00
response 200 do
2018-05-17 16:22:43 +00:00
key :description , 'Returns workspace data.'
2018-04-26 22:55:39 +00:00
schema do
2018-07-25 23:01:05 +00:00
property :data do
key :type , :array
items do
key :'$ref' , :Workspace
end
2018-04-26 22:55:39 +00:00
end
end
end
2018-07-26 02:46:33 +00:00
2018-08-14 18:35:59 +00:00
response 401 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 18:35:59 +00:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-26 02:46:33 +00:00
response 500 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-26 02:46:33 +00:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-26 22:55:39 +00:00
end
# Swagger documentation for /api/v1/workspaces POST
operation :post do
2018-05-17 16:22:43 +00:00
key :description , 'Create a workspace entry.'
2018-04-30 21:40:07 +00:00
key :tags , [ 'workspace' ]
2018-04-26 22:55:39 +00:00
parameter do
key :in , :body
key :name , :body
2018-05-17 16:22:43 +00:00
key :description , 'The attributes to assign to the workspace.'
2018-04-26 22:55:39 +00:00
key :required , true
schema do
2018-05-17 16:22:43 +00:00
property :name , type : :string , description : NAME_DESC
2018-04-26 22:55:39 +00:00
end
end
response 200 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_200
2018-04-26 22:55:39 +00:00
schema do
2018-07-25 23:01:05 +00:00
property :data do
key :'$ref' , :Workspace
end
2018-04-26 22:55:39 +00:00
end
end
2018-07-26 02:46:33 +00:00
2018-08-14 18:35:59 +00:00
response 401 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 18:35:59 +00:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-26 02:46:33 +00:00
response 500 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-26 02:46:33 +00:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-26 22:55:39 +00:00
end
# Swagger documentation for /api/v1/workspaces/ DELETE
operation :delete do
key :description , 'Delete the specified workspaces.'
2018-04-30 21:40:07 +00:00
key :tags , [ 'workspace' ]
2018-04-26 22:55:39 +00:00
parameter :delete_opts
response 200 do
2018-07-26 13:43:05 +00:00
key :description , 'Returns an array containing the successfully deleted workspaces.'
2018-04-26 22:55:39 +00:00
schema do
2018-07-25 23:01:05 +00:00
property :data do
key :type , :array
items do
key :'$ref' , :Workspace
end
2018-04-26 22:55:39 +00:00
end
end
end
2018-07-26 02:46:33 +00:00
2018-08-14 18:35:59 +00:00
response 401 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 18:35:59 +00:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-26 02:46:33 +00:00
response 500 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-26 02:46:33 +00:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-26 22:55:39 +00:00
end
end
2018-05-17 21:56:22 +00:00
swagger_path '/api/v1/workspaces/{id}' do
2018-05-02 19:47:17 +00:00
# Swagger documentation for api/v1/workspaces/:id GET
2018-04-26 22:55:39 +00:00
operation :get do
2018-05-17 21:56:22 +00:00
key :description , 'Return specific workspace that is stored in the database.'
2018-04-30 21:40:07 +00:00
key :tags , [ 'workspace' ]
2018-04-26 22:55:39 +00:00
parameter do
key :name , :id
key :in , :path
2018-05-17 21:56:22 +00:00
key :description , 'ID of workspace to retrieve.'
2018-04-26 22:55:39 +00:00
key :required , true
key :type , :integer
key :format , :int32
end
response 200 do
2018-05-17 21:56:22 +00:00
key :description , 'Returns workspace data.'
2018-04-26 22:55:39 +00:00
schema do
2018-07-25 23:01:05 +00:00
property :data do
2018-07-31 20:43:57 +00:00
key :'$ref' , :Workspace
2018-04-26 22:55:39 +00:00
end
end
end
2018-07-26 02:46:33 +00:00
2018-08-14 18:35:59 +00:00
response 401 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 18:35:59 +00:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-26 02:46:33 +00:00
response 500 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-26 02:46:33 +00:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-26 22:55:39 +00:00
end
# Swagger documentation for /api/v1/workspaces/:id PUT
operation :put do
key :description , 'Update the attributes an existing workspaces.'
2018-04-30 21:40:07 +00:00
key :tags , [ 'workspace' ]
2018-04-26 22:55:39 +00:00
parameter :update_id
parameter do
key :in , :body
key :name , :body
2018-05-17 16:22:43 +00:00
key :description , 'The updated attributes to overwrite to the workspace.'
2018-04-26 22:55:39 +00:00
key :required , true
schema do
key :'$ref' , :Workspace
end
end
response 200 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_200
2018-04-26 22:55:39 +00:00
schema do
2018-07-25 23:01:05 +00:00
property :data do
key :'$ref' , :Workspace
end
2018-04-26 22:55:39 +00:00
end
end
2018-07-26 02:46:33 +00:00
2018-08-14 18:35:59 +00:00
response 401 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_401
2018-08-14 18:35:59 +00:00
schema do
key :'$ref' , :AuthErrorModel
end
end
2018-07-26 02:46:33 +00:00
response 500 do
2018-08-15 20:26:35 +00:00
key :description , RootApiDoc :: DEFAULT_RESPONSE_500
2018-07-26 02:46:33 +00:00
schema do
key :'$ref' , :ErrorModel
end
end
2018-04-26 22:55:39 +00:00
end
end
2018-08-14 18:35:59 +00:00
end