@@ -3,7 +3,7 @@ defmodule PhoenixSwagger do
3
3
use Application
4
4
alias PhoenixSwagger.Path
5
5
alias PhoenixSwagger.Path.PathObject
6
- alias Helpers.MiscHelpers , as: Helpers
6
+ alias PhoenixSwagger.Helpers , as: Helpers
7
7
8
8
@ moduledoc """
9
9
The PhoenixSwagger module provides macros for defining swagger operations and schemas.
@@ -218,62 +218,50 @@ defmodule PhoenixSwagger do
218
218
|> add_module(SimpleWeb.UserSocket)
219
219
220
220
"""
221
- def add_module ( struct , module ) do
221
+ def add_module ( swagger_map , module ) do
222
222
functions = module . __info__ ( :functions )
223
223
224
- paths = get_paths ( functions , struct , module )
224
+ swagger_map
225
+ |> get_paths ( module , functions )
226
+ |> get_schemas ( module , functions )
227
+ end
225
228
229
+ defp get_schemas ( swagger_map , module , functions ) do
226
230
Enum . map ( functions , fn { action , _arg } -> build_schemas ( action , module ) end )
227
231
|> Enum . filter ( & ! is_nil ( & 1 ) )
228
- |> Enum . reduce ( swagger_map ( paths ) , & Helpers . merge_definitions / 2 )
232
+ |> Enum . reduce ( Helpers . swagger_map ( swagger_map ) , & Helpers . merge_definitions / 2 )
229
233
end
230
-
231
- def build_schemas ( function , module ) do
234
+ defp build_schemas ( function , module ) do
232
235
if is_schema? ( function ) , do: apply ( module , function , [ ] )
233
236
end
234
-
235
237
defp is_schema? ( function ) do
236
238
function
237
239
|> Atom . to_string
238
240
|> String . contains? ( "swagger_definitions" )
239
241
end
240
242
241
- defp get_paths ( functions , struct , module ) do
243
+ defp get_paths ( swagger_map , module , functions ) do
242
244
Enum . map ( functions , fn { action , _arg } -> build_path ( action , module ) end )
243
245
|> Enum . filter ( & ! is_nil ( & 1 ) )
244
- |> Enum . reduce ( swagger_map ( struct ) , & Helpers . merge_paths / 2 )
246
+ |> Enum . reduce ( Helpers . swagger_map ( swagger_map ) , & Helpers . merge_paths / 2 )
245
247
end
246
-
247
- def swagger_map ( swagger_map ) do
248
- Map . update ( swagger_map , :definitions , % { } , & ( & 1 ) )
249
- |> Map . update ( :paths , % { } , & ( & 1 ) )
250
- end
251
-
252
- defp build_path ( function , module ) do #room for improvement here for sure, comments?
253
- case is_path? ( function ) do
254
- { true , action } ->
255
- apply ( module , function , extract_args ( action ) )
256
- { false , _action } ->
257
- nil
248
+ defp build_path ( function , module ) do
249
+ if is_path? ( function ) do
250
+ action =
251
+ function
252
+ |> get_action
253
+ apply ( module , function , Helpers . extract_args ( action ) )
258
254
end
259
255
end
260
-
261
- defp is_path? ( function ) do #room for improvement here for sure, comments?
262
- funct_string =
263
- function
264
- |> Atom . to_string
265
-
266
- contains =
267
- funct_string
268
- |> String . contains? ( "swagger_path" )
269
-
270
- { contains , String . replace ( funct_string , "swagger_path_" , "" ) }
256
+ defp is_path? ( function ) do
257
+ function
258
+ |> Atom . to_string
259
+ |> String . contains? ( "swagger_path" )
271
260
end
272
-
273
- defp extract_args ( action ) do
274
- [
275
- % { verb: action |> String . to_atom , path: "" }
276
- ]
261
+ defp get_action ( function ) do
262
+ function
263
+ |> Atom . to_string
264
+ |> String . replace ( "swagger_path_" , "" )
277
265
end
278
266
279
267
@ doc false
0 commit comments