Sha256: cd3636325cd64f7323ffe901ec3238ed464ca7c1420210b4353b774b9f269a97

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true

module WeakSwaggerParameters
  module Definitions
    class Model
      include WeakSwaggerParameters::Definitions::PropertyContainer

      def initialize(model_name, &block)
        @model_name = model_name

        instance_eval(&block) if block.present?
      end

      def apply_validations(parent_node)
        child_definitions.each { |definition| definition.apply_validations(parent_node) }
      end

      def apply_docs(parent_node)
        model_name = @model_name
        definitions = child_definitions
        schema_options = {}
        schema_options[:required] = required_fields unless required_fields.empty?

        parent_node.instance_eval do
          swagger_schema model_name, schema_options do
            schema_node = self
            definitions.each { |definition| definition.apply_docs(schema_node) }
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
weak_swagger_parameters-0.6.0 lib/weak_swagger_parameters/definitions/model.rb
weak_swagger_parameters-0.5.0 lib/weak_swagger_parameters/definitions/model.rb