首页 > 解决方案 > 在数组 swagger 模式中定义不同对象结构的正确方法是什么?

问题描述

我希望这是一个合法的问题,我到处搜索示例或任何有关如何执行此操作的信息来源。我也试过这个https://github.com/fotinakis/swagger-blocks/issues/17。但同样的结果。

我想生成的最终结果如下: { "name": "Awesome Promotion", "description": "30% off", "qualifiers": [ { "id": 12, "type": "Rental" }, { "id": 13, "type": "Qualifier", "user_id": 23 }, { "id": 14, "type": "First", "location_id": 32 } ] 我将模型写成这样: swagger_schema :PromotionResponse do property :name, type: :string, example: 'Awesome Promotion' property :description, type: :string, example: '30% off' property :qualifiers do key :type, :array items do property :id, type: :integer, example: 2 property :type, type: :string, exmple: 'Location' end end end 现在由 swagger 生成的内容: { "name": "Awesome Promotion", "description": "30% off", "qualifiers": [ { "id": 2, "type": "Location" } ] }

在数组模式中定义不同对象结构的正确方法是什么?

标签: swaggerswagger-ui

解决方案


推荐阅读