Module: JSONAPIonify::Api::Attribute::Documentation

Included in:
JSONAPIonify::Api::Attribute
Defined in:
lib/jsonapionify/api/attribute/documentation.rb

Instance Method Summary collapse

Instance Method Details

#documentation_objectObject



15
16
17
18
19
20
21
22
23
# File 'lib/jsonapionify/api/attribute/documentation.rb', line 15

def documentation_object
  OpenStruct.new(
    name:        name,
    type:        type.name,
    required:    required ? Array.wrap(required).join(', ') : false,
    description: JSONAPIonify::Documentation.render_markdown(description),
    allow:       allow
  )
end

#options_json_for_action(action_name, context) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/jsonapionify/api/attribute/documentation.rb', line 3

def options_json_for_action(action_name, context)
  {
    name:        @name,
    type:        @type.to_s,
    description: JSONAPIonify::Documentation.onelinify_markdown(description),
    example:     example(context.resource.class.generate_id)
  }.tap do |opts|
    opts[:not_null] = true if @type.not_null?
    opts[:required] = true if required_for_action?(action_name, context)
  end
end