until they put it in the documentation, if you are using openapi-generator Maven plugin, the concept is called server variables
- it is documented here and passed e.g. to CLI generator as follows:
--server-variables <server variables>
sets server variables overrides for spec documents which support
variable templating of servers.
E.g. (i took the example from the corresponding feature pull request):
openapi-generator generate -g java -i myproject/myapi.json -o myproject/generated --server-variables=host=myhost.com,basePath=myapi
The above would accomodate e.g. the scenario where myapi.json (the specification of our API) contained the following:
...
"servers": [
{
"url": "https://{host}/{basePath}/v1/",
"variables": {
"host": {
"default": "service.domain.org"
},
"basePath": {
"default": "mythings"
}
}
}
],
...
In which case, the generated ApiClient.java would contain the following:
private String basePath = "https://myhost.com/myapi/v1";
I haven't actually tried the above and assembled it as an example. What I tried in a working example was to use openapi-generator-maven-plugin in the following manner (see serverVariableOverrides
):
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/myapi.json</inputSpec>
<generatorName>java</generatorName>
<library>resttemplate</library>
<apiPackage>com.mycompany.myapi.client.generated.api</apiPackage>
<modelPackage>com.mycompany.myapi.client.generated.model</modelPackage>
<invokerPackage>com.mycompany.myapi.client.generated.invoker</invokerPackage>
<configOptions>
<dateLibrary>java8</dateLibrary> <!-- otherwise we have a problem, threetenbp has to be used -->
</configOptions>
<serverVariableOverrides>host=myhost.com,basePath=myapi</serverVariableOverrides>
</configuration>
</execution>
</executions>
</plugin>