Skip to content

lb-ng Generates duplicate keys in object JSON when remote method is defined both in js and json files #213

@cmoore4

Description

@cmoore4

If a remote method is defined in a model's JS file and in its JSON file, if you run lb-ng on the models, the angular sdk outputs an object with duplicate keys(one key from the JSON definition, one from the js implementation). This violates the 'use strict' declaration of the function, and causes the file not to load at all.

  "methods": {
    "greet": {
      "isStatic": true,
      "accepts": {
        "arg": "msg",
        "type": "string"
      },
      "returns": {
        "arg": "greeting",
        "type": "string"
      },
      "description": "Provided a name, returns a greeting ",
      "http": [
        {
          "httpPath": "greet",
          "httpVerb": "post"
        }
      ]
    }
  }
  ModelWithRemoteMethod.greet = function(msg, cb) {
    cb(null, 'Greetings... ' + msg);
  };

  ModelWithRemoteMethod.remoteMethod( 
    'greet',
    {
      http: {path: '/greet', verb: 'post'},
      accepts: {arg: 'msg', type: 'string'},
      returns: {arg: 'greeting', type: 'string'}
    }
  );

Generates this:
https://github.com/cmoore4/loopback-angular-remote-method-duplicate-key-bug-demo/blob/master/client/lb-services.js#L1606-L1643

        "greet": {
          url: urlBase + "/mwrms/greet",
          method: "POST"
        },

        /**
         * @ngdoc method
         */
        "greet": {
          url: urlBase + "/mwrms/greet",
          method: "POST"
        },

Removing the method from the JSON definition resolves the issue, but is not optimal.

See demo project here:
https://github.com/cmoore4/loopback-angular-remote-method-duplicate-key-bug-demo

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions