swagger-core
swagger-core copied to clipboard
Schema with type object and items is being read as an array
For all swagger files which have type mentioned as object and items is also present under the schema, the requests like these are being read as array which is wrong.
For example:
swagger: '2.0'
info:
description: 'This is a TEST.'
version: 1.0.0
title: Test
host: www.abc.com
basePath: /api
schemes:
- http
paths:
/test:
get:
summary: Test
description: 'test'
operationId: test
responses:
'200':
schema:
type: 'object'
items:
$ref: '#/definitions/myResponse'
description: myResponse
definitions:
myResponse:
type: object
properties:
id:
type: integer
format: `int64'
Here, under schema details since we are passing items as a non-null object which has some value, it is treating it as a array object. But, if you look above that, you'll notice that we have defined the type for this, i.e., object. So, this is wrong. It should treat this also as an object instead of array.
This change was made as a part of the following issue: https://github.com/swagger-api/swagger-core/pull/4109
This can be solved by checking if it contains a type or not. If it doesn't contain a type and items is present, then we can treat it as an array by default. But, if it contains type, then we should use that type instead of treating it as an array. Can you please correct this?