[go: nahoru, domu]

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

Add support for polymorphism (discriminators) #174

Open
adupre opened this issue Apr 19, 2019 · 3 comments
Open

Add support for polymorphism (discriminators) #174

adupre opened this issue Apr 19, 2019 · 3 comments

Comments

@adupre
Copy link
adupre commented Apr 19, 2019

I need to be able to leverage the polymorphism features of Mongoose (discriminators) to create schemas that inherit from one another (example: Contract, SalesContract, PurchaseContract)

Enhance the model and api generators to support discriminators. Leverage Swagger's support of OneOf for generation of api and documentation.

There are unfortunately no acceptable alternatives at the moment.

Btw, thank you for this awesome library, it's a true time saver.
Cheers,
Anthony

@JKHeadley
Copy link
Owner

Thanks! Glad to hear it!

I will try to look into this soon and see how feasible it is.

@JKHeadley
Copy link
Owner

@adupre I added some initial support for discriminators. You can test it out with this repo:
https://github.com/JKHeadley/rest-hapi-demo/tree/feature/discriminators

Some notes:

  • Does not use swagger OneOf since it is not supported in hapi-swagger, however most of the documentation should be taken care of by rest-hapi directly.
  • The discriminatorKey property is automatically queryable, which could result in useful filtering of parent models. Ex: with parent model: contractand child models: salesContract and purchaseContract, the following query would return all child model documents but not parent model documents (assuming the discriminatorKey is kind):
    http://localhost:8080/contract?kind=salesContract&kind=purchaseContract

Please let me know what you think.

@JKHeadley
Copy link
Owner

@adupre please let me know if you have any input here. I will try to integrate this feature with the next minor version.

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

No branches or pull requests

2 participants