Sha256: dbe16dde3f70937d5e541a54f90152abbf63006238aee9bf17a1e1878c720b3f
Contents?: true
Size: 1019 Bytes
Versions: 8
Compression:
Stored size: 1019 Bytes
Contents
# frozen_string_literal: true module GrapeSwagger module DocMethods class BuildModelDefinition class << self def build(model, properties) definition = { type: 'object', properties: properties } required = required_attributes(model) definition[:required] = required unless required.blank? definition end private def required_attributes(model) parse_entity(model) || parse_representable(model) end def parse_entity(model) return unless model.respond_to?(:documentation) model.documentation .select { |_name, options| options[:required] } .map { |name, options| options[:as] || name } end def parse_representable(model) return unless model.respond_to?(:map) model.map .select { |p| p[:documentation] && p[:documentation][:required] } .map(&:name) end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems