class OpenApiDocumentation::Util
Constants
- EXAMPLES
- TYPES
Public Class Methods
clean_path(path)
click to toggle source
# File lib/apiculture/openapi_documentation.rb, line 232 def self.clean_path(path) path.gsub(/\/\?\*\?$/, '') end
map_example(type)
click to toggle source
# File lib/apiculture/openapi_documentation.rb, line 228 def self.map_example(type) EXAMPLES.fetch(type, 'string') end
map_type(type)
click to toggle source
# File lib/apiculture/openapi_documentation.rb, line 224 def self.map_type(type) TYPES.fetch(type, 'string') end
response_to_schema(response)
click to toggle source
# File lib/apiculture/openapi_documentation.rb, line 200 def self.response_to_schema(response) case response when NilClass when String { type: 'string', example: response } when Integer { type: 'integer', example: response } when Float { type: 'float', example: response } when Array if response.empty? { type: 'array', items: {} } else { type: 'array', items: response.map { |elem| response_to_schema(elem) } } end when Hash response.each_with_object({}) do |(key, val), schema_hash| schema_hash[key] = response_to_schema(val) end else { type: response.class.name.downcase, example: response.to_s } end end