Sha256: 9fe81d2e77003a7d34a259e5107377f9ff503eda59f9d2f54004ba1a1a5f7748

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

require 'forwardable'
require_relative './endpoint'
require_relative './response_format'
require_relative './groups'
require_relative './versions'
require_relative '../services/open_api_definition_resolver'

module Nexmo
  module OAS
    module Renderer
      module Presenters

        class OpenApiSpecification
          extend Forwardable

          attr_reader :definition_name

          def_delegators :@versions, :current_version, :available_versions
          def_delegators :@groups, :groups

          def initialize(definition_name:, expand_responses:)
            @definition_name  = definition_name
            @expand_responses = expand_responses
            @versions         = Versions.new(definition_name)
            @groups           = Groups.new(definition)
          end

          def errors?
            File.exist?("#{API.oas_path}/../../errors/#{@definition_name}.md")
          end

          def definition_errors
            @definition_errors ||= MarkdownPipeline.new.call(
              File.read("#{API.oas_path}/../../errors/#{@definition_name}.md")
            ) if errors?
          end

          def definition
            @definition ||= OpenApiDefinitionResolver.find(@definition_name)
          end

          def auto_expand_responses
            @expand_responses
          end

          def formats
            @formats ||= ResponseFormat.to_dropdown(endpoints.flat_map(&:formats).uniq)
          end

          private

          def endpoints
            @endpoints ||= definition.endpoints.map { |e| Endpoint.new(e) }
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nexmo-oas-renderer-0.7.1 lib/nexmo/oas/renderer/presenters/open_api_specification.rb
nexmo-oas-renderer-0.7.0 lib/nexmo/oas/renderer/presenters/open_api_specification.rb
nexmo-oas-renderer-0.6.6 lib/nexmo/oas/renderer/presenters/open_api_specification.rb
nexmo-oas-renderer-0.6.5 lib/nexmo/oas/renderer/presenters/open_api_specification.rb
nexmo-oas-renderer-0.6.4 lib/nexmo/oas/renderer/presenters/open_api_specification.rb
nexmo-oas-renderer-0.6.3 lib/nexmo/oas/renderer/presenters/open_api_specification.rb