graphhopper / directions-api-clients

API clients for various languages for the GraphHopper Directions API
https://docs.graphhopper.com/
Apache License 2.0
30 stars 39 forks source link

Kotlin client is definitely not working #27

Open carlos-mg89 opened 6 years ago

carlos-mg89 commented 6 years ago

I'm trying quite hard to include the Kotlin client into my Android project and seems to be a huge hassle.

List of issues:

I've tried to import the client-hc library too, but didn't have luck either :( If anyone could assist me I'll deeply appreciate it.

karussell commented 6 years ago

Thanks for reporting and ugly that it does not work. Can you write which errors you get in detail and what your steps were? Maybe some of them are already known to the swagger team?

The client-hc library works for Java in the JVM so it should work for other JVM languages like Scala, Clojure and also Kotlin. Again can you report the error messages?

carlos-mg89 commented 6 years ago

Hi @karussell ,

I already gave you the errors I'm having with the auto-generated Kotlin library on my original comment.

There seem to be problems with compilation.

I added the folder of the Kotlin library into my project, then I added it in my settings.gradle and in my build.gradle as I have successfully added other libraries (actually, a Java auto-generated client from a Swagger file too, but this one is written by me).

Gonna try again with the client-hc and see if I have more luck this time.

carlos-mg89 commented 6 years ago

@karussell now I do remember what happened when I tried the client-hc.

I imported the .jar of the version 0.10 and I expected to have all the endpoints, specially I'm looking for the online routing endpoints. However, when I import the project, using this code in my build.gradle:

implementation(group: 'com.graphhopper', name: 'graphhopper-core', version: '0.10-SNAPSHOT') {
       exclude group: 'com.google.protobuf', module: 'protobuf-java'
       exclude group: 'org.openstreetmap.osmosis', module: 'osmosis-osm-binary'
       exclude group: 'org.apache.xmlgraphics', module: 'xmlgraphics-commons'
}

Then I cannot find my way to using the online routing (using the GH key, of course), like in this example: https://github.com/graphhopper/graphhopper/tree/master/client-hc

Basically, the setKey method doesn't exist, for example. Nor the setDownloader.

I could load an offline map, but I don't want to do this at the moment, I'm interested in the online capabilities, and will be in the offline in a few months.

What am I missing? I have followed the indications in https://github.com/graphhopper/graphhopper/blob/master/docs/android/index.md although it's using an example to load an offline map, I expected the GraphHopper class to have all the methods I've seen in other examples of code, like the one above, in the client-hc.

I've tried importing the client-hc as an Android library, but cannot figure out a way of doing it with Gradle.

devemux86 commented 6 years ago

The Android sample uses offline maps and with graphhopper-core module loads offline graphs.

If want to use the directions-api-client-hc would need to include it too, e.g. see Maven artifact.

implementation 'com.graphhopper:directions-api-client-hc:0.10.1'
karussell commented 6 years ago

I already gave you the errors I'm having with the auto-generated Kotlin library on my original comment.

I was asking about details like stacktrace or whatever you got. Have no kotlin environment available at the moment and with that I could e.g. search the list of open kotlin issues. Instead of the Kotlin version you can probably use the swagger generated Java lib: com.graphhopper:directions-api-client:0.10.0

Regarding client-hc: yes, you'll need to use the dependency @devemux86 pointed to.

carlos-mg89 commented 6 years ago

I have finally achieved it including this dependency:

implementation 'com.graphhopper:directions-api-client-hc:0.10.1'

Now it works like a charm! I think it might be a bit chaotic to follow some of the readmes, since I didn't find this line that definitely works, if it wasn't because of you @devemux86

Here https://github.com/graphhopper/graphhopper/tree/master/client-hc you don't see anything related with this. I was adding the project as a library, and that didn't really work.

However, thanks for all the assistance. I'm able to consume now any of the online calls of GraphHopper :)

carlos-mg89 commented 6 years ago

@karussell @devemux86 I'd update the main page, where you talk about the Maven snippet top be included, and add the Gradle info. It'd be useful for newcomers.

Obviously, if I'd be more proficient on knowing the differences between Maven and Gradle I should have been able to figure out that it's straightforward to write the equivalent, but Gradle is the current technology and is widely used.

Thanks anyway, you saved my day! :)

karussell commented 6 years ago

Great that you got it working!

Let us keep this issue open until the real kotlin client works too :)

carlos-mg89 commented 6 years ago

@karussell Sure! Perhaps just making a conversion of the client-hc using the auto-conversion tool from Java to Kotlin, and a little bit of adaptation would do the work. I've done it with many classes, and sometimes it even works straightforward.

karussell commented 6 years ago

(And investigate how we can utilize the polyglot graalvm platform)

Dexyon commented 5 years ago

I just tested generating the Kotlin library with the latest gradle and kotlin version. Looks like the naming issue is this present in the Swagger CLI :(

karussell commented 5 years ago

Thanks for your feedback. There are many issues open for kotlin. Can you try the latest swagger cli?

Another problem that we currently have is that swagger-cli (hard) forked into open api and for us it is unclear which horse we should bet on.

carlos-mg89 commented 5 years ago

It looks like there has been a lot going on in the Swagger community, however a lot of people involved on previous project has moved now to OpenAPI-generator. I'd check it as well for a Swagger/OpenAPI spec I have for my own project and see how it behaves.

Anyway, OpenAPI-generator seems to be releasing very often and could be a much better alternative than the previous (and quite out of date) Swagger/OpenAPI client/server generator.

Dexyon commented 5 years ago

I did try the latest (stable) release of the CLI, but that didn't change. Could try the snapshot but didn't find any MR's which will fix the issue (at least from what I have seen).

If I can find some time I will give the openapi-generator a try and post my findings here.

karussell commented 4 years ago

See https://github.com/graphhopper/directions-api-clients/issues/37 for a status update of this repo.

The generator used on https://editor.swagger.io/ seems to work, also for kotlin. At least some sources are created ;). Maybe you can try if it also compiles and runs ok?