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

Wrap the OpenAPI rust client-sdk with a mockable trait for easy testing #46

Closed
edenreich opened this issue Nov 30, 2024 · 2 comments
Closed

Comments

@edenreich
Copy link
Owner

edenreich commented Nov 30, 2024

Summary

Currently OpenAPI generator codegen is simple bad also bad, there is no straightforward to actually mock the API calls, because those functions are not generic and they only getting the configuration injected. So the only thing you can actually mock is probably the API endpoint but the network call will still occur.

Ideally there should be some kind of a trait that you can mock the implementation with automock library.

This is more of an investigation if there is a way to make this code more testable with mocks. I probably need to create additional generic layer between the client-sdk and the actual function calls.

AC's

  • After exploration further actions / tasks were created.
  • The tasks are prioritised
@edenreich edenreich added this to Kopgen Nov 30, 2024
@edenreich edenreich converted this from a draft issue Nov 30, 2024
@edenreich edenreich moved this from Ready to In progress in Kopgen Nov 30, 2024
@edenreich
Copy link
Owner Author

edenreich commented Nov 30, 2024

I found out that https://github.com/oxidecomputer/progenitor wil generate a better client than what openapi standard generator would.

The gained benefits here is less code to generate, excluding explicit functions import will drastically reduce the amount of code generated. Plus it would make the code more testable because the client is being injected into the controller.

Unfortunately it's not as straightforward for using with mockall and automock for testing, but it at least encapsulate everything under a client struct so it would be easy to just inject the client into the controllers.

Perhaps further work would be needed - like writing the mocks, but still it's an improvements than using the regular openapi generator.

@edenreich
Copy link
Owner Author

I also found out there is a new version of the OpenAPI generator which now apparently supports traits: OpenAPITools/openapi-generator#19788

@edenreich edenreich moved this from In progress to Done in Kopgen Dec 24, 2024
@edenreich edenreich closed this as completed by moving to Done in Kopgen Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

1 participant