Class: Swagui::JsonSchema
- Inherits:
-
Object
- Object
- Swagui::JsonSchema
- Defined in:
- lib/swagui/json_schema.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #all_objects ⇒ Object
-
#initialize(schema_hash, name) ⇒ JsonSchema
constructor
A new instance of JsonSchema.
- #models ⇒ Object
- #properties ⇒ Object
Constructor Details
#initialize(schema_hash, name) ⇒ JsonSchema
Returns a new instance of JsonSchema.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/swagui/json_schema.rb', line 6 def initialize(schema_hash, name) @name = name @schema_hash = schema_hash @nested_objects = [] @schema_hash['properties'].each do |pname, pattributes| if pattributes['type'] == 'object' nested_object_name = "#{@name}-#{pname}" @schema_hash['properties'][pname] = {'$ref' => nested_object_name } @nested_objects << JsonSchema.new(pattributes, nested_object_name) end end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/swagui/json_schema.rb', line 4 def name @name end |
Instance Method Details
#all_objects ⇒ Object
33 34 35 |
# File 'lib/swagui/json_schema.rb', line 33 def all_objects ([self] + @nested_objects.map {|x| x.all_objects}).flatten end |
#models ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/swagui/json_schema.rb', line 24 def models all_objects.map do |schema| { 'id' => schema.name, 'properties' => schema.properties } end end |
#properties ⇒ Object
20 21 22 |
# File 'lib/swagui/json_schema.rb', line 20 def properties @schema_hash['properties'] end |