首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >swagger-codegen跳过无效的属性类型:数组

swagger-codegen跳过无效的属性类型:数组
EN

Stack Overflow用户
提问于 2016-06-20 20:05:02
回答 1查看 646关注 0票数 0

在针对下面的swagger规范运行java -jar swagger-codegen-cli.jar generate -i ../tech-bucket/membership-card/apis/mini.swagger -l nodejs-server时,我看到两个错误/警告:

代码语言:javascript
复制
[main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name actual_things
[main] WARN io.swagger.codegen.DefaultCodegen - skipping invalid property {
  "type" : "array"
}
[main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name actual_things
[main] WARN io.swagger.codegen.DefaultCodegen - skipping invalid property {
  "type" : "array"
}

我不明白指定type: array是什么无效的。否则,我如何表示API返回对象数组?也就是说,API返回的内容如下:

代码语言:javascript
复制
{
    formatted_input: "Here is the formatted input",
    actual_things: [
        {id: "10", thing_value: "the value for number 10"},
        {id: "12", thing_value: "the value for number 12"}
    ]
}

错误的招摇过关规范是:

代码语言:javascript
复制
swagger: '2.0'

info:
  version: "1"
  title: title here
  description: description here

paths:
  /endpoint:
    get:
      description: an endpoint
      parameters:
        -
          name: someparam
          in: query
          description: param desc here
          required: true
          type: string
      responses:
        200:
          description: List of things
          schema:
            title: thing_list
            type: object
            properties:
              formatted_input:
                type: string
                description: The passed input
              actual_things:
                type: array
                items:
                  -
                    type: object
                    properties:
                      thing_value:
                        type: string
                        description: The thing
                      id:
                        type: string
                        description: an ID
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-21 08:16:03

问题是,items是一个神奇的关键字,它定义了这个集合中的所有项都使用以下模式。实际上,我们不需要将其作为YAML数组项。因此,“工作招摇规范”看起来如下:

代码语言:javascript
复制
swagger: '2.0'

info:
  version: "1"
  title: title here
  description: description here

paths:
  /endpoint:
    get:
      description: an endpoint
      parameters:
        -
          name: someparam
          in: query
          description: param desc here
          required: true
          type: string
      responses:
        200:
          description: List of things
          schema:
            title: thing_list
            type: object
            properties:
              formatted_input:
                type: string
                description: The passed input
              actual_things:
                type: array
                items:
                  type: object
                  properties:
                    thing_value:
                      type: string
                      description: The thing
                    id:
                      type: string
                      description: an ID
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37930932

复制
相关文章

相似问题

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