You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Array[Object] documentation type parsing (#86)
Fixes incorrect Swagger schema generation when using custom array
documentation syntax like `type: 'Array[Object]'`.
### Problem
When using `type: 'Array[Object]'` with an entity, the Swagger schema
was not correctly generated as an array type with `$ref` items.
### Solution
Add `array_type?` method that detects array notations:
- `is_array: true` - explicit flag (existing behavior)
- `type: 'Array[Object]'` - new syntax for entity arrays
### Usage Example
```ruby
class Report < Grape::Entity
expose :items,
using: ItemEntity,
documentation: {
type: 'Array[Object]',
desc: 'List of items'
}
end
```
Generates correct schema:
```json
{
"type": "array",
"description": "List of items",
"items": { "$ref": "#/definitions/ItemEntity" }
}
```
### Other Changes
- Refactor `parse_grape_entity_params` into smaller, focused methods for
readability
- Add nil guards to prevent potential crashes
- Fix indentation in `parse_nested` method
### Backward Compatibility
- `is_array: true` continues to work as before
- `is_array: false` is respected when explicitly set
- Bare `type: 'Array'` is not double-wrapped
### Note
Tests for empty entity handling require grape-swagger >= 2.1.3
([ruby-grape/grape-swagger#963](ruby-grape/grape-swagger#963))
and are skipped for older versions.
Fixes
[ruby-grape/grape-swagger#962](ruby-grape/grape-swagger#962)
0 commit comments