loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Swagger: skipping unknown type "$new_AccessToken".

Open agung-wete opened this issue 9 years ago • 30 comments

Description/Steps to reproduce

Fresh install loopback, then run node .

Expected result

No error

Result

Swagger: skipping unknown type "$new_AccessToken".
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer

Additional information

Version: loopback 3.11.1 loopback-swagger 4.3.0 loopback-explorer 2.0.2

win32 x64 6.11.3

agung-wete avatar Sep 13 '17 23:09 agung-wete

Same here.

I tested with some versions and problem only appears in loopback >= 3.14.0

i'm back at 3.13.0 as temporary solution

danielbastos avatar Oct 21 '17 19:10 danielbastos

Not sure if its relevant to everyones situation, however i ran into this issue when running with docker. I had a docker-compose file that was running the container. In the docker-compose file I was running the container with user "Node". Removing this user and using the default user made the issue go away.

el-davo avatar Oct 21 '17 21:10 el-davo

Still present in 3.16.0... @bajtos - I would like to fix it, but I can't find any reference of where and what is this causing...

george-oakling avatar Oct 25 '17 13:10 george-oakling

not impressed by the non feedback on this...

maximedubois avatar Oct 25 '17 13:10 maximedubois

I’ll take a look today.

raymondfeng avatar Oct 25 '17 14:10 raymondfeng

From what I remember about our swagger spec generator, we are intentionally omitting type definitions that are not used by any publicly exposed methods, to prevent the swagger spec to be polluted with built-in models like Role and ACL that are known to LoopBack runtime, but that are not relevant for the REST API.

I suspect the code detecting relations (and deciding which models to include) does not know that $new_AccessToken definition is a part of AccessToken model. I may be wrong though, I'll leave it up to you @raymondfeng to investigate more.

bajtos avatar Oct 26 '17 14:10 bajtos

Thank you guys!

george-oakling avatar Oct 26 '17 14:10 george-oakling

works for me. Thank you @raymondfeng @bajtos

agung-wete avatar Nov 04 '17 12:11 agung-wete

I am still reproducing this error with dynamically created models on boot time.

PACKAGE: { "compression": "^1.0.3", "cors": "^2.5.2", "helmet": "^1.3.0", "loopback": "^3.17.0", "loopback-boot": "^3.1.0", "loopback-swagger" : "^5.5.0", "loopback-component-explorer": "^5.2.0", "serve-favicon": "^2.0.1", "strong-error-handler": "^2.0.0" }

CODE:

'use strict';

var loopback = require('loopback');
var boot = require('loopback-boot');

var app = module.exports = loopback({localRegistry: true});

var ds = loopback.createDataSource('postgresql', {
  "host": "localhost",
  "port": 5432,
  "database": "db",
  "username": "user",
  "password": "pass"
});

var acceptedTables = [
  'users',
  'organisation',
  'expectation',
  'location',
  'tags',
  'telephone',
  'email',
  'experience',
  'project',
  'skill',
  'education',
  'language',
  'activity',
  'hobby',
  'social',
  'link',
  'document',
  'user_organisation',
  'users_data',
  'document_permissions',
  'tag_relations'
]

var modelDefinitionsConf = {views: true};
var modelConfig = { schema: 'public' };

function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

function generateModelName(modelName){
  var nameArr = modelName.split(/_|-/);
  var nameArr = nameArr.map(function(el){ return el[0].toUpperCase() + el.substr(1); });
  return nameArr.join('');
}

app.start = function() {
  return app.listen(function() {
    app.emit('started');
    var baseUrl = app.get('url').replace(/\/$/, '');
    ds.discoverModelDefinitions(modelDefinitionsConf, function(err, data){
      for (var el in data) {
        (function(modelName){
          if (acceptedTables.indexOf(modelName) >= 0) {
              ds.discoverSchema(modelName, function (err, schema) {
                var model = ds.createModel(schema.name, schema.properties, schema.options);
                app.model(model, {public : true, dataSource: ds });
              })
          }
        })(data[el].name)
      }
    });
    if (app.get('loopback-component-explorer')) {
      var explorerPath = app.get('loopback-component-explorer').mountPath;
      console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
    }
  });
};

// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
  if (err) throw err;

  // start the server if `$ node server.js`
  if (require.main === module)
    app.start();
});

twboc avatar Dec 06 '17 14:12 twboc

@twboc could you please open a new issue for the problem you are experiencing and be more specific about the kind of error you are seeing? This issue is specifically about $new_AccessToken, which is not part of your discovered/auto-imported models AFAICT.

I am closing this issue as fixed.

bajtos avatar Dec 08 '17 14:12 bajtos