class Fakeit::Openapi::Operation

Public Class Methods

new(request_operation, app_options) click to toggle source
# File lib/fakeit/openapi/operation.rb, line 4
def initialize(request_operation, app_options)
  @request_operation = request_operation
  @validator = Fakeit::Validation::Validator.new(request_operation)
  @app_options = app_options
end

Public Instance Methods

body() click to toggle source
# File lib/fakeit/openapi/operation.rb, line 19
def body
  response_schema
    &.schema
    &.to_example(example_options)
    &.then(&method(:serialise))
    .to_s
end
example_options() click to toggle source
# File lib/fakeit/openapi/operation.rb, line 33
def example_options
  { use_example: @app_options.use_example, use_static: @app_options.method(:use_static?), depth: 0 }
end
headers() click to toggle source
# File lib/fakeit/openapi/operation.rb, line 12
def headers
  response_headers
    .to_h
    .transform_values { _1.schema.to_example(example_options) }
    .tap { _1['Content-Type'] = response_content_type if response_content_type }
end
response(= @request_operation.operation_object.responses.response.min) click to toggle source
# File lib/fakeit/openapi/operation.rb, line 47
  def response = @request_operation.operation_object.responses.response.min
end
response_content() click to toggle source
# File lib/fakeit/openapi/operation.rb, line 37
def response_content
  response.last.content&.find { |k, _| k =~ %r{^application/.*json} || k == 'application/pdf' }
end
response_content_type(= response_content&.first) click to toggle source
# File lib/fakeit/openapi/operation.rb, line 43
      def response_content_type = response_content&.first

      def response_headers = response.last.headers

      def response = @request_operation.operation_object.responses.response.min
    end
  end
end
response_headers(= response.last.headers) click to toggle source
# File lib/fakeit/openapi/operation.rb, line 45
    def response_headers = response.last.headers

    def response = @request_operation.operation_object.responses.response.min
  end
end
response_schema(= response_content&.last) click to toggle source
# File lib/fakeit/openapi/operation.rb, line 41
    def response_schema = response_content&.last

    def response_content_type = response_content&.first

    def response_headers = response.last.headers

    def response = @request_operation.operation_object.responses.response.min
  end
end
serialise(body) click to toggle source
# File lib/fakeit/openapi/operation.rb, line 31
  def serialise(body) = body.is_a?(String) ? body : JSON.generate(body)

  def example_options
    { use_example: @app_options.use_example, use_static: @app_options.method(:use_static?), depth: 0 }
  end

  def response_content
    response.last.content&.find { |k, _| k =~ %r{^application/.*json} || k == 'application/pdf' }
  end

  def response_schema = response_content&.last

  def response_content_type = response_content&.first

  def response_headers = response.last.headers

  def response = @request_operation.operation_object.responses.response.min
end
status(= response.first.to_i) click to toggle source
# File lib/fakeit/openapi/operation.rb, line 10
def status = response.first.to_i

def headers
  response_headers
    .to_h
    .transform_values { _1.schema.to_example(example_options) }
    .tap { _1['Content-Type'] = response_content_type if response_content_type }
end

def body
  response_schema
    &.schema
    &.to_example(example_options)
    &.then(&method(:serialise))
    .to_s
end

def validate(...) = @validator.validate(...)

private

def serialise(body) = body.is_a?(String) ? body : JSON.generate(body)

def example_options
  { use_example: @app_options.use_example, use_static: @app_options.method(:use_static?), depth: 0 }
end

def response_content
  response.last.content&.find { |k, _| k =~ %r{^application/.*json} || k == 'application/pdf' }
end

def response_schema = response_content&.last

def response_content_type = response_content&.first

def response_headers = response.last.headers

def response = @request_operation.operation_object.responses.response.min
validate(...) click to toggle source
# File lib/fakeit/openapi/operation.rb, line 27
def validate(...) = @validator.validate(...)

private

def serialise(body) = body.is_a?(String) ? body : JSON.generate(body)

def example_options
  { use_example: @app_options.use_example, use_static: @app_options.method(:use_static?), depth: 0 }
end

def response_content
  response.last.content&.find { |k, _| k =~ %r{^application/.*json} || k == 'application/pdf' }
end

def response_schema = response_content&.last

def response_content_type = response_content&.first

def response_headers = response.last.headers

def response = @request_operation.operation_object.responses.response.min