Skip to content

Commit 351d688

Browse files
committed
Adds Demo for Nested Resources
1 parent 7eb3975 commit 351d688

File tree

9 files changed

+304
-10
lines changed

9 files changed

+304
-10
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Api::V1
2+
class MyUsers::PetsController < ApiController
3+
swagger_controller :pets, "My User Management"
4+
5+
swagger_api :index do
6+
summary "Fetches all User items"
7+
notes "This lists all the active users"
8+
end
9+
10+
# GET /v1/users
11+
def index
12+
render json: User.all
13+
end
14+
end
15+
end
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
class Api::V1::MyUsers::UsersController < ApiController
1+
module Api::V1
2+
class MyUsers::UsersController < ApiController
23

3-
swagger_controller :my_users_users, "My User Management"
4+
swagger_controller :my_users_users, "My User Management"
45

5-
swagger_api :index do
6-
summary "Fetches all User items"
7-
notes "This lists all the active users"
8-
end
6+
swagger_api :index do
7+
summary "Fetches all User items"
8+
notes "This lists all the active users"
9+
end
910

10-
# GET /v1/users
11-
def index
12-
render json: User.all
11+
# GET /v1/users
12+
def index
13+
render json: User.all
14+
end
1315
end
1416
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Api::V1
2+
class ProductsController < ApiController
3+
swagger_controller :products, "Products Management"
4+
5+
swagger_api :index do
6+
summary "Fetches all User items"
7+
notes "This lists all the active users"
8+
end
9+
10+
def index
11+
render json: User.all
12+
end
13+
end
14+
end

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class ApplicationController < ActionController::API
22
include ActionController::Serialization
33
include ActionController::HttpAuthentication::Token::ControllerMethods
44

5-
# before_action :authenticate, except: [:index_public]
5+
before_action :authenticate, except: [:index_public]
66
before_filter :throttle_token
77

88
protected

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
namespace :v1 do
1616
namespace :my_users do
1717
resources :users
18+
resources :pets
1819
end
20+
resources :products
1921
resources :users
2022
end
2123
end

