首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Swagger-尝试使用包含数组的对象参数时出现ui问题

Swagger-尝试使用包含数组的对象参数时出现ui问题
EN

Stack Overflow用户
提问于 2017-03-21 05:01:28
回答 1查看 668关注 0票数 0

似乎快要成功了.

尝试让swagger在请求正文中发送参数的匿名散列。

我有一个匿名散列,其中包含一个名为list的键,该键包含一个数组。

正在尝试发送此参数(text/json):

代码语言:javascript
运行
复制
{
    list : [ 'string1', 'string2' ]
}

Swagger正在构建正确的curl语句,但没有通过UI发送参数。

Swagger构建以下代码(从命令行工作):

代码语言:javascript
运行
复制
/usr/bin/curl -H 'Content-Type: text/json' -X GET -d '{ "list" : [ "text:/export/home/ihome/perl5/our_modules/check_parse_lib_rest/t/data/hosts:/export/home/ihome/perl5/our_modules/check_parse_lib_rest/t/data/hosts", "text:/export/home/ihome/perl5/our_modules/check_parse_lib_rest/t/data/hosts:/export/home/ihome/perl5/our_modules/check_parse_lib_rest/t/data/hosts.1" ] }' 'https://localhost.localdomain:9086/library/check_diff_batch'

但是Swagger-ui没有显示模型示例,也没有在请求体中发送参数。

在编辑器中,我看到列表显示为未定义。

代码语言:javascript
运行
复制
Schema
 ⇄  
Comparison {
list:
ComparisonList undefined *
} 

定义-

代码语言:javascript
运行
复制
paths:
  /check_diff_batch:
    get:
      summary: Compare a list of file comparrison objects using diff.
      description: |
        FIXME: Takes an array of colon delimited comparrison objects.
        Required parameter Comparrison object format = type:file1:file2
        **RC** will return false if there are differences or a failure.
        **FAULT_MSG** will return No Faults or a failure message.
      parameters:
         - $ref: "#/parameters/ComparrisonList"
      responses:
        200:
          description: Successful response
          examples:
            text/json:
                ...

parameters:
    ComparrisonList:
      name: list
      in: body
      description: List of comparrison objects
      schema:
        $ref: "#/definitions/Comparisons"

definitions:
  Comparisons:
    required:
      - list
    properties:
      list:
        $ref: "#/definitions/ComparisonList"

  ComparisonList:
    additionalProperties:
      type: string
EN

回答 1

Stack Overflow用户

发布于 2017-03-21 06:02:22

additionalProperties用于定义关联数组/哈希图,而不是规则数组。常规字符串数组的定义如下:

代码语言:javascript
运行
复制
definitions:
  ComparisonList:
    type: array
    items:
      type: string

您还应该使用post操作,而不是get,因为GET does not have defined semantics中的请求体是按照RFC 7231 section 4.3.1的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42913893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档