diff --git a/CHANGELOG.md b/CHANGELOG.md
index 551dcaaa..f0cc4018 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,12 @@
This file is created to keep history of the LoopBack SDK Builder, it does not consider or keeps any history of its parent module `loopback-sdk-angular`.
+## Release 2.0.3
+
+- Fixed Lint issues
+- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/99
+
+
## Release 2.0.2
- Hot Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/98
diff --git a/lib/angular2/index.js b/lib/angular2/index.js
index 1526004e..a138d3f4 100644
--- a/lib/angular2/index.js
+++ b/lib/angular2/index.js
@@ -394,7 +394,7 @@ module.exports = function generate(ctx) {
function buildUrlParams(model, methodName, urlParams) {
let output = [''];
// filter params that should not go over url query string
- urlParams = urlParams.filter(param => !param.arg.match(/(id|fk|data|options|credentials)/g));
+ urlParams = urlParams.filter(param => (param.arg && !param.arg.match(/(id|fk|data|options|credentials)/g)));
if (model.isUser && methodName === 'logout')
output.push(` urlParams.access_token = this.auth.getAccessTokenId();`);
if (urlParams && urlParams.length > 0) {
diff --git a/lib/angular2/shared/sdk.module.ejs b/lib/angular2/shared/sdk.module.ejs
index 6b7d7e09..29bc9677 100644
--- a/lib/angular2/shared/sdk.module.ejs
+++ b/lib/angular2/shared/sdk.module.ejs
@@ -75,4 +75,4 @@ export class SDKModule {
]
};
}
-}
\ No newline at end of file
+}
diff --git a/lib/angular2/shared/services/custom/service.ejs b/lib/angular2/shared/services/custom/service.ejs
index 7352f1b3..a2ce9627 100644
--- a/lib/angular2/shared/services/custom/service.ejs
+++ b/lib/angular2/shared/services/custom/service.ejs
@@ -56,7 +56,7 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
}
// SET ROUTE PARAMS
var routeParams = action.accepts.filter(function(param) {
- return (param.http && param.http.source === 'path') || (param.arg.match(/(id|fk|file|container)/));
+ return (param.http && param.http.source === 'path') || (param.arg && param.arg.match(/(id|fk|file|container)/));
});
-%>
public <%- normalizeMethodName(methodName) %>(<%- buildMethodParams(model, methodName, action.accepts) %>) {
diff --git a/lib/utils.js b/lib/utils.js
index ad735412..0fd04465 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -20,7 +20,7 @@ exports.describeModels = function describeModels(app) {
// Tell SDK to blacklist specific methods
c.sharedClass.ctor.settings.sdk.blacklist = Object.assign(
{}, // Will we want to add methods to blacklist by default???
- c.sharedClass.ctor.settings.sdk.blacklist || {}
+ c.sharedClass.ctor.settings.sdk.blacklist || {}
);
if (!c.ctor) {
// Skip classes that don't have a shared ctor
@@ -33,6 +33,16 @@ exports.describeModels = function describeModels(app) {
// the sharedCtor parameters should be added to the parameters
// of prototype methods.
c.methods.forEach(function fixArgsOfPrototypeMethods(method, key) {
+ // Fix for REST DataSource with invalid param configuration
+ if (method.name === 'invoke' && method.sharedMethod.isStatic) {
+ method.accepts.forEach((param) => {
+ if (!param.arg && param.name) {
+ param.arg = param.name;
+ param.http = { source: 'body' };
+ }
+ });
+ }
+ // Add CreateMany Support
if (method.name.match(/(^createMany)/)) return
if (method.name.match(/(^create$|__create__)/)) {
var createMany = Object.create(method);
@@ -44,18 +54,17 @@ exports.describeModels = function describeModels(app) {
if (!ctor || method.sharedMethod.isStatic) return;
method.accepts = ctor.accepts.concat(method.accepts);
var loaded = {};
- // clean duplicated params
+ // Clean duplicated params from diff sources
if (method.name.match(/createMany/)) {
method.accepts.forEach((param, index, arr) => {
if (loaded[param.arg]) {
arr.splice(index, 1);
- } else {
+ } else {
loaded[param.arg] = true;
}
});
}
if (!method.accepts) return;
-
// Any extra http action arguments in the path need to be added to the
// angular resource actions as params
method.accepts.forEach(function findResourceParams(arg) {
@@ -74,7 +83,7 @@ exports.describeModels = function describeModels(app) {
c.properties = c.sharedClass.ctor.definition.properties;
c.isUser = c.sharedClass.ctor.prototype instanceof app.loopback.User ||
- c.sharedClass.ctor.prototype === app.loopback.User.prototype;
+ c.sharedClass.ctor.prototype === app.loopback.User.prototype;
models[name] = c;
});
@@ -131,7 +140,6 @@ function buildScopeMethod(models, modelName, method) {
'Warning: scope %s.%s targets class %j, which is not exposed ' +
'\nvia remoting. The Angular code for this scope won\'t be generated.',
modelName, scopeName, targetClass);
- console.log(modelName, scopeName, targetClass);
modelClass.scopes[scopeName] = null;
return;
}
diff --git a/package.json b/package.json
index a00326a0..d023e38f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@mean-expert/loopback-sdk-builder",
- "version": "2.0.2",
+ "version": "2.0.3",
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
"bin": {
"lb-sdk": "bin/lb-sdk"
diff --git a/tests/angular2/common/models/core.js b/tests/angular2/common/models/core.js
new file mode 100644
index 00000000..839baf28
--- /dev/null
+++ b/tests/angular2/common/models/core.js
@@ -0,0 +1,3 @@
+module.exports = function(Core) {
+
+};
diff --git a/tests/angular2/common/models/core.json b/tests/angular2/common/models/core.json
new file mode 100644
index 00000000..99e2ab63
--- /dev/null
+++ b/tests/angular2/common/models/core.json
@@ -0,0 +1,14 @@
+{
+ "name": "Core",
+ "plural": "cores",
+ "base": "Model",
+ "idInjection": true,
+ "options": {
+ "validateUpsert": true
+ },
+ "properties": {},
+ "validations": [],
+ "relations": {},
+ "acls": [],
+ "methods": {}
+}
diff --git a/tests/angular2/loopback/datasources.json b/tests/angular2/loopback/datasources.json
index 86b6c9cc..7ad57f25 100644
--- a/tests/angular2/loopback/datasources.json
+++ b/tests/angular2/loopback/datasources.json
@@ -8,5 +8,37 @@
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./loopback/storage"
+ },
+ "corezoid": {
+ "name": "corezoid",
+ "crud": false,
+ "connector": "rest",
+ "options": {
+ "headers": {
+ "accept": "application/json",
+ "content-type": "application/json"
+ },
+ "strictSSL": false
+ },
+ "operations": [
+ {
+ "template": {
+ "method": "POST",
+ "url": "https://www.corezoid.com/api/1/json/{path}",
+ "query": {},
+ "responsePath": "$",
+ "body": "{body}",
+ "options": {
+ "useQuerystring": false
+ }
+ },
+ "functions": {
+ "run": [
+ "path",
+ "body"
+ ]
+ }
+ }
+ ]
}
}
diff --git a/tests/angular2/loopback/model-config.json b/tests/angular2/loopback/model-config.json
index 292c9c9b..cbbe8856 100644
--- a/tests/angular2/loopback/model-config.json
+++ b/tests/angular2/loopback/model-config.json
@@ -76,5 +76,9 @@
"Storage": {
"dataSource": "storage",
"public": true
+ },
+ "Core": {
+ "dataSource": "corezoid",
+ "public": true
}
}
diff --git a/tests/angular2/package.json b/tests/angular2/package.json
index 9515df70..b4eb95ad 100644
--- a/tests/angular2/package.json
+++ b/tests/angular2/package.json
@@ -21,13 +21,9 @@
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
- "core-js": "^2.4.0",
- "reflect-metadata": "0.1.3",
- "rxjs": "5.0.0-beta.6",
- "ts-helpers": "^1.1.1",
- "zone.js": "0.6.12",
"compression": "^1.0.3",
"config-chain": "^1.1.10",
+ "core-js": "^2.4.0",
"cors": "^2.5.2",
"es6-shim": "^0.35.0",
"helmet": "^1.3.0",
@@ -37,8 +33,13 @@
"loopback-component-passport": "^2.1.0",
"loopback-component-pubsub": "^1.0.18",
"loopback-component-storage": "^1.9.0",
+ "loopback-connector-rest": "^2.0.0",
"loopback-datasource-juggler": "^2.39.0",
- "socket.io-client": "1.4.8"
+ "reflect-metadata": "0.1.3",
+ "rxjs": "5.0.0-beta.6",
+ "socket.io-client": "1.4.8",
+ "ts-helpers": "^1.1.1",
+ "zone.js": "0.6.12"
},
"devDependencies": {
"@types/jasmine": "^2.2.30",
diff --git a/tests/angular2/src/app/app.component.ts b/tests/angular2/src/app/app.component.ts
index d1d3fd78..6bf650d6 100644
--- a/tests/angular2/src/app/app.component.ts
+++ b/tests/angular2/src/app/app.component.ts
@@ -1,6 +1,4 @@
import { Component } from '@angular/core';
-import { Room } from './shared/sdk/models';
-import { RoomApi } from './shared/sdk/services';
@Component({
selector: 'app-root',
@@ -10,13 +8,4 @@ import { RoomApi } from './shared/sdk/services';
export class AppComponent {
title = 'app works!';
- /*
- constructor(private roomApi: RoomApi) {
- let room: Room = new Room();
- room.name = 'My Room';
- this.roomApi.create(room).subscribe((instance: Room) => {
- console.log(instance);
- });
- }
- */
}
diff --git a/tests/angular2/src/app/app.module.ts b/tests/angular2/src/app/app.module.ts
index f54894e4..fdf669e5 100644
--- a/tests/angular2/src/app/app.module.ts
+++ b/tests/angular2/src/app/app.module.ts
@@ -1,5 +1,5 @@
import { BrowserModule } from '@angular/platform-browser';
-import { NgModule, ApplicationRef } from '@angular/core';
+import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
diff --git a/tests/angular2/src/app/shared/sdk/index.ts b/tests/angular2/src/app/shared/sdk/index.ts
index 2870f255..4b467427 100644
--- a/tests/angular2/src/app/shared/sdk/index.ts
+++ b/tests/angular2/src/app/shared/sdk/index.ts
@@ -35,7 +35,8 @@ import {
CategoryApi,
AccountApi,
RoomAccountApi,
- StorageApi
+ StorageApi,
+ CoreApi
} from './services/index';
export const API_PROVIDERS: any[] = [
HTTP_PROVIDERS,
@@ -52,7 +53,8 @@ export const API_PROVIDERS: any[] = [
CategoryApi,
AccountApi,
RoomAccountApi,
- StorageApi
+ StorageApi,
+ CoreApi
];
export * from './models/index';
export * from './services/index';
diff --git a/tests/angular2/src/app/shared/sdk/models/Core.ts b/tests/angular2/src/app/shared/sdk/models/Core.ts
new file mode 100644
index 00000000..e3cdf322
--- /dev/null
+++ b/tests/angular2/src/app/shared/sdk/models/Core.ts
@@ -0,0 +1,12 @@
+/* tslint:disable */
+
+export interface CoreInterface {
+ id?: number;
+}
+
+export class Core implements CoreInterface {
+ id: number;
+ constructor(instance?: Core) {
+ Object.assign(this, instance);
+ }
+}
diff --git a/tests/angular2/src/app/shared/sdk/models/index.ts b/tests/angular2/src/app/shared/sdk/models/index.ts
index c481b159..9ab675fa 100644
--- a/tests/angular2/src/app/shared/sdk/models/index.ts
+++ b/tests/angular2/src/app/shared/sdk/models/index.ts
@@ -9,4 +9,5 @@ export * from './Category';
export * from './Account';
export * from './RoomAccount';
export * from './Storage';
+export * from './Core';
export * from './BaseModels';
diff --git a/tests/angular2/src/app/shared/sdk/sdk.module.ts b/tests/angular2/src/app/shared/sdk/sdk.module.ts
index a40e8505..dd88517b 100644
--- a/tests/angular2/src/app/shared/sdk/sdk.module.ts
+++ b/tests/angular2/src/app/shared/sdk/sdk.module.ts
@@ -53,7 +53,8 @@ import {
CategoryApi,
AccountApi,
RoomAccountApi,
- StorageApi
+ StorageApi,
+ CoreApi
} from './services/index';
@NgModule({
@@ -81,8 +82,9 @@ export class SDKModule {
CategoryApi,
AccountApi,
RoomAccountApi,
- StorageApi
+ StorageApi,
+ CoreApi
]
};
}
-}
\ No newline at end of file
+}
diff --git a/tests/angular2/src/app/shared/sdk/services/core/base.service.ts b/tests/angular2/src/app/shared/sdk/services/core/base.service.ts
index a49f0529..53e55b19 100644
--- a/tests/angular2/src/app/shared/sdk/services/core/base.service.ts
+++ b/tests/angular2/src/app/shared/sdk/services/core/base.service.ts
@@ -86,4 +86,4 @@ export abstract class BaseLoopBackApi {
.map(res => (res.text() != "" ? res.json() : {}))
.catch(this.errorHandler.handleError);
}
-}
\ No newline at end of file
+}
diff --git a/tests/angular2/src/app/shared/sdk/services/custom/Core.ts b/tests/angular2/src/app/shared/sdk/services/custom/Core.ts
new file mode 100644
index 00000000..a8d56be0
--- /dev/null
+++ b/tests/angular2/src/app/shared/sdk/services/custom/Core.ts
@@ -0,0 +1,105 @@
+/* tslint:disable */
+import { Injectable, Inject, Optional } from '@angular/core';
+import { Http, Response } from '@angular/http';
+import { BaseLoopBackApi } from '../core/base.service';
+import { LoopBackConfig } from '../../lb.config';
+import { LoopBackAuth } from '../core/auth.service';
+import { JSONSearchParams } from '../core/search.params';
+import { ErrorHandler } from '../core/error.service';
+import { Core } from '../../models/Core';
+import { LoopBackFilter } from '../../models/BaseModels'
+import { Subject } from 'rxjs/Subject';
+import 'rxjs/add/observable/throw';
+import 'rxjs/add/operator/map';
+import 'rxjs/add/operator/catch';
+import 'rxjs/add/operator/share';
+
+/**
+ * Api services for the `Core` model.
+ */
+@Injectable()
+export class CoreApi extends BaseLoopBackApi {
+
+ constructor(
+ @Inject(Http) http: Http,
+ @Inject(LoopBackAuth) protected auth: LoopBackAuth,
+ @Inject(JSONSearchParams) protected searchParams: JSONSearchParams,
+ @Optional() @Inject(ErrorHandler) errorHandler: ErrorHandler
+ ) {
+ super(http, auth, searchParams, errorHandler);
+ }
+
+ /**
+ *
+ * (The remote method definition does not provide any description.)
+ *
+ *
+ * @param string path
+ *
+ * @param object data Request data.
+ *
+ * This method expects a subset of model properties as request parameters.
+ *
+ * @returns object An empty reference that will be
+ * populated with the actual data once the response is returned
+ * from the server.
+ *
+ *
+ * (The remote method definition does not provide any description.
+ * This usually means the response is a `Core` object.)
+ *
+ */
+ public run(path: any = undefined, body: any = undefined) {
+ let method: string = "POST";
+ let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
+ "/cores/run/:path";
+ let routeParams: any = {
+ path: path
+ };
+ let postBody: any = {
+ body: body
+ };
+ let urlParams: any = {};
+ if (body) urlParams.body = body;
+ let result = this.request(method, url, routeParams, urlParams, postBody);
+ return result;
+ }
+
+ /**
+ *
+ * (The remote method definition does not provide any description.)
+ *
+ *
+ * @param object data Request data.
+ *
+ * This method expects a subset of model properties as request parameters.
+ *
+ * @returns object An empty reference that will be
+ * populated with the actual data once the response is returned
+ * from the server.
+ *
+ * This method returns no data.
+ */
+ public invoke(request: any = undefined) {
+ let method: string = "POST";
+ let url: string = LoopBackConfig.getPath() + "/" + LoopBackConfig.getApiVersion() +
+ "/cores/invoke";
+ let routeParams: any = {};
+ let postBody: any = {
+ request: request
+ };
+ let urlParams: any = {};
+ if (request) urlParams.request = request;
+ let result = this.request(method, url, routeParams, urlParams, postBody);
+ return result;
+ }
+
+
+ /**
+ * The name of the model represented by this $resource,
+ * i.e. `Core`.
+ */
+ public getModelName() {
+ return "Core";
+ }
+}
diff --git a/tests/angular2/src/app/shared/sdk/services/custom/index.ts b/tests/angular2/src/app/shared/sdk/services/custom/index.ts
index 8d2b380e..8ebe10d7 100644
--- a/tests/angular2/src/app/shared/sdk/services/custom/index.ts
+++ b/tests/angular2/src/app/shared/sdk/services/custom/index.ts
@@ -9,3 +9,4 @@ export * from './Category';
export * from './Account';
export * from './RoomAccount';
export * from './Storage';
+export * from './Core';