Class: OpenApiDocumentation::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/apiculture/openapi_documentation.rb

Constant Summary collapse

TYPES =
{
  String => 'string',
  Integer => 'integer',
  TrueClass => 'boolean'
}.freeze
EXAMPLES =
{
  String => 'string',
  Integer => 1234,
  TrueClass => true
}.freeze

Class Method Summary collapse

Class Method Details

.clean_path(path) ⇒ Object



220
221
222
# File 'lib/apiculture/openapi_documentation.rb', line 220

def self.clean_path(path)
  path.gsub(/\/\?\*\?$/, '')
end

.map_example(type) ⇒ Object



216
217
218
# File 'lib/apiculture/openapi_documentation.rb', line 216

def self.map_example(type)
  EXAMPLES.fetch(type, 'string')
end

.map_type(type) ⇒ Object



212
213
214
# File 'lib/apiculture/openapi_documentation.rb', line 212

def self.map_type(type)
  TYPES.fetch(type, 'string')
end

.response_to_schema(response) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
# File 'lib/apiculture/openapi_documentation.rb', line 200

def self.response_to_schema(response)
  schema = {}
  return nil if response.nil? || response.empty? || response.class == String
  response.each do |key, value|
    schema[key] = {
      type: 'string',
      example: value.to_s
    }
  end
  schema
end