Pedro Pongelupe Lopes
Pedro Pongelupe Lopes

Reputation: 41

Swagger: Expected type array but found type object at #/paths/../parameters

I have this YAML file with a service, but I keep getting some wierd error about receiveing a array instead of a object.

swagger: "2.0"
info:
    description: ""
    version: 1.0.0
    title: Your project
basePath: /
schemes:
  - http
paths: 
    /trocarProprietarioVeiculo:
        post:
            description: ""
            consumes: 
              -application/json
            produces: 
              -application/json
            parameters:
              -in: body
                schema: 
                  $ref: "#/definitions/TrocarProprietarioVeiculoChamada"
            responses:
                "200": 
                  description: ""
                  schema: 
                    $ref: "#/definitions/TrocarProprietarioVeiculoResposta"
definitions: 
    Resposta:
        type: object
        properties:
            erro:
                type: integer
            mensagens:
                type: array
                items:
                    type: string
    RespostaServico:
        type: object
        properties:
            resposta:
                $ref: "#/definitions/Resposta"
    TrocarProprietarioVeiculoChamada:
        type: object
        properties:
            chassi:
                type: string
            codigoCliente:
                type: integer
            nomeCliente:
                type: string
    TrocarProprietarioVeiculoResposta:
        type: object
        properties:
            respostaServico:
                $ref: "#/definitions/RespostaServico"

The message error shown is:

  Swagger schema validation failed. 
  Expected type array but found type object at #/paths//trocarProprietarioVeiculo/post/parameters
  Expected type array but found type string at #/paths//trocarProprietarioVeiculo/post/produces
  Expected type array but found type string at #/paths//trocarProprietarioVeiculo/post/consumes

JSON_OBJECT_VALIDATION_FAILED

This YAML file I am generating dynamically. Any questions about anything that I may answer, I'd be glad to answer!

Upvotes: 3

Views: 7765

Answers (1)

Helen
Helen

Reputation: 98011

Paste your YAML into http://editor.swagger.io and follow the tips. The specific problems are:

1) There must be spaces between - and the values, e.g.:

- application/json

2) The body parameter needs a name, and all attributes must be aligned (have the same indentation):

- in: body
  name: body
  schema:
    $ref: "#/definitions/TrocarProprietarioVeiculoChamada"

Upvotes: 5

Related Questions