Gem grape-entity 如何 expose 字符串数组

markgeek · May 11, 2016 · Last by markgeek replied at May 16, 2016 · 2587 hits

如题。

expose :tags, documentation: { type: 'Array' }

如何在这里声明数组里元素的类型,这里我想声明它是字符串

expose :tags, using: Entities::tag, documentation: { type: 'Array' }

class Tag < Grape::Entity
  expose :field, documentation: {type: 'String'}
end

可以这样试试

expose :tags, documentation: { type: 'Array[String]' } 这样一目了然了

#1 楼 @michael_miao91 这个方法可以,不过其实这个 tags 就是['tag1', 'tag2']这样的机构,不需要field

#2 楼 @pathbox 这个方法是不是跟版本有关,我这里这样写就不行,我用的是 swagger2

You need to Sign in before reply, if you don't have an account, please Sign up first.