Skip to content

Can include model schema definitions in generated $resources #194

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@ ejs.filters.q = function(obj) {
* @returns {string} The generated javascript code.
* @header generateServices
*/
module.exports = function generateServices(app, ngModuleName, apiUrl) {
module.exports = function generateServices(app, ngModuleName, apiUrl, includeSchemas) {
ngModuleName = ngModuleName || 'lbServices';
apiUrl = apiUrl || '/';

var models = describeModels(app);

if (includeSchemas === true) {
for (var modelName in models) {
var modelProperties = app.models[modelName].definition.rawProperties;
models[modelName].modelSchema = {
name: modelName,
properties: modelProperties
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ; at the end of the statement.

}
}
var servicesTemplate = fs.readFileSync(
require.resolve('./services.template.ejs'),
{ encoding: 'utf-8' }
Expand Down
12 changes: 12 additions & 0 deletions lib/services.template.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ module.factory(
<% }); // forEach methods name -%>
<% } // for each scope -%>

<% if (meta.modelSchema) { -%>
/**
* @ngdoc object
* @name <%-: moduleName %>.<%- modelName %>#schema
* @propertyOf <%-: moduleName %>.<%- modelName %>
* @description
* The schema of the model represented by this $resource
*/
R.schema = <%- JSON.stringify(meta.modelSchema, null, '\t') -%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 2 spaces for indentation for consistency, we don't use tabs anywhere else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add ; at the end of the generated statement.

R.schema = <%- ... -%>;



<% } -%>
return R;
}]);

Expand Down