Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude remote services #191

Closed
dekelev opened this issue Apr 4, 2020 · 5 comments
Closed

Exclude remote services #191

dekelev opened this issue Apr 4, 2020 · 5 comments
Labels

Comments

@dekelev
Copy link
Member

dekelev commented Apr 4, 2020

When working with remote services using the feathers-distributed lib, the addService method in feathers-swagger gets called for each service, local or remote.

I want to exclude all the remote services from swagger. in order to do so, I've tried using the include/ignore options, but I don't have any services path list.

I've tried to add a similar addService method to the mixin, right before feathers-swagger addService method, and collect paths to include/ignore, but the include/ignore array is cloned in feathers-swagger when the library is initialized.

I've ended up replacing feathers-swagger addService mixin method with a proxy method that calls feathers-swagger addService method only for local services, when service.remote is false or undefined.

Is there any better way to do this?

@dekelev dekelev changed the title Excluding remote services Ignore remote services Apr 4, 2020
@dekelev dekelev changed the title Ignore remote services Exclude remote services Apr 4, 2020
@Mairu
Copy link
Collaborator

Mairu commented Apr 4, 2020

Well there is also the possibility to ignore by tags.

The tag for a service can be set via docs property.

Another possibility would be to register the services you don't want to have in swagger before the use of feathers-swagger initialization.

@dekelev
Copy link
Member Author

dekelev commented Apr 4, 2020

I've tried that, but it also requires me to check if service.remote is true in the mixin method in order to set the tag on the service.docs. it also group tags in the UI, so all the services with tag internal will be listed in a single list.

@Mairu
Copy link
Collaborator

Mairu commented Apr 5, 2020

So I tested it not with feathers-distributed directly, but with a service that has a property remote set to true.

Service with remote set to true.

  const seqtestService = new Seqtest(options, app);
  seqtestService.remote = true;
  app.use('/seqtest', seqtestService);

Adding a mixin that sets the internal tag for services with the remote property.

app.configure((app) => {
  app.mixins.push((service) => {
    if (service.remote === true) {
      service.docs = {
        tag: 'internal',
      };
    }
  });
});

app.configure(swagger({
  specs: {
    info: {
      title: 'Testing stuff with feathers',
      version: '0.0.1',
    },
  },
  openApiVersion: 3,
  uiIndex: true,
  ignore: {
    tags: ['internal'],
  },
  //...
}));

And this worked out for me.

And tags that are not used by any added service, like the internal tag in that case, should not be added to the spec at all.

@Mairu
Copy link
Collaborator

Mairu commented Apr 5, 2020

But for a future version, an additional function based option to ignore services can be added for sure.

@dekelev
Copy link
Member Author

dekelev commented Apr 5, 2020

Cool, setting internal tag this way works great, though "additional function based option to ignore services" is definitely the prefered solution.

Thanks a lot for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants