Class: OpenApiDocumentation::Util
- Inherits:
-
Object
- Object
- OpenApiDocumentation::Util
- 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
- .clean_path(path) ⇒ Object
- .map_example(type) ⇒ Object
- .map_type(type) ⇒ Object
- .response_to_schema(response) ⇒ Object
Class Method Details
.clean_path(path) ⇒ Object
232 233 234 |
# File 'lib/apiculture/openapi_documentation.rb', line 232 def self.clean_path(path) path.gsub(/\/\?\*\?$/, '') end |
.map_example(type) ⇒ Object
228 229 230 |
# File 'lib/apiculture/openapi_documentation.rb', line 228 def self.map_example(type) EXAMPLES.fetch(type, 'string') end |
.map_type(type) ⇒ Object
224 225 226 |
# File 'lib/apiculture/openapi_documentation.rb', line 224 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 211 212 213 214 215 216 217 218 219 220 221 222 |
# 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 |