class Praxis::Docs::OpenApi::RequestBodyObject
Attributes
Public Class Methods
new(attribute:)
click to toggle source
# File lib/praxis/docs/open_api/request_body_object.rb, line 12 def initialize(attribute:) @attribute = attribute end
Public Instance Methods
dump()
click to toggle source
# File lib/praxis/docs/open_api/request_body_object.rb, line 16 def dump h = {} h[:description] = attribute.options[:description] if attribute.options[:description] h[:required] = attribute.options[:required] || false # OpenApi wants a set of bodies per MediaType/Content-Type # For us there's really only one schema (regardless of encoding)... # so we'll show all the supported MTs...but repeating the schema # dumped_schema = SchemaObject.new(info: attribute).dump_schema example_handlers = \ if attribute.type < Praxis::Types::MultipartArray ident = MediaTypeIdentifier.load('multipart/form-data') [{ ident.to_s => 'json' }] # Multipart content type else # TODO: We could run it through other handlers I guess...if they're registered [{ 'application/json' => 'json' }] end h[:content] = MediaTypeObject.create_content_attribute_helper(type: attribute.type, example_payload: attribute.example(nil), example_handlers: example_handlers) # # Key string (of MT) , value MTObject # content_hash = info[:examples].each_with_object({}) do |(handler, example_hash),accum| # content_type = example_hash[:content_type] # accum[content_type] = MediaTypeObject.new( # schema: dumped_schema, # Every MT will have the same exact type..oh well # example: info[:examples][handler][:body], # ).dump # end # # TODO! Handle Multipart types! they look like arrays now in the schema...etc # h[:content] = content_hash h end