Sha256: 76ac9bebad143b3591a07e95bf903d19087f00af4c8a19225751605f7d176a94

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require_relative 'parameter_object'
require_relative 'request_body_object'
require_relative 'responses_object'

module Praxis
  module Docs
    module OpenApi
      class OperationObject
        # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#operation-object
        attr_reader :id, :url, :action, :tags

        def initialize(id:, url:, action:, tags:)
          @id = id
          @url = url
          @action = action
          @tags = tags
        end

        def dump
          all_parameters = ParameterObject.process_parameters(action)
          all_tags = tags + action.traits
          h = {
            summary: action.name.to_s,
            # externalDocs: {}, # TODO/FIXME
            operationId: id,
            responses: ResponsesObject.new(responses: action.responses).dump
            # callbacks
            # deprecated: false
            # security: [{}]
            # servers: [{}]
          }
          h[:description] = action.description if action.description
          h[:tags] = all_tags.uniq unless all_tags.empty?
          h[:parameters] = all_parameters unless all_parameters.empty?
          h[:requestBody] = RequestBodyObject.new(attribute: action.payload).dump if action.payload
          h
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
praxis-2.0.pre.31 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.30 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.29 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.28 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.27 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.26 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.25 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.24 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.23 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.22 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.21 lib/praxis/docs/open_api/operation_object.rb
praxis-2.0.pre.20 lib/praxis/docs/open_api/operation_object.rb