swagger-codegen 跳过无效 属性 type:array
swagger-codegen skipping invalid property type:array
在 运行 java -jar swagger-codegen-cli.jar generate -i ../tech-bucket/membership-card/apis/mini.swagger -l nodejs-server
上,针对下面的 swagger 规范,我看到两个 errors/warnings:
[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 returns 对象数组?也就是说,API returns 看起来像:
{
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 规范是:
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
问题是 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
在 运行 java -jar swagger-codegen-cli.jar generate -i ../tech-bucket/membership-card/apis/mini.swagger -l nodejs-server
上,针对下面的 swagger 规范,我看到两个 errors/warnings:
[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 returns 对象数组?也就是说,API returns 看起来像:
{
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 规范是:
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
问题是 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