Sha256: 506be1777d5cd62931b75892e230ea742ecf010662f80625ef48154586ed7b6b

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ImportCommand
      module OpenAPI
        class ThreeScaleApiSpec
          attr_reader :openapi

          def initialize(openapi, base_path = nil)
            @openapi = openapi
            @base_path = base_path
          end

          def title
            openapi.info.title
          end

          def description
            openapi.info.description
          end

          def host
            openapi.host
          end

          def schemes
            Array(openapi.schemes)
          end

          def backend_version
            # default authentication mode if no security requirement
            return '1' if security.nil?

            case security.type
            when 'oauth2'
              'oidc'
            when 'apiKey'
              '1'
            else
              raise ThreeScaleToolbox::Error, "Unexpected security scheme type #{security.type}"
            end
          end

          def security
            @security ||= parse_security
          end

          def operations
            openapi.operations.map do |op|
              Operation.new(
                base_path: base_path,
                public_base_path: public_base_path,
                path: op.path,
                verb: op.verb,
                operationId: op.operation_id,
                description: op.description,
              )
            end
          end

          def public_base_path
            @base_path || base_path
          end

          def base_path
            openapi.base_path || '/'
          end

          private

          def parse_security
            raise ThreeScaleToolbox::Error, 'Invalid OAS: multiple security requirements' \
              if openapi.global_security_requirements.size > 1

            openapi.global_security_requirements.first
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb