From 7932d75c447f0ed4a916582192de34ff74a23bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 15 Aug 2016 10:57:02 +0200 Subject: [PATCH] Revert globalization of Swagger descriptions --- common/models/user.js | 16 +++++----- lib/model.js | 47 ++++++++++++++-------------- lib/persisted-model.js | 69 +++++++++++++++++------------------------- 3 files changed, 60 insertions(+), 72 deletions(-) diff --git a/common/models/user.js b/common/models/user.js index b857e38e..210df6db 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -660,12 +660,12 @@ module.exports = function(User) { UserModel.remoteMethod( 'login', { - description: g.f('Login a user with username/email and password.'), + description: 'Login a user with username/email and password.', accepts: [ {arg: 'credentials', type: 'object', required: true, http: {source: 'body'}}, {arg: 'include', type: ['string'], http: {source: 'query'}, - description: g.f('Related objects to include in the response. ' + - 'See the description of return value for more details.') }, + description: 'Related objects to include in the response. ' + + 'See the description of return value for more details.' }, ], returns: { arg: 'accessToken', type: 'object', root: true, @@ -683,15 +683,15 @@ module.exports = function(User) { UserModel.remoteMethod( 'logout', { - description: g.f('Logout a user with access token.'), + description: 'Logout a user with access token.', accepts: [ {arg: 'access_token', type: 'string', required: true, http: function(ctx) { var req = ctx && ctx.req; var accessToken = req && req.accessToken; var tokenID = accessToken && accessToken.id; return tokenID; - }, description: g.f('Do not supply this argument, it is automatically extracted ' + - 'from request headers.'), + }, description: 'Do not supply this argument, it is automatically extracted ' + + 'from request headers.', }, ], http: {verb: 'all'} @@ -701,7 +701,7 @@ module.exports = function(User) { UserModel.remoteMethod( 'confirm', { - description: g.f('Confirm a user registration with email verification token.'), + description: 'Confirm a user registration with email verification token.', accepts: [ {arg: 'uid', type: 'string', required: true}, {arg: 'token', type: 'string', required: true}, @@ -714,7 +714,7 @@ module.exports = function(User) { UserModel.remoteMethod( 'resetPassword', { - description: g.f('Reset password for a user with email.'), + description: 'Reset password for a user with email.', accepts: [ {arg: 'options', type: 'object', required: true, http: {source: 'body'}} ], diff --git a/lib/model.js b/lib/model.js index 3b5fe4c4..5651c0e7 100644 --- a/lib/model.js +++ b/lib/model.js @@ -13,6 +13,7 @@ var assert = require('assert'); var RemoteObjects = require('strong-remoting'); var SharedClass = require('strong-remoting').SharedClass; var extend = require('util')._extend; +var format = require('util').format; module.exports = function(registry) { @@ -452,7 +453,7 @@ module.exports = function(registry) { http: {verb: 'get', path: '/' + pathName}, accepts: {arg: 'refresh', type: 'boolean', http: {source: 'query'}}, accessType: 'READ', - description: g.f('Fetches belongsTo relation %s.', relationName), + description: format('Fetches belongsTo relation %s.', relationName), returns: {arg: relationName, type: modelName, root: true}, }, fn); }; @@ -476,7 +477,7 @@ module.exports = function(registry) { isStatic: false, http: {verb: 'get', path: '/' + pathName}, accepts: {arg: 'refresh', type: 'boolean', http: {source: 'query'}}, - description: g.f('Fetches hasOne relation %s.', relationName), + description: format('Fetches hasOne relation %s.', relationName), accessType: 'READ', returns: {arg: relationName, type: relation.modelTo.modelName, root: true}, rest: {after: convertNullToNotFoundError.bind(null, toModelName)} @@ -486,7 +487,7 @@ module.exports = function(registry) { isStatic: false, http: {verb: 'post', path: '/' + pathName}, accepts: {arg: 'data', type: toModelName, http: {source: 'body'}}, - description: g.f('Creates a new instance in %s of this model.', relationName), + description: format('Creates a new instance in %s of this model.', relationName), accessType: 'WRITE', returns: {arg: 'data', type: toModelName, root: true} }); @@ -495,7 +496,7 @@ module.exports = function(registry) { isStatic: false, http: {verb: 'put', path: '/' + pathName}, accepts: {arg: 'data', type: toModelName, http: {source: 'body'}}, - description: g.f('Update %s of this model.', relationName), + description: format('Update %s of this model.', relationName), accessType: 'WRITE', returns: {arg: 'data', type: toModelName, root: true} }); @@ -503,7 +504,7 @@ module.exports = function(registry) { define('__destroy__' + relationName, { isStatic: false, http: {verb: 'delete', path: '/' + pathName}, - description: g.f('Deletes %s of this model.', relationName), + description: format('Deletes %s of this model.', relationName), accessType: 'WRITE', }); }; @@ -517,10 +518,10 @@ module.exports = function(registry) { isStatic: false, http: {verb: 'get', path: '/' + pathName + '/:fk'}, accepts: {arg: 'fk', type: 'any', - description: g.f('Foreign key for %s', relationName), + description: format('Foreign key for %s', relationName), required: true, http: {source: 'path'}}, - description: g.f('Find a related item by id for %s.', relationName), + description: format('Find a related item by id for %s.', relationName), accessType: 'READ', returns: {arg: 'result', type: toModelName, root: true}, rest: {after: convertNullToNotFoundError.bind(null, toModelName)} @@ -531,10 +532,10 @@ module.exports = function(registry) { isStatic: false, http: {verb: 'delete', path: '/' + pathName + '/:fk'}, accepts: { arg: 'fk', type: 'any', - description: g.f('Foreign key for %s', relationName), + description: format('Foreign key for %s', relationName), required: true, http: {source: 'path'}}, - description: g.f('Delete a related item by id for %s.', relationName), + description: format('Delete a related item by id for %s.', relationName), accessType: 'WRITE', returns: [] }, destroyByIdFunc); @@ -545,12 +546,12 @@ module.exports = function(registry) { http: {verb: 'put', path: '/' + pathName + '/:fk'}, accepts: [ {arg: 'fk', type: 'any', - description: g.f('Foreign key for %s', relationName), + description: format('Foreign key for %s', relationName), required: true, http: { source: 'path' }}, {arg: 'data', type: toModelName, http: {source: 'body'}}, ], - description: g.f('Update a related item by id for %s.', relationName), + description: format('Update a related item by id for %s.', relationName), accessType: 'WRITE', returns: {arg: 'result', type: toModelName, root: true} }, updateByIdFunc); @@ -569,10 +570,10 @@ module.exports = function(registry) { isStatic: false, http: {verb: 'put', path: '/' + pathName + '/rel/:fk'}, accepts: [{ arg: 'fk', type: 'any', - description: g.f('Foreign key for %s', relationName), + description: format('Foreign key for %s', relationName), required: true, http: {source: 'path'}}].concat(accepts), - description: g.f('Add a related item by id for %s.', relationName), + description: format('Add a related item by id for %s.', relationName), accessType: 'WRITE', returns: {arg: relationName, type: modelThrough.modelName, root: true} }, addFunc); @@ -582,10 +583,10 @@ module.exports = function(registry) { isStatic: false, http: {verb: 'delete', path: '/' + pathName + '/rel/:fk'}, accepts: {arg: 'fk', type: 'any', - description: g.f('Foreign key for %s', relationName), + description: format('Foreign key for %s', relationName), required: true, http: {source: 'path'}}, - description: g.f('Remove the %s relation to an item by id.', relationName), + description: format('Remove the %s relation to an item by id.', relationName), accessType: 'WRITE', returns: [] }, removeFunc); @@ -597,10 +598,10 @@ module.exports = function(registry) { isStatic: false, http: {verb: 'head', path: '/' + pathName + '/rel/:fk'}, accepts: {arg: 'fk', type: 'any', - description: g.f('Foreign key for %s', relationName), + description: format('Foreign key for %s', relationName), required: true, http: {source: 'path'}}, - description: g.f('Check the existence of %s relation to an item by id.', relationName), + description: format('Check the existence of %s relation to an item by id.', relationName), accessType: 'READ', returns: {arg: 'exists', type: 'boolean', root: true}, rest: { @@ -643,7 +644,7 @@ module.exports = function(registry) { isStatic: isStatic, http: {verb: 'get', path: '/' + pathName}, accepts: {arg: 'filter', type: 'object'}, - description: g.f('Queries %s of %s.', scopeName, this.modelName), + description: format('Queries %s of %s.', scopeName, this.modelName), accessType: 'READ', returns: {arg: scopeName, type: [toModelName], root: true} }); @@ -652,7 +653,7 @@ module.exports = function(registry) { isStatic: isStatic, http: {verb: 'post', path: '/' + pathName}, accepts: {arg: 'data', type: toModelName, http: {source: 'body'}}, - description: g.f('Creates a new instance in %s of this model.', scopeName), + description: format('Creates a new instance in %s of this model.', scopeName), accessType: 'WRITE', returns: {arg: 'data', type: toModelName, root: true} }); @@ -660,7 +661,7 @@ module.exports = function(registry) { define('__delete__' + scopeName, { isStatic: isStatic, http: {verb: 'delete', path: '/' + pathName}, - description: g.f('Deletes all %s of this model.', scopeName), + description: format('Deletes all %s of this model.', scopeName), accessType: 'WRITE', }); @@ -668,8 +669,8 @@ module.exports = function(registry) { isStatic: isStatic, http: {verb: 'get', path: '/' + pathName + '/count'}, accepts: {arg: 'where', type: 'object', - description: g.f('Criteria to match model instances')}, - description: g.f('Counts %s of %s.', scopeName, this.modelName), + description: 'Criteria to match model instances'}, + description: format('Counts %s of %s.', scopeName, this.modelName), accessType: 'READ', returns: {arg: 'count', type: 'number'} }); @@ -718,7 +719,7 @@ module.exports = function(registry) { acceptArgs = [ { arg: paramName, type: 'any', http: { source: 'path' }, - description: g.f('Foreign key for %s.', relation.name), + description: format('Foreign key for %s.', relation.name), required: true, }, ]; diff --git a/lib/persisted-model.js b/lib/persisted-model.js index 534a41e0..d3e9a6fe 100644 --- a/lib/persisted-model.js +++ b/lib/persisted-model.js @@ -16,18 +16,6 @@ var debug = require('debug')('loopback:persisted-model'); var PassThrough = require('stream').PassThrough; var utils = require('./utils'); -// workaround for low performance of strong-globalize -// see https://github.com/strongloop/strong-globalize/issues/66 -var stringCache = Object.create(null); -g.s = function(str) { - assert.equal(1, arguments.length, 'g.s() does not support parameters'); - if (str in stringCache) - return stringCache[str]; - var result = g.t(str); - stringCache[str] = result; - return result; -}; - module.exports = function(registry) { var Model = registry.getModel('Model'); @@ -627,7 +615,7 @@ module.exports = function(registry) { } setRemoting(PersistedModel, 'create', { - description: g.s('Create a new instance of the model and persist it into the data source.'), + description: 'Create a new instance of the model and persist it into the data source.', accessType: 'WRITE', accepts: {arg: 'data', type: 'object', description: 'Model instance data', http: {source: 'body'}}, returns: {arg: 'data', type: typeName, root: true}, @@ -636,7 +624,7 @@ module.exports = function(registry) { var upsertOptions = { aliases: ['patchOrCreate', 'updateOrCreate'], - description: g.s('Patch an existing model instance or insert a new one into the data source.'), + description: 'Patch an existing model instance or insert a new one into the data source.', accessType: 'WRITE', accepts: { arg: 'data', type: 'object', http: { source: 'body' }, description: 'Model instance data' }, @@ -665,7 +653,7 @@ module.exports = function(registry) { setRemoting(PersistedModel, 'replaceOrCreate', replaceOrCreateOptions); setRemoting(PersistedModel, 'exists', { - description: g.s('Check whether a model instance exists in the data source.'), + description: 'Check whether a model instance exists in the data source.', accessType: 'READ', accepts: {arg: 'id', type: 'any', description: 'Model id', required: true}, returns: {arg: 'exists', type: 'boolean'}, @@ -696,13 +684,13 @@ module.exports = function(registry) { }); setRemoting(PersistedModel, 'findById', { - description: g.s('Find a model instance by {{id}} from the data source.'), + description: 'Find a model instance by {{id}} from the data source.', accessType: 'READ', accepts: [ { arg: 'id', type: 'any', description: 'Model id', required: true, http: {source: 'path'}}, { arg: 'filter', type: 'object', - description: g.s('Filter defining fields and include') }, + description: 'Filter defining fields and include' }, ], returns: {arg: 'data', type: typeName, root: true}, http: {verb: 'get', path: '/:id'}, @@ -729,7 +717,7 @@ module.exports = function(registry) { setRemoting(PersistedModel, 'replaceById', replaceByIdOptions); setRemoting(PersistedModel, 'find', { - description: g.s('Find all instances of the model matched by filter from the data source.'), + description: 'Find all instances of the model matched by filter from the data source.', accessType: 'READ', accepts: {arg: 'filter', type: 'object', description: 'Filter defining fields, where, include, order, offset, and limit'}, returns: {arg: 'data', type: [typeName], root: true}, @@ -737,7 +725,7 @@ module.exports = function(registry) { }); setRemoting(PersistedModel, 'findOne', { - description: g.s('Find first instance of the model matched by filter from the data source.'), + description: 'Find first instance of the model matched by filter from the data source.', accessType: 'READ', accepts: {arg: 'filter', type: 'object', description: 'Filter defining fields, where, include, order, offset, and limit'}, returns: {arg: 'data', type: typeName, root: true}, @@ -746,7 +734,7 @@ module.exports = function(registry) { }); setRemoting(PersistedModel, 'destroyAll', { - description: g.s('Delete all matching records.'), + description: 'Delete all matching records.', accessType: 'WRITE', accepts: {arg: 'where', type: 'object', description: 'filter.where object'}, returns: { @@ -761,17 +749,17 @@ module.exports = function(registry) { setRemoting(PersistedModel, 'updateAll', { aliases: ['update'], - description: g.s('Update instances of the model matched by {{where}} from the data source.'), + description: 'Update instances of the model matched by {{where}} from the data source.', accessType: 'WRITE', accepts: [ {arg: 'where', type: 'object', http: { source: 'query'}, - description: g.s('Criteria to match model instances')}, + description: 'Criteria to match model instances'}, {arg: 'data', type: 'object', http: {source: 'body'}, - description: g.s('An object of model property name/value pairs')}, + description: 'An object of model property name/value pairs'}, ], returns: { arg: 'count', - description: g.s('The number of instances updated'), + description: 'The number of instances updated', type: 'object', root: true }, @@ -780,7 +768,7 @@ module.exports = function(registry) { setRemoting(PersistedModel, 'deleteById', { aliases: ['destroyById', 'removeById'], - description: g.s('Delete a model instance by {{id}} from the data source.'), + description: 'Delete a model instance by {{id}} from the data source.', accessType: 'WRITE', accepts: {arg: 'id', type: 'any', description: 'Model id', required: true, http: {source: 'path'}}, @@ -789,7 +777,7 @@ module.exports = function(registry) { }); setRemoting(PersistedModel, 'count', { - description: g.s('Count instances of the model matched by where from the data source.'), + description: 'Count instances of the model matched by where from the data source.', accessType: 'READ', accepts: {arg: 'where', type: 'object', description: 'Criteria to match model instances'}, returns: {arg: 'count', type: 'number'}, @@ -798,7 +786,7 @@ module.exports = function(registry) { var updateAttributesOptions = { aliases: ['patchAttributes'], - description: g.s('Patch attributes for a model instance and persist it into the data source.'), + description: 'Patch attributes for a model instance and persist it into the data source.', accessType: 'WRITE', accepts: { arg: 'data', type: 'object', http: { source: 'body' }, description: 'An object of model property name/value pairs' }, @@ -814,7 +802,7 @@ module.exports = function(registry) { if (options.trackChanges || options.enableRemoteReplication) { setRemoting(PersistedModel, 'diff', { - description: g.s('Get a set of deltas and conflicts since the given checkpoint.'), + description: 'Get a set of deltas and conflicts since the given checkpoint.', accessType: 'READ', accepts: [ {arg: 'since', type: 'number', description: 'Find deltas since this checkpoint'}, @@ -826,8 +814,8 @@ module.exports = function(registry) { }); setRemoting(PersistedModel, 'changes', { - description: g.s('Get the changes to a model since a given checkpoint.' + - 'Provide a filter object to reduce the number of results returned.'), + description: 'Get the changes to a model since a given checkpoint.' + + 'Provide a filter object to reduce the number of results returned.', accessType: 'READ', accepts: [ {arg: 'since', type: 'number', description: 'Only return changes since this checkpoint'}, @@ -838,7 +826,7 @@ module.exports = function(registry) { }); setRemoting(PersistedModel, 'checkpoint', { - description: g.s('Create a checkpoint.'), + description: 'Create a checkpoint.', // The replication algorithm needs to create a source checkpoint, // even though it is otherwise not making any source changes. // We need to allow this method for users that don't have full @@ -849,14 +837,14 @@ module.exports = function(registry) { }); setRemoting(PersistedModel, 'currentCheckpoint', { - description: g.s('Get the current checkpoint.'), + description: 'Get the current checkpoint.', accessType: 'READ', returns: {arg: 'checkpoint', type: 'object', root: true}, http: {verb: 'get', path: '/checkpoint'} }); setRemoting(PersistedModel, 'createUpdates', { - description: g.s('Create an update list from a delta list.'), + description: 'Create an update list from a delta list.', // This operation is read-only, it does not change any local data. // It is called by the replication algorithm to compile a list // of changes to apply on the target. @@ -867,14 +855,14 @@ module.exports = function(registry) { }); setRemoting(PersistedModel, 'bulkUpdate', { - description: g.s('Run multiple updates at once. Note: this is not atomic.'), + description: 'Run multiple updates at once. Note: this is not atomic.', accessType: 'WRITE', accepts: {arg: 'updates', type: 'array'}, http: {verb: 'post', path: '/bulk-update'} }); setRemoting(PersistedModel, 'findLastChange', { - description: g.s('Get the most recent change record for this instance.'), + description: 'Get the most recent change record for this instance.', accessType: 'READ', accepts: { arg: 'id', type: 'any', required: true, http: { source: 'path' }, @@ -885,10 +873,9 @@ module.exports = function(registry) { }); setRemoting(PersistedModel, 'updateLastChange', { - description: [ - g.s('Update the properties of the most recent change record ' + - 'kept for this instance.'), - ], + description: + 'Update the properties of the most recent change record ' + + 'kept for this instance.', accessType: 'WRITE', accepts: [ { @@ -897,7 +884,7 @@ module.exports = function(registry) { }, { arg: 'data', type: 'object', http: {source: 'body'}, - description: g.s('An object of Change property name/value pairs'), + description: 'An object of Change property name/value pairs', }, ], returns: { arg: 'result', type: this.Change.modelName, root: true }, @@ -923,7 +910,7 @@ module.exports = function(registry) { } setRemoting(PersistedModel, 'createChangeStream', { - description: g.s('Create a change stream.'), + description: 'Create a change stream.', accessType: 'READ', http: [ {verb: 'post', path: '/change-stream'},