-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apparently I failed update master before creating branch task/191. Sigh...
- Loading branch information
Showing
15 changed files
with
300 additions
and
117 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...penapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/BaseValidationMessages.java
This file contains 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,30 @@ | ||
package com.reprezen.kaizen.oasparser.val; | ||
|
||
import com.reprezen.kaizen.oasparser.val.msg.Messages; | ||
|
||
public enum BaseValidationMessages implements Messages { | ||
WrongTypeJson("Incorrect JSON value type: %1; allowed types: %2"), // | ||
BadRef("Reference '%1' could not be resolved: %2"), // | ||
PatternMatchFail("Value '%1' does not match required pattern '%2'"), // | ||
BadPattern("Pattern is not a valid Java Regular Expression but may be valid in ECMA 262: %1"), // | ||
BadUrl("Invalid URL '%1': %2"), // | ||
BadEmail("Invalid email address '%1': %2"), // | ||
NumberConstraint("Value %1 must be %2"), // | ||
EmptyList("List may not be empty"), // | ||
DuplicateValue("Value at '%2' appeared already: %1"), // | ||
MissingField("Required field '%1' is missing"), // | ||
WrongTypeFormat("OpenAPI-defined format '%1' requires type '%3' but appears with missing or invalid type %2"), // | ||
WrongTypeValue("Value is incompatible with schema type"); | ||
|
||
private String formatString; | ||
|
||
BaseValidationMessages(String formatString) { | ||
this.formatString = formatString; | ||
} | ||
|
||
@Override | ||
public String getFormatString() { | ||
return formatString; | ||
} | ||
|
||
} |
This file contains 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
30 changes: 0 additions & 30 deletions
30
kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/Messages.java
This file was deleted.
Oops, something went wrong.
This file contains 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 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
42 changes: 42 additions & 0 deletions
42
kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/msg/Messages.java
This file contains 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,42 @@ | ||
package com.reprezen.kaizen.oasparser.val.msg; | ||
|
||
import java.util.Locale; | ||
import java.util.Properties; | ||
|
||
public interface Messages { | ||
|
||
// TODO: add a method to test a localization file for missing and invalid | ||
// property names (compare all the property keys to the enum value names). This | ||
// should be easily executed by a main method in the enum class. It would be | ||
// great to also flag localized messages whose list of placeholder positions | ||
// does not match that of the default message. | ||
public String getFormatString(); | ||
|
||
public String name(); | ||
|
||
public default String getFormatString(Locale locale) { | ||
Properties localeStrings = locale != null ? getFormatStrings(locale) : null; | ||
String formatString = localeStrings != null ? localeStrings.getProperty(name()) : null; | ||
return formatString != null ? formatString : getFormatString(); | ||
} | ||
|
||
public default Properties getFormatStrings(Locale locale) { | ||
return MessagesHelper.loadLocalizations(this.getClass(), locale); | ||
} | ||
|
||
public default String msg(Object... args) { | ||
return msg(Locale.getDefault(), args); | ||
} | ||
|
||
public default String msgNoLocale(Object... args) { | ||
return msg((Locale) null, args); | ||
} | ||
|
||
public default String msg(Locale locale, Object... args) { | ||
return MessagesHelper.format(locale, this, args); | ||
} | ||
|
||
public static String msg(Messages instance, Object... args) { | ||
return instance.msg(args); | ||
} | ||
} |
Oops, something went wrong.