class SwaggerYard::Property
Holds the name and type for a single model property
Constants
- NAME_OPTIONS_REGEXP
Attributes
description[RW]
name[R]
nullable[R]
required[R]
type[R]
Public Class Methods
from_method(yard_method)
click to toggle source
# File lib/swagger_yard/property.rb, line 22 def self.from_method(yard_method) return nil unless yard_method.explicit || yard_method.parameters.empty? tags = (yard_method.tags ||[]).dup prop_tag = tags.detect { |t| t.tag_name == 'property' } return nil unless prop_tag tags.reject { |t| t.tag_name == 'property' } from_tag(prop_tag).tap do |prop| ex = tags.detect { |t| t.tag_name == 'example' } prop.example = ex.text.empty? ? ex.name : ex.text if ex prop.description = yard_method.docstring unless prop.description end end
from_tag(tag)
click to toggle source
# File lib/swagger_yard/property.rb, line 35 def self.from_tag(tag) tag = SwaggerYard.requires_type(tag) return nil unless tag name = tag_name(tag) return nil unless name text = tag.text if (options_src = (tag.name || '')) =~ NAME_OPTIONS_REGEXP _, options_string = options_src.split(NAME_OPTIONS_REGEXP) elsif tag.name && tag.object.is_a?(YARD::CodeObjects::MethodObject) if text text = tag.name + ' ' + text else text = tag.name end end options = options_string.to_s.split(',').map(&:strip) new(name, tag.types, text, options) end
new(name, types, description, options)
click to toggle source
# File lib/swagger_yard/property.rb, line 59 def initialize(name, types, description, options) @name, @description = name, description @required = options.include?('required') @nullable = options.include?('nullable') @type = Type.from_type_list(types) end
tag_name(tag)
click to toggle source
# File lib/swagger_yard/property.rb, line 12 def self.tag_name(tag) if tag.object.is_a?(YARD::CodeObjects::MethodObject) tag.object.name.to_s else tag = SwaggerYard.requires_name(tag) return nil unless tag tag.name.split(NAME_OPTIONS_REGEXP).first end end
Public Instance Methods
required?()
click to toggle source
# File lib/swagger_yard/property.rb, line 66 def required? @required end