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

OpenAPI generator for reactive data client? #312

Open
AndrewPrifer opened this issue Apr 3, 2020 · 6 comments
Open

OpenAPI generator for reactive data client? #312

AndrewPrifer opened this issue Apr 3, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@AndrewPrifer
Copy link

AndrewPrifer commented Apr 3, 2020

Hi, I’m evaluating rest-hooks for a new project. We already use OpenAPI/Swagger. Does it sound like a good idea to write an OpenAPI generator to transform the OpenAPI definitions into rest-hooks resource definitions? That way there’d be a single source of truth for all things API. Has anyone had a similar setup? Did it work? Do you think it could work? Thank you for your answers!

@ntucker
Copy link
Collaborator

ntucker commented Apr 3, 2020

This is a great idea! At Coinbase we generate our definitions from protos, which works great! Doing something similar for OpenAPI, would be great, and if you open source it - probably benefit many other people! We would happily link to such a generator in the docs, as we consider codegen the best way to work with APIs at scale.

The hardest part is probably creating the schema. Someone did some similar work on this for normalizr, which has an almost identical API https://github.com/eightcard/openapi-to-normalizr. This project might be helpful for any endeavors in this area.

@AndrewPrifer
Copy link
Author

Thank you for the pointers @ntucker!

@ntucker ntucker added the enhancement New feature or request label Apr 3, 2020
@jamakase
Copy link

@AndrewPrifer do you plan to implement it? I have some experience with https://github.com/OpenAPITools/openapi-generator and can probably help with the implementation of such a generator.

@AndrewPrifer
Copy link
Author

AndrewPrifer commented Apr 16, 2020

@jamakase that’s great news! We are planning to make a generator! However after some thinking we decided to for now just start implementing the resource definitions by hand and see what we learn. We decided on this because of how flexible rest(-like) APIs can be. It’d of course be trivial to support neatly arranged resources that can be 1 to 1 translated to resource definitions that don’t override anything besides pk(), however more complex logic is required already for the common patterns of nested resources and server-side joins, which we already use. These probably don’t just mean a more complex generator but also necessary extensions to OpenAPI so that we can somehow communicate to the generator the intention.

If you already have a clear idea or prior experience with rest-hooks though, we’re always open to collaboration, it’s just that we’re still building up experience with it.

TLDR; we are absolutely planning to write a generator, but we’re taking some time to learn first.

@krunicn
Copy link

krunicn commented Jan 10, 2022

Hi @ntucker, would you mind sharing an overview on how you use protos to generate entities?

@ntucker
Copy link
Collaborator

ntucker commented Jan 10, 2022

@krunicn Sure! They key is identifying which messages are entities and then how they make a primary key. The easiest way to do this if you have control over your API is to simply designate a given field (like 'id') to always mean a primary. In this case, your codegen would simply check for existence of the field and if so create an Entity. Since they are all the same id, you can create an IDEntity base class to extend from.

Alternatively if you don't have that level of control, you can use the annotation system to specify the primary key.

@ntucker ntucker changed the title OpenAPI generator for rest hooks? OpenAPI generator for reactive data client? Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants
@ntucker @AndrewPrifer @jamakase @krunicn and others