Sha256: 3ac12d91dd49a6063d5750fcd1b99538884c600d5466ad03c8aecb6f9e887f61

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module OpenAPI::Loader
  #
  # Translates OAS2 to OAS3 specification
  # @private
  #
  class Translator
    extend Dry::Initializer
    extend ConstructorShortcut[:call] # class-level .call

    param :source

    def call
      return source unless oas2?
      WRAPPERS.each { |wrapper| wrapper.new(source).call }
      source
    end

    private

    def oas2?
      source.is_a?(Hash) && source["swagger"].to_s.start_with?("2")
    end

    require_relative "translator/clean_definitions"
    require_relative "translator/convert_bodies"
    require_relative "translator/convert_forms"
    require_relative "translator/convert_parameters"
    require_relative "translator/convert_responses"
    require_relative "translator/convert_security_schemes"
    require_relative "translator/convert_servers"
    require_relative "translator/convert_version"
    require_relative "translator/denormalize_consumes"
    require_relative "translator/denormalize_parameters"
    require_relative "translator/denormalize_produces"

    WRAPPERS = [
      CleanDefinitions,
      DenormalizeParameters,
      DenormalizeConsumes,
      DenormalizeProduces,
      ConvertForms,
      ConvertBodies,
      ConvertParameters,
      ConvertResponses,
      ConvertServers,
      ConvertSecuritySchemes,
      ConvertVersion
    ].freeze
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
open_api-loader-0.0.1 lib/open_api/loader/translator.rb