OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.97k stars 6.59k forks source link

[REQ] Add a Kotlin client Volley library #10011

Open alisters opened 3 years ago

alisters commented 3 years ago

Is your feature request related to a problem? Please describe.

We use android and volley, but with Kotlin. Presently there is

Searching the issues shows the volley client may need attention - https://github.com/OpenAPITools/openapi-generator/issues/9293

Additionally we use co-routines, but my understanding (limited!) of the implementation of co-routines in both these libraries is that whilst they add a suspending function, they then block on it's return. I'd like to see suspendCoroutine, adding the callback listeners to the co-routine continuation, and suspending the co-routine until a value has returned (avoiding tying up a thread until the response arrives). This is the documented way of adapting existing callback based api's to co-routines - though the best explanation of it i've found is in this video, at this point - https://youtu.be/YrrUCSi72E8?t=982

Describe the solution you'd like

I'd like to leverage the model generation in the kotlin client generator, but add a library to for volley

Describe alternatives you've considered

Using one of the existing two generators / libraries. See some of the shortcomings outlined above

Additional context

We've started work on it, and should have a PR ready with basic functionality ready in a week or two. It has some obvious extension points with the ability to pass your own configured requestQueue, or your own factory for mapping from the various http call fields to volley request classes.

wing328 commented 3 years ago

@alisters thanks for offering contributions on this. We definitely welcome Volley support via the --library option in the Kotlin client generator.

Let us know if you need any help.

alisters commented 3 years ago

@wing328 - great. This is progressing, but as always more slowly than hoped ! We are using it in house, and are adding some auth to it. Next update will hopefully be a PR and any/all help and feedback welcomed then.

alisters commented 3 years ago

@wing328

alisters commented 3 years ago

Design decisions for the Android Kotlin library

A kotlin client for Android using the currently recommended http client, Volley. See https://developer.android.com/training/volley

Future improvements

Consumption of the client

Hilt Dependency injection example - when constructing our clients, we inject the appropriate header factories. We don't use auth from the api, but in this sample i also inject a basic auth header factory and bind it's credentials return SomeApi (context = context, requestQueue = restService.getRequestQueue(), requestFactory = RequestFactory(sessionHeaderFactory, traceHeaderFactory, RequestFactory.basicAuthHeaderFactoryBuilder("username", "password")), basePath = configurationService.getBaseUrl() )

alisters commented 3 years ago

I've attempted to add per operation security but can't see an easy way to do it presently.

Have seen that it was done for the python client here - https://github.com/OpenAPITools/openapi-generator/pull/6569/files - but am wondering if this is commonly implemented ?

alisters commented 3 years ago

@wing328 We've updated the PR after generating the required samples and docs. Could you indicate

I was unable to tag the issue as Kotlin client related when i raised it. I'm happy to be tagged on bugs raised, and to monitor the appropriate tags if you can tell me what they will be.

alisters commented 3 years ago

@wing328 Some help is required please. I'm unsure why the circle:ci and bitrise builds are failing.

Dry Run Results:

k C:\dev...-kotlin-volley.openapi-generator-ignore Skipped by user option(s) Skipped by supportingFiles options supplied by user. w C:\dev...-integration-kotlin-volley.openapi-generator\VERSION Write............... File will be written.

States:

Circle:ci circle_parallel seems to be failing on the typescript client ?

wing328 commented 3 years ago

Please ignore those CI failure for the time being. I'll take a look at your PR later today.

alisters commented 3 years ago

Ok and thank you.

If you're not familiar with volley, the major aspect i didn't really call out in the above comments is that volley doesn't directly communicate with an http client - it adds requests to a queue which then interacts with an http client. So in our code gen setup we replaced an apiclient or api invoker that the other kotlin and java clients had with just the RequestFactory. In turn this changes the way you might interact with the code gen in the course of making a given request - how do you set the username and password for a single operation that has overridden global security ? We could put these calls on the request factory but it didn't feel great. TBD further if you wish to.