Class: Jellyfish::Swagger

Inherits:
Object
  • Object
show all
Includes:
Jellyfish
Defined in:
lib/jellyfish/swagger.rb

Constant Summary

Constants included from Jellyfish

Cascade, GetValue, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Jellyfish

#call, #log, #log_error

Constructor Details

#initialize(path_prefix = '', *apps) ⇒ Swagger

Returns a new instance of Swagger.



63
64
65
66
67
# File 'lib/jellyfish/swagger.rb', line 63

def initialize path_prefix='', *apps
  super(apps.first)
  @jellys      = apps
  @path_prefix = path_prefix
end

Instance Attribute Details

#jellysObject (readonly)

Returns the value of attribute jellys.



62
63
64
# File 'lib/jellyfish/swagger.rb', line 62

def jellys
  @jellys
end

#path_prefixObject (readonly)

Returns the value of attribute path_prefix.



62
63
64
# File 'lib/jellyfish/swagger.rb', line 62

def path_prefix
  @path_prefix
end

Instance Method Details

#jellyfish_apisObject



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/jellyfish/swagger.rb', line 69

def jellyfish_apis
  @jellyfish_apis ||= jellys.flat_map{ |j|
    j.routes.flat_map{ |meth, routes|
      routes.map{ |(path, _, meta)|
        meta.merge(operation(meth, path, meta))
      }
    }
  }.group_by{ |api| api[:path] }.
    inject(Hash.new{[]}){ |r, (path, operations)|
      r[path] = operations.group_by{ |op| op[:nickname] }
      r
    }
end

#swagger_apisObject



56
57
58
59
60
# File 'lib/jellyfish/swagger.rb', line 56

def swagger_apis
  @swagger_apis ||= jellyfish_apis.keys.map do |name|
    {:path => name}
  end
end

#swagger_apiVersionObject

The application should define the API version.



48
49
50
51
52
53
54
# File 'lib/jellyfish/swagger.rb', line 48

def swagger_apiVersion
  if app.respond_to?(:swagger_apiVersion)
    app.swagger_apiVersion
  else
    '0.1.0'
  end
end

#swagger_infoObject

The application should define the API description.



39
40
41
42
43
44
45
# File 'lib/jellyfish/swagger.rb', line 39

def swagger_info
  if app.respond_to?(:info)
    app.info
  else
    {}
  end
end