forked from loafle/openapi-generator-original
Merge pull request #3623 from wing328/ruby_better_pattern
Add function to handle missing delimiter in regex
This commit is contained in:
@@ -551,7 +551,7 @@ public class DefaultCodegen {
|
||||
* @return properly-escaped pattern
|
||||
*/
|
||||
public String toRegularExpression(String pattern) {
|
||||
return escapeText(pattern);
|
||||
return escapeText(addRegularExpressionDelimiter(pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3273,4 +3273,19 @@ public class DefaultCodegen {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the pattern misses the delimiter, add "/" to the beginning and end
|
||||
* Otherwise, return the original pattern
|
||||
*
|
||||
* @param pattern the pattern (regular expression)
|
||||
* @return the pattern with delimiter
|
||||
*/
|
||||
public String addRegularExpressionDelimiter(String pattern) {
|
||||
if (pattern != null && !pattern.matches("^/.*")) {
|
||||
return "/" + pattern + "/";
|
||||
}
|
||||
|
||||
return pattern;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,4 +727,5 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("=end", "=_end").replace("=begin", "=_begin");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user