Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7208
Closed
Open
Issue created Aug 13, 2020 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

[BUG] [Kotlin] [Retrofit 2] [openapi-generator-gradle-plugin] - Generating an absolute paths instead of relative.

Created by: shaban-rant

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: Screenshot 2020-08-14 at 00 25 43

Assignee
Assign to
Time tracking