forked from swagger-api/swagger-codegen
-
Notifications
You must be signed in to change notification settings - Fork 2
Extended java generator #15
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
Open
fcavalieri
wants to merge
1
commit into
master
Choose a base branch
from
extend-java-generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import java.util.List; | |
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.TimeZone; | ||
import java.util.regex.Pattern; | ||
|
||
import java.net.URLEncoder; | ||
|
||
|
@@ -333,11 +334,19 @@ public class ApiClient { | |
* if JSON exists in the given array, use it; | ||
* otherwise use the first one of the array. | ||
* | ||
* @param headerParams The user provided header parameters map | ||
* @param contentTypes The Content-Type array to select from | ||
* @return The Content-Type header to use. If the given array is empty, | ||
* JSON will be used. | ||
*/ | ||
public String selectHeaderContentType(String[] contentTypes) { | ||
public String selectHeaderContentType({{javaUtilPrefix}}Map<String, String> headerParams, String[] contentTypes) { | ||
String customContentType = null; | ||
for (String header: headerParams.keySet()) | ||
{ | ||
if (header.equalsIgnoreCase("Content-Type")) | ||
customContentType = headerParams.get(header); | ||
} | ||
if (customContentType != null) return customContentType; | ||
if (contentTypes.length == 0) return "application/json"; | ||
if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) return "application/json"; | ||
return contentTypes[0]; | ||
|
@@ -651,4 +660,23 @@ public class ApiClient { | |
} | ||
return hostMap.get(basePath); | ||
} | ||
|
||
/** | ||
* Adds pattern-based parameters (after name validation) to a dictionary query parameters. | ||
* @throws ApiException | ||
*/ | ||
public <T> void addPatternQueryParameters(String collectionFormat, Map<String, T> parameters, String pattern, List<Pair> queryParams) throws ApiException | ||
{ | ||
Pattern p = Pattern.compile(pattern); | ||
for (Entry<String, T> entry: parameters.entrySet()) | ||
{ | ||
if (p.matcher(entry.getKey()).matches()) | ||
{ | ||
queryParams.addAll(parameterToPairs(collectionFormat, entry.getKey(), entry.getValue())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not return the List and do the queryParams.addAll outside of the function? It is not so clear that the queryParams is the "out" parameter. But I leave it to you. Just a suggestion... |
||
} | ||
else | ||
throw new ApiException(400, "Invalid parameter " + entry.getKey() + ", parameter name must match the regular expression \"" + pattern + "\""); | ||
} | ||
} | ||
|
||
} |
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
2 changes: 1 addition & 1 deletion
2
modules/swagger-codegen/src/main/resources/Java/generatedAnnotation.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 |
---|---|---|
@@ -1 +1 @@ | ||
@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}") | ||
@javax.annotation.Generated(value = "{{generatorClass}}") |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strange indentation