Class: Rack::JsonSchema::Mock::ResponseGenerator
- Inherits:
-
Object
- Object
- Rack::JsonSchema::Mock::ResponseGenerator
- Defined in:
- lib/rack/json_schema/mock.rb
Class Method Summary collapse
-
.call(schema) ⇒ Hash
Generates example response Hash from given schema.
Class Method Details
.call(schema) ⇒ Hash
Generates example response Hash from given schema
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rack/json_schema/mock.rb', line 61 def self.call(schema) schema.properties.inject({}) do |result, (key, value)| result.merge( key => case when !value.properties.empty? call(value) when !value.data["example"].nil? value.data["example"] when value.type.include?("null") nil when value.type.include?("array") [call(value.items)] else raise ExampleNotFound, "No example found for #{schema.pointer}/#{key}" end ) end end |