Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top level objects must not be type 'array' #36

Open
kellertk opened this issue Mar 14, 2017 · 2 comments
Open

Top level objects must not be type 'array' #36

kellertk opened this issue Mar 14, 2017 · 2 comments

Comments

@kellertk
Copy link

kellertk commented Mar 14, 2017

I've given the swagger definitions in YAML, but I'm converting it to JSON before compilation.

definitions:
  Servers:
    type: array
    items:
      $ref: "#/definitions/Server"
  Server:
    type: object
    properties:
      uid:
        type: string
        description: Unique server ID
      name:
        type: string
        description: FQDN

This returns:

Error: Unrecognized schema type: undefined
    at propertyMap (node_modules\swagger-mongoose\lib\index.js:48:13)
    at getSchemaProperty (node_modules\swagger-mongoose\lib\index.js:240:16)
    at node_modules\swagger-mongoose\lib\index.js:217:26
    at node_modules\swagger-mongoose\node_modules\lodash\lodash.js:4944:15
    at baseForOwn (node_modules\swagger-mongoose\node_modules\lodash\lodash.js:3001:24)
    at node_modules\swagger-mongoose\node_modules\lodash\lodash.js:4913:18
    at Function.forEach (node_modules\swagger-mongoose\node_modules\lodash\lodash.js:9359:14)
    at getSchema (node_modules\swagger-mongoose\lib\index.js:216:5)
    at node_modules\swagger-mongoose\lib\index.js:319:14
    at node_modules\swagger-mongoose\node_modules\lodash\lodash.js:4944:15
    at baseForOwn (node_modules\swagger-mongoose\node_modules\lodash\lodash.js:3001:24)
    at node_modules\swagger-mongoose\node_modules\lodash\lodash.js:4913:18
    at Function.forEach (node_modules\swagger-mongoose\node_modules\lodash\lodash.js:9359:14)
    at Object.module.exports.compile (node_modules\swagger-mongoose\lib\index.js:307:5)
    at Object.<anonymous> (api\models\db.js:11:31)
    at Module._compile (module.js:570:32)

However, encapsulating the array in an object works properly:

definitions:
  Servers:
    description: Many Servers
    type: object
    properties:
      servers:
        type: array 
        items:
          $ref: "#/definitions/Server"
  Server:
    type: object
    properties:
      uid:
        type: string
        description: Unique server ID
      name:
        type: string
        description: FQDN
@briananderson1222
Copy link
Collaborator

What is the desired functionality for a top level array? What would you expect it to do on the mongo side as the object is the essence of the database collection that gets created? If you do:

definitions:
  Servers:
    x-swagger-mongoose:
      exclude-schema: true
    type: array
    items:
      $ref: "#/definitions/Server"
  Server:
    type: object
    properties:
      uid:
        type: string
        description: Unique server ID
      name:
        type: string
        description: FQDN

Does it still fail?

@tnphis
Copy link

tnphis commented Apr 12, 2017

Just had a similar problem. Yes, it fails, probably because getSchema is called before checking for exclude-schema.

Upd: this is resloved in the repository but not in the files pulled from npm registry (even though the version matches). Could be something with my npm cache but it's the first version I installed.

Anyway, doing something with arrays like that is probably a good idea. Even as simple as ignoring them and mentioning it in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants