Module: OpenApiAnnotator::SerializerAnnotatable::ClassMethods
- Defined in:
- lib/open_api_annotator/serializer_annotatable.rb
Instance Method Summary collapse
- #attribute(attr, options = {}, &block) ⇒ Object
- #belongs_to(name, options = {}, &block) ⇒ Object
- #has_many(name, options = {}, &block) ⇒ Object
- #has_one(name, options = {}, &block) ⇒ Object
- #open_api_attributes ⇒ Object
- #open_api_belongs_to_associations ⇒ Object
- #open_api_has_many_associations ⇒ Object
- #open_api_has_one_associations ⇒ Object
- #open_api_resource_name ⇒ Object
- #skip_open_api_validation! ⇒ Object
- #validate_open_api_format!(format) ⇒ Object
- #validate_open_api_nullable!(type) ⇒ Object
- #validate_open_api_options(field, options) ⇒ Object
- #validate_open_api_type!(type) ⇒ Object
Instance Method Details
#attribute(attr, options = {}, &block) ⇒ Object
10 11 12 13 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 10 def attribute(attr, = {}, &block) (attr, ) super(attr, , &block) end |
#belongs_to(name, options = {}, &block) ⇒ Object
25 26 27 28 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 25 def belongs_to(name, = {}, &block) (name, ) super(name, , &block) end |
#has_many(name, options = {}, &block) ⇒ Object
15 16 17 18 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 15 def has_many(name, = {}, &block) (name, ) super(name, , &block) end |
#has_one(name, options = {}, &block) ⇒ Object
20 21 22 23 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 20 def has_one(name, = {}, &block) (name, ) super(name, , &block) end |
#open_api_attributes ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 85 def open_api_attributes _attributes_data.values.reject { |attribute| attribute.name.to_s.start_with?("_") }.map { |attribute| serializer_class = attribute.[:serializer] type = serializer_class ? [serializer_class.open_api_resource_name] : attribute.[:type] Attribute.new(attribute.name.to_sym, type, attribute.[:format], attribute.[:nullable]) } end |
#open_api_belongs_to_associations ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 75 def open_api_belongs_to_associations _reflections.values.select { |reflection| reflection.is_a?(ActiveModel::Serializer::BelongsToReflection) }.map do |reflection| serializer_class = reflection.[:serializer] type = serializer_class ? [serializer_class.open_api_resource_name] : reflection.[:type] Association.new(reflection.name.to_sym, type, reflection.[:nullable]) end end |
#open_api_has_many_associations ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 55 def open_api_has_many_associations _reflections.values.select { |reflection| reflection.is_a?(ActiveModel::Serializer::HasManyReflection) }.map do |reflection| serializer_class = reflection.[:serializer] type = serializer_class ? [serializer_class.open_api_resource_name] : reflection.[:type] Association.new(reflection.name.to_sym, type, reflection.[:nullable]) end end |
#open_api_has_one_associations ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 65 def open_api_has_one_associations _reflections.values.select { |reflection| reflection.is_a?(ActiveModel::Serializer::HasOneReflection) }.map do |reflection| serializer_class = reflection.[:serializer] type = serializer_class ? [serializer_class.open_api_resource_name] : reflection.[:type] Association.new(reflection.name.to_sym, type, reflection.[:nullable]) end end |
#open_api_resource_name ⇒ Object
95 96 97 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 95 def open_api_resource_name name.remove(/Serializer\z/) end |
#skip_open_api_validation! ⇒ Object
6 7 8 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 6 def skip_open_api_validation! @open_api_validation_skipped = true end |
#validate_open_api_format!(format) ⇒ Object
50 51 52 53 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 50 def validate_open_api_format!(format) @open_api_format_validator ||= FormatValidator.new @open_api_format_validator.validate!(format) end |
#validate_open_api_nullable!(type) ⇒ Object
45 46 47 48 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 45 def validate_open_api_nullable!(type) @open_api_nullable_validator ||= NullableValidator.new @open_api_nullable_validator.validate!(type) end |
#validate_open_api_options(field, options) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 30 def (field, ) return if @open_api_validation_skipped validate_open_api_type!([:type]) validate_open_api_format!([:format]) validate_open_api_nullable!([:nullable]) rescue ValidationError => e Rails.logger.warn(e.) end |
#validate_open_api_type!(type) ⇒ Object
40 41 42 43 |
# File 'lib/open_api_annotator/serializer_annotatable.rb', line 40 def validate_open_api_type!(type) @open_api_type_validator ||= TypeValidator.new @open_api_type_validator.validate!(type) end |