public/apidocs/api-docs.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
"swaggerVersion": "1.2",
44
"basePath": "http://127.0.0.1:3000",
55
"apis": [
6+
{
7+
"path": "/apidocs/api/v1/my_users/users.{format}",
8+
"description": "My User Management"
9+
},
10+
{
11+
"path": "/apidocs/api/v1/my_users/pets.{format}",
12+
"description": "My User Management"
13+
},
14+
{
15+
"path": "/apidocs/api/v1/products.{format}",
16+
"description": "Products Management"
17+
},
618
{
719
"path": "/apidocs/api/v1/users.{format}",
820
"description": "User Management"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"apiVersion": "1.0",
3+
"swaggerVersion": "1.2",
4+
"basePath": "http://127.0.0.1:3000",
5+
"resourcePath": "pets",
6+
"apis": [
7+
{
8+
"path": "/v1/my_users/pets",
9+
"operations": [
10+
{
11+
"parameters": [
12+
{
13+
"paramType": "header",
14+
"name": "Authorization",
15+
"type": "string",
16+
"description": "Authentication token",
17+
"required": true
18+
}
19+
],
20+
"summary": "Fetches all User items",
21+
"notes": "This lists all the active users",
22+
"nickname": "Api::V1::MyUsers::Pets#index",
23+
"method": "get"
24+
}
25+
]
26+
},
27+
{
28+
"path": "/v1/my_users/pets",
29+
"operations": [
30+
{
31+
"parameters": [
32+
{
33+
"paramType": "header",
34+
"name": "Authorization",
35+
"type": "string",
36+
"description": "Authentication token",
37+
"required": true
38+
}
39+
],
40+
"nickname": "Api::V1::MyUsers::Pets#create",
41+
"method": "post"
42+
}
43+
]
44+
},
45+
{
46+
"path": "/v1/my_users/pets/{id}",
47+
"operations": [
48+
{
49+
"parameters": [
50+
{
51+
"paramType": "header",
52+
"name": "Authorization",
53+
"type": "string",
54+
"description": "Authentication token",
55+
"required": true
56+
}
57+
],
58+
"nickname": "Api::V1::MyUsers::Pets#show",
59+
"method": "get"
60+
}
61+
]
62+
},
63+
{
64+
"path": "/v1/my_users/pets/{id}",
65+
"operations": [
66+
{
67+
"parameters": [
68+
{
69+
"paramType": "header",
70+
"name": "Authorization",
71+
"type": "string",
72+
"description": "Authentication token",
73+
"required": true
74+
}
75+
],
76+
"nickname": "Api::V1::MyUsers::Pets#update",
77+
"method": "patch"
78+
}
79+
]
80+
}
81+
],
82+
"authorizations": null
83+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"apiVersion": "1.0",
3+
"swaggerVersion": "1.2",
4+
"basePath": "http://127.0.0.1:3000",
5+
"resourcePath": "tetsusers",
6+
"apis": [
7+
{
8+
"path": "/v1/my_users/users",
9+
"operations": [
10+
{
11+
"parameters": [
12+
{
13+
"paramType": "header",
14+
"name": "Authorization",
15+
"type": "string",
16+
"description": "Authentication token",
17+
"required": true
18+
}
19+
],
20+
"summary": "Fetches all User items",
21+
"notes": "This lists all the active users",
22+
"nickname": "Api::V1::MyUsers::Users#index",
23+
"method": "get"
24+
}
25+
]
26+
},
27+
{
28+
"path": "/v1/my_users/users",
29+
"operations": [
30+
{
31+
"parameters": [
32+
{
33+
"paramType": "header",
34+
"name": "Authorization",
35+
"type": "string",
36+
"description": "Authentication token",
37+
"required": true
38+
}
39+
],
40+
"nickname": "Api::V1::MyUsers::Users#create",
41+
"method": "post"
42+
}
43+
]
44+
},
45+
{
46+
"path": "/v1/my_users/users/{id}",
47+
"operations": [
48+
{
49+
"parameters": [
50+
{
51+
"paramType": "header",
52+
"name": "Authorization",
53+
"type": "string",
54+
"description": "Authentication token",
55+
"required": true
56+
}
57+
],
58+
"nickname": "Api::V1::MyUsers::Users#show",
59+
"method": "get"
60+
}
61+
]
62+
},
63+
{
64+
"path": "/v1/my_users/users/{id}",
65+
"operations": [
66+
{
67+
"parameters": [
68+
{
69+
"paramType": "header",
70+
"name": "Authorization",
71+
"type": "string",
72+
"description": "Authentication token",
73+
"required": true
74+
}
75+
],
76+
"nickname": "Api::V1::MyUsers::Users#update",
77+
"method": "patch"
78+
}
79+
]
80+
}
81+
],
82+
"authorizations": null
83+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"apiVersion": "1.0",
3+
"swaggerVersion": "1.2",
4+
"basePath": "http://127.0.0.1:3000",
5+
"resourcePath": "products",
6+
"apis": [
7+
{
8+
"path": "/v1/products",
9+
"operations": [
10+
{
11+
"parameters": [
12+
{
13+
"paramType": "header",
14+
"name": "Authorization",
15+
"type": "string",
16+
"description": "Authentication token",
17+
"required": true
18+
}
19+
],
20+
"summary": "Fetches all User items",
21+
"notes": "This lists all the active users",
22+
"nickname": "Api::V1::Products#index",
23+
"method": "get"
24+
}
25+
]
26+
},
27+
{
28+
"path": "/v1/products",
29+
"operations": [
30+
{
31+
"parameters": [
32+
{
33+
"paramType": "header",
34+
"name": "Authorization",
35+
"type": "string",
36+
"description": "Authentication token",
37+
"required": true
38+
}
39+
],
40+
"nickname": "Api::V1::Products#create",
41+
"method": "post"
42+
}
43+
]
44+
},
45+
{
46+
"path": "/v1/products/{id}",
47+
"operations": [
48+
{
49+
"parameters": [
50+
{
51+
"paramType": "header",
52+
"name": "Authorization",
53+
"type": "string",
54+
"description": "Authentication token",
55+
"required": true
56+
}
57+
],
58+
"nickname": "Api::V1::Products#show",
59+
"method": "get"
60+
}
61+
]
62+
},
63+
{
64+
"path": "/v1/products/{id}",
65+
"operations": [
66+
{
67+
"parameters": [
68+
{
69+
"paramType": "header",
70+
"name": "Authorization",
71+
"type": "string",
72+
"description": "Authentication token",
73+
"required": true
74+
}
75+
],
76+
"nickname": "Api::V1::Products#update",
77+
"method": "patch"
78+
}
79+
]
80+
}
81+
],
82+
"authorizations": null
83+
}

0 commit comments

Comments
 (0)