Class: Jdoc::Link::RequestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/jdoc/link.rb

Class Method Summary collapse

Class Method Details

.call(schema) ⇒ Hash

Note:

Not includes properties that have readOnly property

Generates example request body from given schema

Examples:

Jdoc::Link::RequestGenerator(schema) #=> { "name" => "example", "description" => "foo bar." }

Returns:

  • (Hash)


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/jdoc/link.rb', line 128

def self.call(schema)
  schema.properties.inject({}) do |result, (key, value)|
    if value.data["readOnly"]
      result
    else
      result.merge(
        key => case
        when !value.properties.empty?
          call(value)
        when !value.data["example"].nil?
          value.data["example"]
        when value.type.include?("null")
          nil
        else
          raise ExampleNotFound, "No example found for #{schema.pointer}/#{key}"
        end
      )
    end
  end
end