Reputation: 2110
On running java -jar swagger-codegen-cli.jar generate -i ../tech-bucket/membership-card/apis/mini.swagger -l nodejs-server
against the swagger spec below, I see two 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"
}
I don't understand what's invalid about specifying type: array
. How else do I express that the API returns an array of objects? That is, the API returns something that looks like:
{
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"}
]
}
The swagger spec in error is:
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
Upvotes: 0
Views: 814
Reputation: 2110
The issue is that items
is a magic keyword which defines that all items in this collection use the following schema. We do not need to actually make it a YAML array item. So, working swagger spec looks like:
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
Upvotes: 2