swagger-api/swagger-codegen

programmatically setting baseUrl in java / retrofit2

Open

#3,891 opened on Sep 28, 2016

View on GitHub
 (10 comments) (3 reactions) (0 assignees)HTML (12,701 stars) (5,474 forks)batch import
Client: RetrofitFeature: DocumentationGeneral: Questionhelp wanted

Description

Description

Using Java / retrofit2 client generation.

It generates ApiClient where baseUrl is locally set in createDefaultAdapter and passed to Retrofit.Builder.

I want to use this same generated code, but with different baseUrls programmatically.

That does not seem to be possible.

Swagger-codegen version

2.2.2-SNAPSHOT

Command line used for generation
java -jar ${swaggerCodegenJar} generate \
     -l java \
     --library retrofit2 \
     --group-id TO-BE-DELETED \
     --artifact-id java-retrofit2-client \
     --api-package api \
     --invoker-package invoker \
     --model-package model \
     -i DocService-folders-swagger.json \
     -o /tmp
Related issues

https://github.com/swagger-api/swagger-codegen/issues/2823

Suggest a Fix

Rather than have a bunch of different constructors for ApiClient, use a "fluent/builder" style that includes baseUrl as one of its methods.

Contributor guide