swagger-api / swagger-api/swagger-codegen

programmatically setting baseUrl in java / retrofit2

Open
#3,891 10 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Retrofit Feature: Documentation General: Question help wanted
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated ApiClient, especially createDefaultAdapter where baseUrl is set and passed to Retrofit.Builder. Review the Java retrofit2 generation path using the command shown in the issue and determine how a fluent or builder-style configuration could expose baseUrl. Done means generated clients can set different baseUrls programmatically without requiring multiple constructors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.