Swagger: 在哈希错误中表示枚举属性
Swagger: 在哈希错误中表示枚举属性
我目前正在为Ruby on Rails API创建Swagger文档。该API中包含了许多枚举器(enums),这些枚举器包含在各个模型中。为了能够在后期进行修改而不出问题,这些枚举器被存储为哈希而不是数组,存放在app/models/concerns
目录中。
状态枚举(state.rb)
module State extend ActiveSupport::Concern included do enum state: { state1: 'State 1', state2: 'State 2', state3: 'State 3', state4: 'State 4', state5: 'State 5' } end end
然而,当我试图在Swagger的组件模式中以以下方式表示它时:
components:
schemas:
State:
type: object
properties:
enum: { state1: 'State 1',
state2: 'State 2',
state3: 'State 3',
state4: 'State 4',
state5: 'State 5' }
我得到了一个错误:
不应有额外的属性
state1: 'State 1'
state2: 'State 2'
state3: 'State 3'
state4: 'State 4'
state5: 'State 5'
我想要以哈希的形式表示枚举,而不是以数组的形式。有没有什么方法可以解决这个问题?