-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[java] Support templated servers #4998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jimschubert
merged 12 commits into
OpenAPITools:master
from
jirikuncar:java-client-endpoint-servers
Feb 19, 2020
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
594f055
[java] Support templated servers
jirikuncar 807ece0
Deprecate old signature of invokeAPI method
jirikuncar 6577bde
Regenerated
jirikuncar 5b93d63
throw ArrayIndexOutOfBoundsException
jirikuncar 07965b9
Regenerated
jirikuncar 09b84f5
Merge branch 'master' into java-client-endpoint-servers
jirikuncar edca168
Update modules/openapi-generator/src/main/resources/Java/ServerConfig…
jirikuncar d98c7dd
Regenerated
jirikuncar fe93888
Merge remote-tracking branch 'upstream/master' into java-client-endpo…
jirikuncar b0b1cfe
Fix imports and typo in index name
jirikuncar e299f8d
Fix javadoc
jirikuncar 63a26c8
[java] Regenerate samples
jimschubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
modules/openapi-generator/src/main/resources/Java/ServerConfiguration.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package {{invokerPackage}}; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import com.datadog.api.v1.client.ServerVariable; | ||
|
|
||
| /** | ||
| * Representing a Server configuration. | ||
| */ | ||
| public class ServerConfiguration { | ||
| public String URL; | ||
| public String description; | ||
| public Map<String, ServerVariable> variables; | ||
|
|
||
| /** | ||
| * @param A URL to the target host. | ||
| * @param description A describtion of the host designated by the URL. | ||
| * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. | ||
| */ | ||
| public ServerConfiguration(String URL, String description, Map<String, ServerVariable> variables) { | ||
| this.URL = URL; | ||
| this.description = description; | ||
| this.variables = variables; | ||
| } | ||
|
|
||
| /** | ||
| * Format URL template using given variables. | ||
| * | ||
| * @param variables A map between a variable name and its value. | ||
| * @return Formatted URL. | ||
| */ | ||
| public String URL(Map<String, String> variables) { | ||
| String url = this.URL; | ||
|
|
||
| // go through variables and replace placeholders | ||
| for (Map.Entry<String, ServerVariable> variable: this.variables.entrySet()) { | ||
| String name = variable.getKey(); | ||
| ServerVariable serverVariable = variable.getValue(); | ||
| String value = serverVariable.defaultValue; | ||
|
|
||
| if (variables != null && variables.containsKey(name)) { | ||
| value = variables.get(name); | ||
| if (serverVariable.enumValues.size() > 0 && !serverVariable.enumValues.contains(value)) { | ||
| throw new RuntimeException("The variable " + name + " in the server URL has invalid value " + value + "."); | ||
| } | ||
| } | ||
| url = url.replaceAll("\\{" + name + "\\}", value); | ||
| } | ||
| return url; | ||
| } | ||
|
|
||
| /** | ||
| * Format URL template using default server variables. | ||
| * | ||
| * @return Formatted URL. | ||
| */ | ||
| public String URL() { | ||
| return URL(null); | ||
| } | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
modules/openapi-generator/src/main/resources/Java/ServerVariable.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package {{invokerPackage}}; | ||
|
|
||
| import java.util.HashSet; | ||
|
|
||
| /** | ||
| * Representing a Server Variable for server URL template substitution. | ||
| */ | ||
| public class ServerVariable { | ||
| public String description; | ||
| public String defaultValue; | ||
| public HashSet<String> enumValues = null; | ||
|
|
||
| /** | ||
| * @param description A description for the server variable. | ||
| * @param defaultValue The default value to use for substitution. | ||
| * @param enumValues An enumeration of string values to be used if the substitution options are from a limited set. | ||
| */ | ||
| public ServerVariable(String description, String defaultValue, HashSet<String> enumValues) { | ||
| this.description = description; | ||
| this.defaultValue = defaultValue; | ||
| this.enumValues = enumValues; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.