Class: SwaggerYard::ApiDeclaration
- Inherits:
-
Object
- Object
- SwaggerYard::ApiDeclaration
- Defined in:
- lib/swagger_yard/api_declaration.rb
Instance Attribute Summary collapse
-
#apis ⇒ Object
readonly
Returns the value of attribute apis.
-
#authorizations ⇒ Object
readonly
Returns the value of attribute authorizations.
-
#description ⇒ Object
Returns the value of attribute description.
-
#resource_path ⇒ Object
Returns the value of attribute resource_path.
Instance Method Summary collapse
- #add_api(yard_object) ⇒ Object
-
#add_authorizations_to_resource_listing(yard_object) ⇒ Object
HACK, requires knowledge of resource_listing.
- #add_listing_info(listing_info) ⇒ Object
- #add_yard_object(yard_object) ⇒ Object
- #add_yard_objects(yard_objects) ⇒ Object
-
#initialize(resource_listing) ⇒ ApiDeclaration
constructor
A new instance of ApiDeclaration.
- #listing_hash ⇒ Object
- #models ⇒ Object
- #ref?(name) ⇒ Boolean
- #resource_name ⇒ Object
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(resource_listing) ⇒ ApiDeclaration
Returns a new instance of ApiDeclaration.
6 7 8 9 10 11 |
# File 'lib/swagger_yard/api_declaration.rb', line 6 def initialize(resource_listing) @resource_listing = resource_listing @apis = {} @authorizations = {} end |
Instance Attribute Details
#apis ⇒ Object (readonly)
Returns the value of attribute apis.
4 5 6 |
# File 'lib/swagger_yard/api_declaration.rb', line 4 def apis @apis end |
#authorizations ⇒ Object (readonly)
Returns the value of attribute authorizations.
4 5 6 |
# File 'lib/swagger_yard/api_declaration.rb', line 4 def @authorizations end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/swagger_yard/api_declaration.rb', line 3 def description @description end |
#resource_path ⇒ Object
Returns the value of attribute resource_path.
3 4 5 |
# File 'lib/swagger_yard/api_declaration.rb', line 3 def resource_path @resource_path end |
Instance Method Details
#add_api(yard_object) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/swagger_yard/api_declaration.rb', line 42 def add_api(yard_object) path = Api.path_from_yard_object(yard_object) return if path.nil? api = (apis[path] ||= Api.from_yard_object(yard_object, self)) api.add_operation(yard_object) end |
#add_authorizations_to_resource_listing(yard_object) ⇒ Object
HACK, requires knowledge of resource_listing
52 53 54 55 56 |
# File 'lib/swagger_yard/api_declaration.rb', line 52 def (yard_object) yard_object..select {|t| t.tag_name == "authorization"}.each do |t| @resource_listing. << Authorization.from_yard_object(t) end end |
#add_listing_info(listing_info) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/swagger_yard/api_declaration.rb', line 34 def add_listing_info(listing_info) @description = listing_info.description @resource_path = listing_info.resource_path # we only have api_key auth, the value for now is always empty array @authorizations = Hash[listing_info..uniq.map {|k| [k, []]}] end |
#add_yard_object(yard_object) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/swagger_yard/api_declaration.rb', line 24 def add_yard_object(yard_object) case yard_object.type when :class add_listing_info(ListingInfo.new(yard_object)) (yard_object) when :method add_api(yard_object) end end |
#add_yard_objects(yard_objects) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/swagger_yard/api_declaration.rb', line 17 def add_yard_objects(yard_objects) yard_objects.each do |yard_object| add_yard_object(yard_object) end self end |
#listing_hash ⇒ Object
82 83 84 85 86 87 |
# File 'lib/swagger_yard/api_declaration.rb', line 82 def listing_hash { "path" => resource_path, "description" => description } end |
#models ⇒ Object
62 63 64 |
# File 'lib/swagger_yard/api_declaration.rb', line 62 def models (api_models + property_models).uniq end |
#ref?(name) ⇒ Boolean
66 67 68 |
# File 'lib/swagger_yard/api_declaration.rb', line 66 def ref?(name) @resource_listing.models.map(&:id).include?(name) end |
#resource_name ⇒ Object
58 59 60 |
# File 'lib/swagger_yard/api_declaration.rb', line 58 def resource_name @resource_path end |
#to_h ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/swagger_yard/api_declaration.rb', line 70 def to_h { "apiVersion" => SwaggerYard.config.api_version, "swaggerVersion" => SwaggerYard.config.swagger_version, "basePath" => SwaggerYard.config.api_base_path, "resourcePath" => resource_path, "apis" => apis.values.map(&:to_h), "models" => Hash[models.map {|m| [m.id, m.to_h]}], "authorizations" => } end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/swagger_yard/api_declaration.rb', line 13 def valid? !@resource_path.nil? end |