question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Attached model schema not available in app.js using crow generated service

See original GitHub issue

What did I do?

  1. running feathers v4
  2. app with multiple fully functioning swagger model-schemas (services generated using feathers v3)
  3. generated a new service using feather v4
  4. added a model schema to service.model for that new service
  5. confirmed the model schema is generated and attached to the service (in the service file)

What happens?

I checked the Swagger UI and not model schema for the newly generated service. Looking further it appears service.model is not available/undefined in app.js whereas it is for all other services that were generated using the feathers v3 cli.

as a workaround I keep using the v3 service style for now.

app.js

The console.log message below indicates the exact point where things go amiss, undefined for the v4 service. Interesting: the console.debug at the very bottom does show the model schema so I am sure it is added.

app.js

// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
app.configure(authentication);

// Set up swagger (OpenAPI)
app.configure(
  swagger({
    openApiVersion: 3,
    uiIndex: true,
    docsPath: '/docs',
    docsJsonPath: '/docs/schema',
    specs: {
      info: {
        title: 'P2 API',
        description: 'A description',
        version: '0.0.1',
      },
    },
    defaults: {
      schemasGenerator(service, model, modelName) {
        if (model === 'projects') {
          console.log(service.model); // not set for the v4 service
        }

        return {
          [model]: service.model,
          [`${model}_list`]: {
            title: `${modelName} list`,
            type: 'array',
            items: { $ref: `#/components/schemas/${model}` },
          },
        };
      },
    },
  }),
);

// Set up our services (see `services/index.js`)
app.configure(services);

console.log('------------------------');
console.log(app.service('projects').model);

Services

v3 generated projects service (working)

service.model set here is available in app.js for use by the SchemaGenerator.

// Initializes the `projects` service on path `/projects`
const createService = require('feathers-sequelize');
const createModel = require('../../models/projects.model');
const hooks = require('./projects.hooks');

module.exports = function init(app) {
  const Model = createModel(app);
  const paginate = app.get('paginate');

  const options = {
    Model,
    paginate,
  };

  // create service
  const service = createService(options);

  // generate OpenAPI 3.0 model schema as required by feathers-swagger
  service.model = app
    .get('jsonSchemaManager')
    .generate(Model, app.get('openApi3Strategy'));

  // get initialized service so we can register hooks
  app.use('/projects', service);

  // register hooks
  app.service('projects').hooks(hooks);
};

v4 generated projects service (not working)

service.model set here is NOT available in app.js for use by the SchemaGenerator.

// Initializes the `projects` service on path `/projects`
const { Projects } = require('./projects.class');
const createModel = require('../../models/projects.model');
const hooks = require('./projects.hooks');

module.exports = function (app) {
  const Model = createModel(app);
  const paginate = app.get('paginate');

  const options = {
    Model,
    paginate
  };

  // Initialize our service with any options it requires
  app.use('/projects', new Projects(options, app));

  // Get our initialized service so that we can register hooks
  const service = app.service('projects');

  // generate OpenAPI 3.0 model schema as required by feathers-swagger
  service.model = app
    .get('jsonSchemaManager')
    .generate(Model, app.get('openApi3Strategy'));

  service.hooks(hooks);
};

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:25 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
bravo-kernelcommented, Feb 29, 2020

Never used mongoose

1reaction
Mairucommented, Sep 25, 2019

Yes it was theoretically for sequelize, I just tested it with with NeDB, there it was working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Application - Feathers.js
The core @feathersjs/feathers module provides the ability to initialize a new Feathers application instance. It works in Node, React Native and ...
Read more >
schema has not been registered for model error showing
Try Changing the line from. const blogModel = mongoose.model('Blog'). to. const blogModel = require('../model/Blog.js').
Read more >
Developing Applications with Oracle Visual Builder
Switch Schemas Used During an App's Lifecycle. 4-86. 5 Work with Services. What Are Service Connections? 5-1. What Are Backends?
Read more >
npmsearchfullcat_npm143.txt - GitHub
=mike.hemesath 2011-07-21 0.3.3 json node activepush Web push service built ... 0.1.0 alamid-schema Extendable mongoose-like schemas for node.js and the ...
Read more >
Error in react app: "It looks like you are trying to ... - MongoDB
I suspect you may have an axios.get() request that is trying to fetch a Mongoose model or MongoDB URI (which would result in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found