moleculer-auto-openapi icon indicating copy to clipboard operation
moleculer-auto-openapi copied to clipboard

Exclude some files and some folders inside services folder

Open deepdil-sp opened this issue 7 months ago • 1 comments

how to exclude some folders, some files from openapi. i dont want to include db folders service and openapi.service files @grinat @intech @jodysimpson @krifamed @randomnerd

deepdil-sp avatar Nov 28 '23 14:11 deepdil-sp

You can override in openapi.service.js fetchServicesWithActions method and filter services/actions:

const Openapi = require("moleculer-auto-openapi");

module.exports = {
  name: 'openapi',
  mixins: [Openapi],
  methods: {
      async fetchServicesWithActions() {
        const services = await this.broker.call("$node.services", {
           withActions: true,
           onlyLocal: this.settings.onlyLocal,
         });

        // TODO
        // your filters and etc...

        return services;
      },
  }
}


You can create 2 web service - private and public. And set collectOnlyFromWebServices: [apiPublic] in openapi scheme. Example:

apiPublic.service.js

const ApiGateway = require("moleculer-web");

module.exports = {
  name: `apiPublic`,
  mixins: [ApiGateway],
  settings: {
    port: 2000,
    routes: [
      {
        path: '/api/public',
        aliases: {
          'POST /login': 'auth.login',
        },
      },
     // moleculer-auto-openapi routes
      {
        path: '/api/openapi',
        aliases: {
          'GET /openapi.json': 'openapi.generateDocs', // swagger scheme
          'GET /ui': 'openapi.ui', // ui
          'GET /assets/:file': 'openapi.assets', // js/css files
        },
      },
    ],
  },
};

apiPrivate.service.js

const ApiGateway = require("moleculer-web");

module.exports = {
  name: `apiPrivate`,
  mixins: [ApiGateway],
  settings: {
    port: 2001,
    routes: [
      {
        path: '/api/private',
        aliases: {
          'POST /login': 'admin.login',
        },
      },
    ],
  },
};

openapi.service.js

const Openapi = require("moleculer-auto-openapi");

module.exports = {
  name: 'openapi',
  mixins: [Openapi],
  settings: {
     // show route only from apiPublic web service
     collectOnlyFromWebServices: [`apiPublic`],
  },
}

grinat avatar Jan 09 '24 07:01 grinat