Sha256: dbd9ca083bec5feb67d143d634386e1315328b9f2a7969879ba3e7868dda646e

Contents?: true

Size: 995 Bytes

Versions: 6

Compression:

Stored size: 995 Bytes

Contents

module SoberSwag
  module Reporting
    module Output
      ##
      # Models outputting an enum.
      class Enum < Base
        def initialize(output, values)
          @output = output
          @values = values
        end

        ##
        # @return [Interface]
        attr_reader :output

        ##
        # @return [Array]
        attr_reader :values

        def call(value)
          output.call(value)
        end

        def serialize_report(value)
          rep = output.serialize_report(value)

          return rep if rep.is_a?(Report::Base)

          return Report::Value.new(['was not an acceptable enum member']) unless values.include?(rep)

          rep
        end

        def swagger_schema
          schema, found = output.swagger_schema
          merged =
            if schema.key?(:$ref)
              { allOf: [schema] }
            else
              schema
            end.merge(enum: values)
          [merged, found]
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sober_swag-0.25.2 lib/sober_swag/reporting/output/enum.rb
sober_swag-0.25.1 lib/sober_swag/reporting/output/enum.rb
sober_swag-0.25.0 lib/sober_swag/reporting/output/enum.rb
sober_swag-0.24.1 lib/sober_swag/reporting/output/enum.rb
sober_swag-0.24.0 lib/sober_swag/reporting/output/enum.rb
sober_swag-0.23.0 lib/sober_swag/reporting/output/enum.rb