Day 18: API Specification - Expected response to be object but found array instead

Hey, though there is an existing question on this topic, I didn’t quite understand it. I have tried all sorts of methods, to no avail.

To the question, in the schemas I defined the /cosmos request as in the image below but I am still getting this issue of expecting an object but found array instead.

The Error:

The Request and Response:

This is my schema definition for the request…

I tried changing the example to fit the response type but upon validating, Postman throws an error of unexpected change in the example.

@kevinc-postman Any idea here?

Hi,

I’m really new to schemas but after playing around, if you change it from this;

components:
  schemas:
    Cosmos:
      type: array
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string

To this (adding in the “items:” for array and indenting everything underneath;

components:
  schemas:
    Cosmos:
      type: array
      items:
        required:
            - id
            - name
        properties:
            id:
            type: integer
            format: int64
            name:
            type: string
            tag:
            type: string

And then refresh the page (I was using Postman in the browser)… then that warning message disappears.

Not sure if this is the legitimate fix for the issue though?

1 Like

Hey @w4dd325 , thank you so much! I tried this but it still threw the error. I re-forked the collection and did it again and it works… don’t really know what went wrong in the old one.

1 Like

It’s been intermittent for me too. I’ve just had it working, then throws a warning, then it worked again.
Quite strange.

Yeah, it was very strange. Honestly, was losing my mind over this. Glad to know I’m not the only one lol.

3 Likes