Skip to content

Commit

Permalink
Use format option
Browse files Browse the repository at this point in the history
  • Loading branch information
gregg-platogo committed Nov 22, 2024
1 parent c54ed8f commit e7a8ace
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,14 @@ def build_memo_schema(memo, route, value, response_model, options)
end

def build_primitive_response(memo, _route, value, _options)
type = GrapeSwagger::DocMethods::DataType.call(value[:type])
data_type = GrapeSwagger::DocMethods::DataType.call(value[:type])
type, format = GrapeSwagger::DocMethods::DataType.mapping(data_type)

if memo[value[:code]].include?(:schema) && value.include?(:as)
memo[value[:code]][:schema][:properties].merge!(value[:as] => { type: type })
memo[value[:code]][:schema][:properties].merge!(value[:as] => { type: type, format: format }.compact)
elsif value.include?(:as)
memo[value[:code]][:schema] = { type: :object, properties: { value[:as] => { type: type } } }
memo[value[:code]][:schema] =
{ type: :object, properties: { value[:as] => { type: type, format: format }.compact } }
else
memo[value[:code]][:schema] = { type: type }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class ResponseApiModelsAndPrimitiveTypes < Grape::API
success: [
{ type: 'Integer', as: :integer_response },
{ model: Entities::UseResponse, as: :user_response },
{ type: 'String', as: :string_response }
{ type: 'String', as: :string_response },
{ type: 'Float', as: :float_response }
],
failure: [
{ code: 400, message: 'NotFound', model: '' },
Expand Down Expand Up @@ -51,8 +52,9 @@ def app
'type' => 'object',
'properties' => {
'user_response' => { '$ref' => '#/definitions/UseResponse' },
'integer_response' => { 'type' => 'integer' },
'string_response' => { 'type' => 'string' }
'integer_response' => { 'type' => 'integer', 'format' => 'int32' },
'string_response' => { 'type' => 'string' },
'float_response' => { 'type' => 'number', 'format' => 'float' }
}
}
},
Expand Down

0 comments on commit e7a8ace

Please sign in to comment.