HyperBrain / serverless-models-plugin

Model support for Serverless 0.5.x
25 stars 6 forks source link

Error 'Model not defined: Empty' #5

Closed dennisoverbeeke closed 8 years ago

dennisoverbeeke commented 8 years ago

Hyprbrain,

wanted to use your plugin for added model support but when testing I am getting an error: "POST - registrations: Model not defined: Empty" where I have a sls function named 'registration'.

I defined a model 'registrationModel' in s-models.json (in my project root folder) and referenced to it in my s-function.json like this:

      "requestModels": {
        "application/json": "registrationModel"
      },

sls models list outputs me the model:

$ sls models list
Serverless: registrationModel  

and the sls models show registrationModel gives:

$ sls models show registrationModel
Serverless: 
{
  "registrationModel": {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
      "myProp": {
        "type": "string"
      },
      "myProp2": {
        "type": "number"
      }
    }
  }
} 

sls dash deploy --debug gives:

Serverless: Deploying endpoints in "dev" to the following regions: eu-central-1  
Serverless: /   serverless:lib.node_modules.serverless.lib.ProviderAws "dev - eu-central-1": found existing REST API on AWS API Gateway with name: BCOS-Serverless +186ms
  serverless:lib.node_modules.serverless.lib.utils.index Writing file: /Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/_meta/variables/s-variables-dev-eucentral1.json... +3ms
Serverless: |   serverless:lib.node_modules.serverless.lib.ProviderAws "dev - eu-central-1": found existing REST API on AWS API Gateway with name: BCOS-Serverless +168ms
  serverless:lib.node_modules.serverless.lib.utils.index Reading file: /Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/s-models.json... +9ms
Serverless: Failed to deploy endpoints in "dev" to the following regions:  
Serverless: eu-central-1 ------------------------  
Serverless:   POST - registrations: Model not defined: Empty  
  serverless:lib.node_modules.serverless.lib.actions.EndpointDeploy ServerlessError: Model not defined: Empty
    at new ServerlessError (/Users/dennisoverbeeke/npm/lib/node_modules/serverless/lib/Error.js:17:11)
    at /Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/lib/actions/ModelsDeploy.js:100:45
    at tryCatcher (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:502:31)
    at Promise._settlePromise (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:559:18)
    at Promise._settlePromise0 (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:604:10)
    at Promise._settlePromises (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:683:18)
    at Promise._fulfill (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:628:18)
    at Promise._resolveCallback (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:445:14)
    at Promise._settlePromiseFromHandler (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:514:17)
    at Promise._settlePromise (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:559:18)
    at Promise._settlePromise0 (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:604:10)
    at Promise._settlePromises (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:683:18)
    at Promise._fulfill (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:628:18)
    at MappingPromiseArray.PromiseArray._resolve (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise_array.js:125:19)
    at MappingPromiseArray._filter (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/map.js:123:10)
    at MappingPromiseArray._promiseFulfilled (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/map.js:95:18)
    at MappingPromiseArray.PromiseArray._iterate (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise_array.js:113:31)
    at MappingPromiseArray.init (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise_array.js:77:10)
    at Promise._settlePromise (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:556:21)
    at Promise._settlePromise0 (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:604:10)
    at Promise._settlePromises (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/promise.js:683:18)
    at Async._drainQueue (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/async.js:138:16)
    at Async._drainQueues (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/async.js:148:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/node_modules/serverless-models-plugin/node_modules/bluebird/js/release/async.js:17:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17) +5ms
Serverless:   
Serverless: Run this again with --debug to get more error information...  

Would love to use the plugin but it it not working for me... Did I do something wrong? Or is something not working correctly?

dennisoverbeeke commented 8 years ago

Some more information after trial and error...

After deleting the s-models.json I also get the error (without referencing to models anywhere).

If a use an empty s-models.json file I get the error Could not parse JSON in file: /Users/dennisoverbeeke/Documents/Development/BCOS-Serverless/s-models.json (sounds logic)

If s-models.json exists and has content (whatever the content is, used your example as well), it gives the error as in the OP. Even if I am not using it at all

Hope this gives extra information

HyperBrain commented 8 years ago

The problem with the missing "Empty" model is, that the function create boilerplate of Serverless creates an reference to "Empty" for each endpoint it creates. As soon as you now use the models plugin, it is missing as it is not defined by default. You have to remove the "Empty" model reference then from the endpoint definition and define it to be just empty for that endpoint:

"repsonseModels": {}
dennisoverbeeke commented 8 years ago

Few things: 1) I feel stupid 2) Of course this works like a charm 3) It is now documented for others 4) Thank you for your quick reply

dennisoverbeeke commented 8 years ago

As stated, works as a charm when deleting the boilerplate code

HyperBrain commented 8 years ago

Thanks for bringing that up :-)