Open jazzapple opened 3 years ago
Same
Copied from the docs:
servers:
- url: '{protocol}://myapp.com'
variables:
protocol:
enum:
- http
- https
default: https
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.22</version>
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2020-11-02T12:34:38.995686-08:00[America/Los_Angeles]")@Component("myapp.ApiClient")
public class ApiClient {
public enum CollectionFormat {
CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null);
private final String separator;
private CollectionFormat(String separator) {
this.separator = separator;
}
private String collectionToString(Collection<? extends CharSequence> collection) {
return StringUtils.collectionToDelimitedString(collection, separator);
}
}
private boolean debugging = false;
private HttpHeaders defaultHeaders = new HttpHeaders();
private String basePath = "{protocol}://myapp.com";
private RestTemplate restTemplate;
private Map<String, Authentication> authentications;
private HttpStatus statusCode;
private MultiValueMap<String, String> responseHeaders;
private DateFormat dateFormat;
public ApiClient() {
this.restTemplate = buildRestTemplate();
init();
}
@Autowired
public ApiClient(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
init();
}
protected void init() {
// Use RFC3339 format for date and datetime.
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
this.dateFormat = new RFC3339DateFormat();
// Use UTC as the default time zone.
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
// Set default User-Agent.
setUserAgent("Java-SDK");
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
/**
* Get the current base path
* @return String the base path
*/
public String getBasePath() {
return basePath;
}
/**
* Set the base path, which should include the host
* @param basePath the base path
* @return ApiClient this client
*/
public ApiClient setBasePath(String basePath) {
this.basePath = basePath;
return this;
}
...
Description
I'm using server templating in my swagger.yaml and swagger-codegen-cli-3.0.21 JAR file to generate a Python SDK. In the generated configuration.py file, the host is populated as a string with the placeholders rather than being substituted. This consequently returns "name or service unknown" error when the client tries to connect to the host
Swagger-codegen version
swagger-codegen-cli-3.0.21
Swagger declaration file content or url
Command line used for generation
java -jar swagger-codegen-cli-3.0.21 generate -i myclient/swagger.yaml -o myclient/ -l python
Steps to reproduce
run command line above, returns configuration.py with:
Related issues/PRs
Suggest a fix/enhancement
have codegen perform variable substitution on the default values and populate host accordingly in configuration.py. Similar functionality has been implemented in OpenAPI generator which handles both multiple servers and variable substitution