swagger-api / swagger-api/swagger-codegen
programmatically setting baseUrl in java / retrofit2
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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