在针对下面的swagger规范运行java -jar swagger-codegen-cli.jar generate -i ../tech-bucket/membership-card/apis/mini.swagger -l nodejs-server时,我看到两个错误/警告:
[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返回的内容如下:
{
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"}
]
}错误的招摇过关规范是:
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发布于 2016-06-21 08:16:03
问题是,items是一个神奇的关键字,它定义了这个集合中的所有项都使用以下模式。实际上,我们不需要将其作为YAML数组项。因此,“工作招摇规范”看起来如下:
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 IDhttps://stackoverflow.com/questions/37930932
复制相似问题