-
Notifications
You must be signed in to change notification settings - Fork 2
Added default value if exists #5
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,10 +23,15 @@ | |
| * | ||
| */ | ||
| public class ParameterParser extends AbstractParser { | ||
| Map<String, String> descriptionMap; | ||
|
|
||
| private Map<String, String> descriptionMap; | ||
|
|
||
| private Map<String, String> defaultValueMap; | ||
|
|
||
| public ParameterParser(Log log, ClassLoader loader, List<Tag> tags, List<Definition> definitions) { | ||
| super(log, loader, tags, definitions); | ||
| this.defaultValueMap = new HashMap<>(); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -76,8 +81,7 @@ public List<Parameter> findParametersInMethodHeader(String header, List<String> | |
| } | ||
|
|
||
| /** | ||
| * Extracts a {@link Parameter} object from a parameter declaration in a | ||
| * method header | ||
| * Extracts a {@link Parameter} object from a parameter declaration in a method header | ||
| * | ||
| * @param paramUnformatted | ||
| * parameter with white spaces and annotations | ||
|
|
@@ -91,10 +95,31 @@ public List<Parameter> findParametersInMethodHeader(String header, List<String> | |
| */ | ||
| private Parameter getParameter(String paramUnformatted, List<String> imports, String fileName, String packageName) | ||
| throws ParserException { | ||
|
|
||
| DataTypeFactory typeHandler = new DataTypeFactory(); | ||
| DefinitionParser definitionParser = new DefinitionParser(log, loader, tags, definitions); | ||
| Boolean isQueryParam = paramUnformatted.matches(".*@QueryParam\\(\"[^\"]+\"\\).*"); | ||
| Boolean isDefaultValue = paramUnformatted.matches(".*@DefaultValue\\(\"[^\"]+\"\\).*"); | ||
|
|
||
| String param = paramUnformatted.replaceAll("[\\s]*" + Regex.ANNOTATION + "[\\s]*", "").trim(); | ||
|
|
||
| List<String> defaultValue = new ArrayList<String>(); | ||
|
|
||
| Matcher m = Pattern.compile(Regex.GETMETHODHEADERPARAMETER).matcher(paramUnformatted); | ||
| while (m.find() && isDefaultValue) { | ||
| String paramUnformattedTest = m.group(); | ||
|
|
||
| if (paramUnformattedTest.contains("@DefaultValue")) { | ||
| createMapFromParameters(paramUnformatted); | ||
| defaultValue.add(paramUnformattedTest); | ||
|
|
||
| } | ||
| } | ||
| Matcher matchDef = Pattern.compile(Regex.GETMETHODHEADERPARAMETERINSIDE).matcher(defaultValue.toString()); | ||
| while (matchDef.find()) { | ||
| defaultValue.removeAll(defaultValue); | ||
| defaultValue.add(matchDef.group()); | ||
| } | ||
| if (!param.isEmpty()) { | ||
| String[] split = param.split(" "); | ||
| String className = split[0]; | ||
|
|
@@ -132,14 +157,32 @@ private Parameter getParameter(String paramUnformatted, List<String> imports, St | |
| parameter.setLocation("body"); | ||
| parameter.setType(type); | ||
| parameter.setRequired(true); | ||
|
|
||
| } else { | ||
| parameter.setLocation("query"); | ||
| parameter.setName(getNameFromQueryParamAnnotation(paramUnformatted)); | ||
| parameter.setType(type); | ||
| } | ||
| parameter.setFormat(format); | ||
| String description = descriptionMap.get(name); | ||
| parameter.setDescription(description); | ||
| if (isDefaultValue) { | ||
| parameter.setLocation("query"); | ||
| // parameter.setType(type); | ||
| for (int i = 0; i < defaultValue.size(); i++) { | ||
|
Collaborator
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. Ich bevorzuge for-Schleifen mit der Doppelpunkt-Schreibweise |
||
| parameter.setDefaultValue(defaultValue.get(i)); | ||
|
Collaborator
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. Aktuell ist es so, wenn es mehrere |
||
| parameter.setRequired(false); | ||
| } | ||
| parameter.setFormat(format); | ||
| String description = descriptionMap.get(name); | ||
| if (this.defaultValueMap.get(name) != null) { | ||
| description = description | ||
| + ". If parameter is not set, parameter will be set to the default Value \"" | ||
| + this.defaultValueMap.get(name) + "\""; | ||
| } | ||
| parameter.setDescription(description); | ||
| } else { | ||
| parameter.setFormat(format); | ||
| String description = descriptionMap.get(name); | ||
| parameter.setDescription(description); | ||
| } | ||
| return parameter; | ||
| } | ||
| return null; | ||
|
|
@@ -185,4 +228,75 @@ private Map<String, String> getParameterDescriptionMap(String javadoc) { | |
| } | ||
| return map; | ||
| } | ||
|
|
||
| /** | ||
| * Takes the parameter String and extracts the values of the parameter and of the default value and maps them | ||
| * together | ||
| * | ||
| * @param paramUnformatted | ||
| * @return | ||
| */ | ||
| private void createMapFromParameters(String paramUnformatted) { | ||
|
|
||
| Boolean isDefaultValue = paramUnformatted.matches(".*@DefaultValue\\(\"[^\"]+\"\\).*"); | ||
| Boolean isQueryParam = paramUnformatted.matches(".*@QueryParam\\(\"[^\"]+\"\\).*"); | ||
|
|
||
| List<String> defaultValue = new ArrayList<String>(); | ||
| List<String> defaultValueKey = new ArrayList<String>(); | ||
| List<String> defaultValueValue = new ArrayList<String>(); | ||
|
|
||
| List<String> queryParam = new ArrayList<String>(); | ||
| List<String> queryParamKey = new ArrayList<String>(); | ||
| List<String> queryParamValue = new ArrayList<String>(); | ||
|
|
||
| Matcher m = Pattern.compile(Regex.GETMETHODHEADERPARAMETER).matcher(paramUnformatted); | ||
| while (m.find() && isDefaultValue) { | ||
| List<String> paramUnformattedTest = new ArrayList<String>(); | ||
| paramUnformattedTest.add(m.group()); | ||
| for (int i = 0; i < paramUnformattedTest.size(); i++) { | ||
| if (paramUnformattedTest.get(i).contains("@DefaultValue")) { | ||
|
|
||
| defaultValue.add(paramUnformattedTest.get(i)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Matcher matchDefKey = Pattern.compile("@([a-zA-Z0-9])+").matcher(defaultValue.toString()); | ||
| while (matchDefKey.find()) { | ||
| defaultValueKey.removeAll(defaultValueKey); | ||
| defaultValueKey.add(matchDefKey.group()); | ||
| } | ||
|
|
||
| Matcher matchDefValueValue = Pattern.compile(Regex.GETMETHODHEADERPARAMETERINSIDE) | ||
| .matcher(defaultValue.toString()); | ||
| while (matchDefValueValue.find()) { | ||
| defaultValueValue.removeAll(defaultValueValue); | ||
| defaultValueValue.add(matchDefValueValue.group()); | ||
| } | ||
| Matcher m5 = Pattern.compile(Regex.GETMETHODHEADERPARAMETER).matcher(paramUnformatted); | ||
| while (m5.find() && isQueryParam) { | ||
| List<String> paramUnformattedTest = new ArrayList<String>(); | ||
| paramUnformattedTest.add(m5.group()); | ||
| for (int i = 0; i < paramUnformattedTest.size(); i++) { | ||
| if (paramUnformattedTest.get(i).contains("@QueryParam")) { | ||
| queryParam.add(paramUnformattedTest.get(i)); | ||
| } | ||
| } | ||
| } | ||
| Matcher matchQueryParamKey = Pattern.compile("@([a-zA-Z0-9])+").matcher(queryParam.toString()); | ||
| while (matchQueryParamKey.find()) { | ||
| queryParamKey.removeAll(queryParamKey); | ||
| queryParamKey.add(matchQueryParamKey.group()); | ||
| } | ||
|
|
||
| Matcher matchQueryParamValue = Pattern.compile(Regex.GETMETHODHEADERPARAMETERINSIDE) | ||
| .matcher(queryParam.toString()); | ||
| while (matchQueryParamValue.find()) { | ||
| queryParamValue.removeAll(queryParamValue); | ||
| queryParamValue.add(matchQueryParamValue.group()); | ||
| } | ||
|
|
||
| this.defaultValueMap.put(queryParamValue.toString().replace("[", "").replace("]", ""), | ||
| defaultValueValue.toString().replace("[", "").replace("]", "")); | ||
| } | ||
| } | ||
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.
Namensgebung: Damit man direkt sehen kann, dass es mehrere Werte sind, lieber umbenennen zu
defaultValues