Sha256: 732f87052fb7001d6ba23054597da6c17a982ea3119fa225f2ec9fcf7321e6a8

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

module Dox
  module Printers
    class DocumentPrinter < BasePrinter
      def initialize(output)
        super(body)
        @output = output
      end

      def print(passed_examples)
        spec['paths'] = {}
        spec['tags'] = []
        spec['x-tagGroups'] = []

        passed_examples.sort.each do |_, resource_group|
          group_printer.print(resource_group)
        end

        order_groups

        @output.puts(JSON.pretty_generate(spec))
      end

      private

      def body
        {
          openapi: Dox.config.openapi_version || '3.0.0',
          info: {
            title: Dox.config.title || 'API Documentation',
            description: adjust_description(Dox.config.header_description || ''),
            version: Dox.config.api_version || '1.0'
          }
        }
      end

      def adjust_description(description)
        description.end_with?('.md') ? acquire_desc(description) : description
      end

      def acquire_desc(path)
        read_file(path)
      end

      def group_printer
        @group_printer ||= ResourceGroupPrinter.new(spec)
      end

      def order_groups
        return if (Dox.config.groups_order || []).empty?

        spec['x-tagGroups'] = spec['x-tagGroups'].sort_by do |tag|
          Dox.config.groups_order.index(tag[:name]) || 100
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dox-2.4.0 lib/dox/printers/document_printer.rb
dox-2.3.0 lib/dox/printers/document_printer.rb
dox-2.2.0 lib/dox/printers/document_printer.rb
dox-2.1.0 lib/dox/printers/document_printer.rb
dox-2.0.0 lib/dox/printers/document_printer.rb