Skip to content

Commit b22c7e0

Browse files
committed
Updated README
1 parent b193756 commit b22c7e0

File tree

1 file changed

+120
-2
lines changed

1 file changed

+120
-2
lines changed

README.md

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ A rule based validator developed for easy use with the Spring Boot framework.
1414
- [`array` rules](#array-rules)
1515
- [Custom rules](#custom-rules)
1616

17+
18+
---
19+
20+
1721
## Adding dependency
1822
To use the validator add the following dependency to your `pom.xml`.
1923
```xml
@@ -24,6 +28,10 @@ To use the validator add the following dependency to your `pom.xml`.
2428
</dependency>
2529
```
2630

31+
32+
---
33+
34+
2735
## Usage
2836

2937
Easiest way to use the validator in a Spring Boot project is to setup a `ValidatorConfig` class. There you can
@@ -55,13 +63,21 @@ the validate method. That way you get the validated and updated input DTO for fu
5563
dto = validator.validate(dto);
5664
```
5765

66+
67+
---
68+
69+
5870
## Internationalization
5971
Unfortunately it is not possible to change the outputted language to something different than english.
6072
If you need to provide other languages as well, you can make use of the error type. When
6173
you return the result of the `getErrors()` method of the ErrorBag that you got from the thrown
6274
`ValidationException` you have the error type available and can show messages based on this
6375
unique key.
6476

77+
78+
---
79+
80+
6581
## Builders and Methods
6682
As said, to generate a validator you should make use of the static helper methods.
6783
The following types are supported at the moment:
@@ -71,7 +87,8 @@ The following types are supported at the moment:
7187
- array
7288

7389
In the following sections you learn which methods and rules are available by default and how
74-
to use them.
90+
to use them. Each `Builder` has a `build()` method which returns a `Validateable`, if you need
91+
to have one of those.
7592

7693
### `string` rules
7794

@@ -125,7 +142,8 @@ string(field)
125142

126143
- ##### `defaultValue(String)`
127144
*Sets the fields value to the given string*, if the fields value is null or empty.
128-
145+
Rejects if the given parameter is not assignable to the fields value.
146+
129147
- ##### `custom(Rule)`
130148
Registers a custom defined rule.
131149

@@ -139,6 +157,106 @@ The following snippet returns an instance of the `NumberRuleBuilder` class.
139157
number(field)
140158
```
141159

160+
#### Available rules
161+
162+
- ##### `required()`
163+
Marks the field as *required* meaning it cannot be null.
164+
165+
- ##### `optional()`
166+
Marks the field as *optional*. All rules behind this rule can fail.
167+
168+
- ##### `length(int)`
169+
Checks if the *fields value is the same* as the provided parameter `length`.
170+
171+
- ##### `size(int, int)`
172+
Checks if the *value is between* the first and second parameter integers.
173+
174+
- ##### `min(int)`
175+
Checks if the fields value is *greater or equal* to the given parameter.
176+
177+
- ##### `max(int)`
178+
Checks if the fields value of the string is *smaller or equal* to the given parameter.
179+
180+
- ##### `defaultValue(int)`
181+
*Sets the fields value to the given number*, if the fields value is null or 0.
182+
Rejects if the given parameter is not assignable to the fields value.
183+
184+
- ##### `custom(Rule)`
185+
Registers a custom defined rule.
186+
187+
---
188+
189+
### `object` rules
190+
191+
#### Usage
192+
The following snippet returns an instance of the `ObjectRuleBuilder` class.
193+
```java
194+
object(field)
195+
```
196+
197+
#### Available rules
198+
199+
- ##### `optional()`
200+
Marks the field as *optional*. All rules behind this rule can fail.
201+
202+
- ##### `child(Builder)`
203+
Adds a check for *one child property* using a `Builder`.
204+
205+
- ##### `child(Validatable)`
206+
Adds a check for *one child property* using a `Validatable`.
207+
208+
- ##### `fields(Builder[])`
209+
Adds a check for *one or more child properties* using the given `Builder`.
210+
211+
---
212+
213+
### `array` rules
214+
215+
#### Usage
216+
The following snippet returns an instance of the `ArrayRuleBuilder` class.
217+
```java
218+
array(field)
219+
```
220+
221+
#### Available rules
222+
223+
- ##### `required()`
224+
Marks the field as *required* meaning it cannot be null or empty.
225+
226+
- ##### `optional()`
227+
Marks the field as *optional*. All rules behind this rule can fail.
228+
229+
- ##### `length(int)`
230+
Checks if the *length of the array is the same* as the provided parameter `length`.
231+
232+
- ##### `size(int, int)`
233+
Checks if the *length of the array is between* the first and second parameter integers.
234+
235+
- ##### `min(int)`
236+
Checks if the length of the array is *greater or equal* to the given parameter.
237+
238+
- ##### `max(int)`
239+
Checks if the length of the array is *smaller or equal* to the given parameter.
240+
241+
- ##### `objects(Builder[])`
242+
*Used for object arrays only!* Gets an array of `Builder` instances, which are validated for every object in the array.
243+
244+
- ##### `custom(Rule)`
245+
Registers a custom defined rule.
246+
247+
#### Additional methods
248+
249+
Arrays are handled differently as they can have elements or objects as children. To handle
250+
an array of elements you have to use the `elements` method which returns an `ArrayElementRuleBuilder`.
251+
252+
- ##### `elements()`
253+
Returns an `ArrayElementRuleBuilder` which has access to nearly every rule from above as
254+
the type of the arrays elements is unknown.
255+
256+
257+
---
258+
259+
142260
## Custom rules
143261
You can easily extend the functionality of the validator by defining custom rules. If you need a specific Regex and don't
144262
want to use the `PatternRule` over and over again you can create your own rule.

0 commit comments

Comments
 (0)