corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

property: create return @emit result, instead should return 'this' #40

Closed ramukima closed 8 years ago

ramukima commented 8 years ago

Creating a pet using yang-express:petstore example returns this error -

{
  "error": {
    "message": "callback.call(...).toJSON is not a function"
  }
}

The reason is that a 'true/false' value is returned by Property.create as part of its last statement execution (which is @emit 'create', value). I think the intent was to return the model/property (this) as part of create.

Adding a return statement in property.litcoffee like below fixes the issue:

      create: (value) ->
        @merge value, replace: false
        @emit 'create', this
        return this
ramukima commented 8 years ago

Note that, with recent changes to yang-js, the list entry unique validation is broken and I am able to create more than one pet with the same identifier.

sekur commented 8 years ago

Ah, yes, before there was no @emit 'create', this at the end of the block... will fix now.

Right, on the list entry unique validation was a temporary compromise - I meant to bring it back but the reminder is helpful. :-)

sekur commented 8 years ago

BTW, take a look at http://github.com/corenova/yang-swagger. It allows you to have auto-generated documentation integration with apiary.io. http://docs.yangswagger.apiary.io for self-documentation of YANG model-driven projects. It was created for the 'yang-cord' project, which you can see here: http://docs.yangcord.apiary.io