-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
Description
The openapi-generator-gradle-plugin
is generating the endpoints as absolute paths, with leading /
like /pets
, instead of relative like pets
.
And because the path is absolute - Retrofit seems to be ignoring any path information given to the builder in the .baseUrl(HttpUrl) function. It seems to just be taking the schema and host, and ignoring any base path given to it.
Info from Retrofit's site:
Endpoint values which contain a leading `/` are absolute.
Absolute values retain only the host from baseUrl and ignore any specified path components.
Base URL: http://example.com/api/
Endpoint: /foo/bar/
Result: http://example.com/foo/bar/
openapi-generator version
org.openapi.generator version "4.3.1"
OpenAPI declaration file content or url
https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
Steps to reproduce
This is the setup:
gradle task:
openApiGenerate {
generatorName = "kotlin"
library = "jvm-retrofit2"
inputSpec = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml"
configOptions = [
dateLibrary: "java8"
]
}
generated PetsApi interface:
interface PetsApi {
@POST("/pets")
fun createPets(): Call<Unit>
@GET("/pets")
fun listPets(@Query("limit") limit: kotlin.Int): Call<kotlin.Array<Pet>>
@GET("/pets/{petId}")
fun showPetById(@Path("petId") petId: kotlin.String): Call<Pet>
}
initialising the petsApi:
private val apiClient = ApiClient(baseUrl = "http://petstore.swagger.io/v1/", okHttpClient = okHttpClient)
private val petsApi: PetsApi = apiClient.createService(PetsApi::class.java)
Suggest a fix
Maybe to have the generating an absolute paths configurable.
Similar / related
Here is the same issue described on stackoverflow - https://stackoverflow.com/questions/32352159/retrofit-2-removes-characters-after-hostname-from-base-url
There is a presentation how to fix the issue manually, like removing the leading /
to make the path relative. https://www.youtube.com/watch?v=KIAoQbAu3eA&feature=youtu.be&t=32m50s
Screenshot from the video: