Method: Fdoc::EndpointPresenter#example_from_schema

Defined in:
lib/fdoc/presenters/endpoint_presenter.rb

#example_from_schema(schema) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fdoc/presenters/endpoint_presenter.rb', line 96

def example_from_schema(schema)
  if schema.nil?
    return nil
  end

  type = Array(schema["type"])

  if type.any? { |t| ATOMIC_TYPES.include?(t) }
    schema["example"] || schema["default"] || example_from_atom(schema)
  elsif type.include?("object") || schema["properties"]
    example_from_object(schema)
  elsif type.include?("array") || schema["items"]
    example_from_array(schema)
  else
    {}
  end
end