根据下面的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
答案 0 :(得分:1)
问题是items
是一个神奇的关键字,它定义此集合中的所有项目都使用以下架构。我们不需要实际使它成为YAML数组项。因此,工作swagger规范看起来像:
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