|
1 | | -# Json-Schema-Validation-Starter |
2 | | - |
3 | | -This provides a Spring-Boot-Starter to include JsonSchemaValidation with the help of the [https://github.com/networknt/json-schema-validator](https://github.com/networknt/json-schema-validator) -library. |
4 | | - |
5 | | -<a href="https://www.buymeacoffee.com/JanLoebel" rel="Buy me a coffee!"></a> |
6 | | - |
7 | | -## Usage |
8 | | - |
9 | | -Include the starter into you're project. |
10 | | - |
11 | | -You need to add jitpack to your `pom.xml` because this project is not available in the official maven repository. |
12 | | -``` |
13 | | -<repositories> |
14 | | - <repository> |
15 | | - <id>jitpack.io</id> |
16 | | - <url>https://jitpack.io</url> |
17 | | - </repository> |
18 | | -</repositories> |
19 | | -``` |
20 | | - |
21 | | -Add the `json-schema-validation-starter`-dependency to your `pom.xml` |
22 | | -``` |
23 | | -<dependency> |
24 | | - <groupId>com.github.JanLoebel</groupId> |
25 | | - <artifactId>json-schema-validation-starter</artifactId> |
26 | | - <version>2.0.0</version> |
27 | | -</dependency> |
28 | | -``` |
29 | | - |
30 | | -After that simply create a json-schema and put it into e.g.: `resources/jsonschema/book.json`. |
31 | | -The last step is now to let your entity know that it should be validated and which schema it should use. |
32 | | - |
33 | | -``` |
34 | | -@JsonSchemaValidation("classpath:jsonschema/book.json") |
35 | | -public class Book { |
36 | | - private String title; |
37 | | - private String author; |
38 | | -} |
39 | | -``` |
40 | | - |
41 | | -## Example project |
42 | | -Head over to [http://github.com/JanLoebel/json-schema-validation-starter-example](http://github.com/JanLoebel/json-schema-validation-starter-example) to checkout the sample project. |
43 | | - |
44 | | -## Contribution |
45 | | -Please feel free to improve or modify the code and open a Pull-Request! Any contribution is welcome :) |
46 | | - |
47 | | -## License |
48 | | -MIT License |
49 | | - |
50 | | -Copyright (c) 2019 Jan Löbel |
51 | | - |
52 | | -See LICENSE file for details. |
| 1 | +# Json-Schema-Validation-Starter |
| 2 | + |
| 3 | +This provides a Spring-Boot-Starter to include JsonSchemaValidation with the help of the [https://github.com/networknt/json-schema-validator](https://github.com/networknt/json-schema-validator) -library. |
| 4 | + |
| 5 | +<a href="https://www.buymeacoffee.com/JanLoebel" rel="Buy me a coffee!"></a> |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +Include the starter into you're project. |
| 10 | + |
| 11 | +You need to add jitpack to your `pom.xml` because this project is not available in the official maven repository. |
| 12 | +``` |
| 13 | +<repositories> |
| 14 | + <repository> |
| 15 | + <id>jitpack.io</id> |
| 16 | + <url>https://jitpack.io</url> |
| 17 | + </repository> |
| 18 | +</repositories> |
| 19 | +``` |
| 20 | + |
| 21 | +Add the `json-schema-validation-starter`-dependency to your `pom.xml` |
| 22 | +``` |
| 23 | +<dependency> |
| 24 | + <groupId>com.github.JanLoebel</groupId> |
| 25 | + <artifactId>json-schema-validation-starter</artifactId> |
| 26 | + <version>2.0.0</version> |
| 27 | +</dependency> |
| 28 | +``` |
| 29 | + |
| 30 | +After that simply create a json-schema and put it into e.g.: `resources/jsonschema/book.json`. |
| 31 | +The last step is now to let your entity know that it should be validated and which schema it should use. |
| 32 | + |
| 33 | +``` |
| 34 | +@JsonSchemaValidation("classpath:jsonschema/book.json") |
| 35 | +public class Book { |
| 36 | + private String title; |
| 37 | + private String author; |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +Alternatively, you need to add this annotation in your controller like below. This is helpful when you generate your classes from a schema or can't edit them. |
| 42 | + |
| 43 | +``` |
| 44 | +@RestController |
| 45 | +@RequestMapping("/books") |
| 46 | +public BooksConroller { |
| 47 | + @PostMapping |
| 48 | + public ResponseEntity<Book> createBook(@RequestBody @JsonSchemaValidation("classpath:jsonschema/book.json") Book bookDto) { |
| 49 | + //... |
| 50 | + return bookDto; |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +## Example project |
| 56 | +Head over to [http://github.com/JanLoebel/json-schema-validation-starter-example](http://github.com/JanLoebel/json-schema-validation-starter-example) to checkout the sample project. |
| 57 | + |
| 58 | +## Contribution |
| 59 | +Please feel free to improve or modify the code and open a Pull-Request! Any contribution is welcome :) |
| 60 | + |
| 61 | +## License |
| 62 | +MIT License |
| 63 | + |
| 64 | +Copyright (c) 2019 Jan Löbel |
| 65 | + |
| 66 | +See LICENSE file for details. |
0 commit comments