feathersjs-ecosystem / feathers-swagger

Add documentation to your FeatherJS services and feed them to Swagger UI.
MIT License
225 stars 62 forks source link

not work with service #138

Closed alexandrmiee closed 5 years ago

alexandrmiee commented 5 years ago

feathers generate service

in file user.service.js

// Initializes the `user` service on path `/user`
const createService = require('feathers-sequelize');
const createModel = require('../../models/user.model');
const hooks = require('./user.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('/user', createService(options));

  const user = createService(options)
  user.docs = {
    description: 'A service to send and receive messages',
  }
  app.use('/user', user)

};

in app.js

app.configure(swagger({
  docsPath: '/docs',
  uiIndex: true, // no need for src/docs.html
  info: {
    title: 'A test',
    description: 'A description'
  }
}));
console.log (app.docs);

console.log result

{ paths: {},
  definitions: {},
  swagger: '2.0',
  schemes: [ 'http' ],
  tags: [],
  basePath: '',
  docsPath: '/docs',
  consumes: [ 'application/json' ],
  produces: [ 'application/json' ],
  info: { title: 'A test', description: 'A description' },
  ignore: { tags: [] },
  uiIndex: true }

http://localhost:3030/docs/?url=/docs

No operations defined in spec!

daffl commented 5 years ago

This plugins needs to be set up before any service (usually app.configure(services)).

alexandrmiee commented 5 years ago

Thanks! It works now.