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

Export class from controller #166

Open
salvacnj opened this issue Sep 1, 2020 · 2 comments
Open

Export class from controller #166

salvacnj opened this issue Sep 1, 2020 · 2 comments

Comments

@salvacnj
Copy link

salvacnj commented Sep 1, 2020

I'm trying to export a class instead of functions on my controller file, as show in this example:

https://github.com/exegesis-js/exegesis/blob/40b0b34ed7d5a692e403197f9d510e5972acb2ae/samples/typescript-example/controllers/greetController.ts

But I'm not able to get it working. Should the methods of the class been the operationId?

Thank you

@jwalton
Copy link
Contributor

jwalton commented Sep 8, 2020

Should the methods of the class been the operationId?

Yeah, this exactly. Did you get it working?

You'll also need to instantiate the class yourself:

export class MyController() {
  sayHello(context) {...}
}

And then when you create your Exegesis instance, the controllers option should be:

    controllers: [ new MyController() ],

I've been thinking about adding something like a controllerFactory option for a while, where you can specify how controllers get loaded, but right now exegesis won't instantiate that class for you (it wouldn't know what to pass to the constructor), so you have to do it yourself.

@salvacnj
Copy link
Author

@jwalton Is there any way to combine the controllers initialization mantaining the folder inicialitation or factory?

Regards

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

No branches or pull requests

2 participants