Skip to content

Commit c41b83d

Browse files
authored
[docs] Beautify code blocks (#617)
* [docs] Beautify code blocks * [docs] Beautify code blocks
1 parent 4992d7d commit c41b83d

14 files changed

+50
-54
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ This is a Java implementation of the [JSON Schema Core Draft v4, v6, v7, v2019-0
1818

1919
It is the fastest Java JSON Schema Validator as far as I know. Here is the testing result compare with the other two open-source implementations. It is about 32 times faster than the Fge and five times faster than the Everit.
2020

21-
fge: 7130ms
22-
23-
everit-org: 1168ms
24-
25-
networknt: 223ms
21+
- fge: 7130ms
22+
- everit-org: 1168ms
23+
- networknt: 223ms
2624

2725
You can run the performance tests for three libraries from [https://github.com/networknt/json-schema-validator-perftest](https://github.com/networknt/json-schema-validator-perftest)
2826

@@ -44,7 +42,7 @@ Following the design principle of the Light Platform, this library has minimum d
4442

4543
Here are the dependencies.
4644

47-
```
45+
```xml
4846
<dependency>
4947
<groupId>com.fasterxml.jackson.core</groupId>
5048
<artifactId>jackson-databind</artifactId>
@@ -88,7 +86,7 @@ Maven:
8886

8987
Gradle:
9088

91-
```
89+
```java
9290
dependencies {
9391
compile(group: "com.networknt", name: "json-schema-validator", version: "1.0.73");
9492
}

doc/collector-context.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CollectorContext instance can be obtained by calling the getInstance static meth
1515

1616
Collectors are added to CollectorContext. Collectors allow to collect the objects. A Collector is added to CollectorContext with a name and corresponding Collector instance.
1717

18-
```
18+
```java
1919
CollectorContext collectorContext = CollectorContext.getInstance();
2020
collectorContext.add(SAMPLE_COLLECTOR_NAME, new Collector<List<String>>() {
2121
@Override
@@ -29,7 +29,7 @@ collectorContext.add(SAMPLE_COLLECTOR_NAME, new Collector<List<String>>() {
2929

3030
However there might be use cases where we want to add a simple Object like String, Integer, etc, into the Context. This can be done the same way a collector is added to the context.
3131

32-
```
32+
```java
3333
CollectorContext collectorContext = CollectorContext.getInstance();
3434
collectorContext.add(SAMPLE_COLLECTOR,"sample-string")
3535

@@ -38,7 +38,7 @@ collectorContext.add(SAMPLE_COLLECTOR,"sample-string")
3838
To validate the schema with the ability to use CollectorContext, validateAndCollect method has to be invoked on the JsonSchema class. This class returns a ValidationResult that contains the errors encountered during validation and a CollectorContext instance. Objects constructed by Collectors or directly added to CollectorContext can be retrieved from CollectorContext by using the name they were added with.
3939

4040

41-
```
41+
```java
4242
ValidationResult validationResult = jsonSchema.validateAndCollect(jsonNode);
4343
CollectorContext context = validationResult.getCollectorContext();
4444
List<String> contextValue = (List<String>)context.get(SAMPLE_COLLECTOR);
@@ -49,7 +49,7 @@ Note that CollectorContext will be removed from ThreadLocal once validateAndColl
4949

5050
There might be usecases where a collector needs to collect the data at multiple touch points. For example one usecase might be collecting data in a validator and a formatter. If you are using a Collector rather than a Object, the combine method of the Collector allows to define how we want to combine the data into existing Collector. CollectorContext combineWithCollector method calls the combine method on the Collector. User just needs to call the CollectorContext combineWithCollector method every time some data needs to merged into existing Collector. The collect method on the Collector is called by the framework at the end of validation to return the data that was collected.
5151

52-
```
52+
```java
5353
class CustomCollector implements Collector<List<String>> {
5454

5555
List<String> returnList = new ArrayList<String>();
@@ -81,7 +81,7 @@ collectorContext.combineWithCollector(SAMPLE_COLLECTOR, node.textValue());
8181

8282
One important thing to note when using Collectors is if we call get method on CollectorContext before the validation is complete, we would get back a Collector instance that was added to CollectorContext.
8383

84-
```
84+
```java
8585
// Returns Collector before validation is done.
8686
Collector<List<String>> collector = collectorContext.get(SAMPLE_COLLECTOR);
8787

@@ -92,7 +92,7 @@ List<String> data = collectorContext.get(SAMPLE_COLLECTOR);
9292

9393
If you are using simple objects and if the data needs to be collected from multiple touch points, logic is straightforward as shown.
9494

95-
```
95+
```java
9696

9797
CollectorContext collectorContext = CollectorContext.getInstance();
9898
// If collector name is not added to context add one.

doc/config.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Most of the configuration flags are used to control the difference between Swagg
1010

1111
#### How to use config
1212

13-
When you create a JsonSchema instance from the JsonSchemaFactory, you can pass an object of SchemaValidatorsConfig as the second parameter.
13+
When you create a `JsonSchema` instance from the `JsonSchemaFactory`, you can pass an object of SchemaValidatorsConfig as the second parameter.
1414

15-
```
15+
```java
1616
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
1717
config.setTypeLoose(false);
1818
JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schema, config);
@@ -46,7 +46,7 @@ For more details, please refer to this [issue](https://github.com/networknt/json
4646
Map of public, typically internet-accessible schema URLs to alternate locations; this allows for offline validation of schemas that refer to public URLs. This is merged with any mappings the sonSchemaFactory
4747
may have been built.
4848

49-
The type for this variable is Map<String, String>.
49+
The type for this variable is `Map<String, String>`.
5050

5151
* javaSemantics
5252

@@ -62,4 +62,4 @@ When set to true, can interpret round doubles as integers.
6262

6363
Note that setting `javaSemantics = true` will achieve the same functionality at this time.
6464

65-
For more details, please refer to this [issue](https://github.com/networknt/json-schema-validator/issues/344).
65+
For more details, please refer to this [issue](https://github.com/networknt/json-schema-validator/issues/344).

doc/cust-fetcher.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
The default URIFetcher implementation uses JDK connection/socket without handling network exceptions. It works in most of the cases; however, if you want to have a customized implementation, you can do so. One user has his implementation with urirest to handle the timeout. A detailed discussion can be found in this [issue](https://github.com/networknt/json-schema-validator/issues/240)
1+
The default `URIFetcher` implementation uses JDK connection/socket without handling network exceptions. It works in most of the cases; however, if you want to have a customized implementation, you can do so. One user has his implementation with urirest to handle the timeout. A detailed discussion can be found in this [issue](https://github.com/networknt/json-schema-validator/issues/240)

doc/cust-meta.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
How to use your customized meta schema?
22

3-
The library supports customized meta schema with this builder method. We have provided default instances for v4, v6, v7, and v2019-09 but users can always create their own JsonMetaSchema instance with customized meta schema.
3+
The library supports customized meta schema with this builder method. We have provided default instances for v4, v6, v7, and v2019-09 but users can always create their own `JsonMetaSchema` instance with customized meta schema.
44

55
https://github.com/networknt/json-schema-validator/blob/master/src/main/java/com/networknt/schema/JsonMetaSchema.java#L188
66

doc/cust-msg.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ We can provide the custom message in the json schema itself.
55

66
<b> Example of schema with default message: </b>
77

8-
````
8+
````json
99
{
1010
"type": "object",
1111
"properties": {
@@ -24,7 +24,7 @@ We can provide the custom message in the json schema itself.
2424

2525
<b> Example of schema with a custom message: </b>
2626

27-
````
27+
````json
2828
{
2929
"type": "object",
3030
"properties": {
@@ -46,7 +46,7 @@ We can provide the custom message in the json schema itself.
4646

4747

4848

49-
````
49+
````json
5050
"message": {
5151
[validationType] : [customMessage]
5252
}
@@ -59,4 +59,4 @@ Also, we can make format the dynamic message with properties returned from [Vali
5959

6060

6161

62-
Take a look at the [PR](https://github.com/networknt/json-schema-validator/pull/438)
62+
Take a look at the [PR](https://github.com/networknt/json-schema-validator/pull/438)

doc/ecma-262.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
For the pattern validator, we now have two options for regex in the library. The default one is java.util. regex; however, you can use the ECMA-262 standard library org.jruby.joni by configuration.
1+
For the pattern validator, we now have two options for regex in the library. The default one is `java.util.regex`; however, you can use the ECMA-262 standard library `org.jruby.joni` by configuration.
22

3-
As we know, the JSON schema is designed based on the Javascript language and its regex. The Java internal implementation has some differences which don't comply with the standard. For most users, these edge cases are not the issue as they are not using them anyway. Even when they are using it, they are expecting the Java regex result as the application is built on the Java platform. For users who want to ensure that they are using 100% standard patter validator, we have provided an option to override the default regex library with org.jruby.joni that is complying with the ECMA-262 standard.
3+
As we know, the JSON schema is designed based on the Javascript language and its regex. The Java internal implementation has some differences which don't comply with the standard. For most users, these edge cases are not the issue as they are not using them anyway. Even when they are using it, they are expecting the Java regex result as the application is built on the Java platform. For users who want to ensure that they are using 100% standard patter validator, we have provided an option to override the default regex library with `org.jruby.joni` that is complying with the ECMA-262 standard.
44

55
### Which one to choose?
66

7-
If you want a faster regex lib and don't care about the slight difference between Java and Javascript regex, then you don't need to do anything. The default regex lib is the java.util.regex.
7+
If you want a faster regex lib and don't care about the slight difference between Java and Javascript regex, then you don't need to do anything. The default regex lib is the `java.util.regex`.
88

9-
If you want to ensure full compliance, use the org.jruby.joni. It is 1.5 times slower then java.util.regex. Depending on your use case, it might not be an issue.
9+
If you want to ensure full compliance, use the `org.jruby.joni`. It is 1.5 times slower then `java.util.regex`. Depending on your use case, it might not be an issue.
1010

1111
### How to switch?
1212

1313
Here is the test case that shows how to pass a config object to use the ECMA-262 library.
1414

15-
```
15+
```java
1616
@Test(expected = JsonSchemaException.class)
1717
public void testInvalidPatternPropertiesValidatorECMA262() throws Exception {
1818
SchemaValidatorsConfig config = new SchemaValidatorsConfig();

doc/openapi-discriminators.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,3 @@ more examples in https://github.com/networknt/json-schema-validator/blob/master/
187187
}
188188
}
189189
```
190-
191-
###

doc/quickstart.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
## Quick Start
22

3-
To use the validator, we need to have both the JsonSchema object and JsonNode object constructed.
3+
To use the validator, we need to have both the `JsonSchema` object and `JsonNode` object constructed.
44
There are many ways to do that.
5-
Here is base test class, that shows several ways to construct these from String, Stream, Url, and JsonNode.
6-
Please pay attention to the JsonSchemaFactory class as it is the way to construct the JsonSchema object.
5+
Here is base test class, that shows several ways to construct these from `String`, `Stream`, `Url`, and `JsonNode`.
6+
Please pay attention to the `JsonSchemaFactory` class as it is the way to construct the `JsonSchema` object.
77

88
```java
99
public class BaseJsonSchemaValidatorTest {
@@ -54,7 +54,7 @@ public class BaseJsonSchemaValidatorTest {
5454

5555
}
5656
```
57-
And the following is one of the test cases in one of the test classes that extend from the above base class. As you can see, it constructs JsonSchema and JsonNode from String.
57+
And the following is one of the test cases in one of the test classes that extend from the above base class. As you can see, it constructs `JsonSchema` and `JsonNode` from `String`.
5858

5959
```java
6060
class Sample extends BaseJsonSchemaValidatorTest {

doc/schema-map.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Basically, you can specify a mapping in the builder. For more details, please ta
1818

1919
https://github.com/JMRI/JMRI/blob/master/java/src/jmri/server/json/schema-map.json
2020

21-
In case you provide the schema through an InputStream or a String to resolve $ref with URN (relative path), you need to provide the URNFactory to the JsonSchemaFactory.Builder.
22-
URNFactory interface will allow you to resolve URN to URI.
21+
In case you provide the schema through an `InputStream` or a `String` to resolve `$ref` with URN (relative path), you need to provide the `URNFactory` to the `JsonSchemaFactory.Builder.
22+
URNFactory` interface will allow you to resolve URN to URI.
2323

2424
please take a look at the test cases and the [PR](https://github.com/networknt/json-schema-validator/pull/274).

doc/specversion.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ or with default configuration
1313
JsonSchemaFactory validatorFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4));
1414
```
1515

16-
Please avoid using default getInstance(), which, internally, defaults to the SpecVersion.VersionFlag.V4 as the parameter. This is deprecated.
16+
Please avoid using default `getInstance()`, which, internally, defaults to the `SpecVersion.VersionFlag.V4` as the parameter. This is deprecated.
1717

1818
#### To create a draft V6 JsonSchemaFactory
1919

@@ -77,7 +77,7 @@ JsonSchemaFactory validatorFactory = JsonSchemaFactory.getInstance(SpecVersionDe
7777

7878
#### SpecVersion
7979

80-
A new class SpecVersion has been introduced to indicate which version of the specification is used when creating the JsonSchemaFactory. The SpecVersion has an enum and two methods to convert a long to an EnumSet or a set of VersionFlags to a long value.
80+
A new class `SpecVersion` has been introduced to indicate which version of the specification is used when creating the `JsonSchemaFactory`. The `SpecVersion` has an enum and two methods to convert a long to an `EnumSet` or a set of `VersionFlags` to a long value.
8181

8282
```java
8383
public enum VersionFlag {
@@ -110,19 +110,19 @@ For most of the validators, the version code should be 31, which is 11111. This
110110

111111
For example.
112112

113-
```
113+
```java
114114
MAXIMUM("maximum", "1011", new MessageFormat("{0}: must have a maximum value of {1}"), MaximumValidator.class, 31),
115115
```
116116

117117
Since if-then-else was introduced in the V7, it only works for V7, V2019-09 and V2020-12
118118

119-
```
119+
```java
120120
IF_THEN_ELSE("if", "1037", null, IfValidator.class, 28), // V7|V201909|V202012 11100
121121
```
122122

123123
For exclusiveMaximum, it was introduced from V6
124124

125-
```
125+
```java
126126
EXCLUSIVE_MAXIMUM("exclusiveMaximum", "1038", new MessageFormat("{0}: must have a exclusive maximum value of {1}"), ExclusiveMaximumValidator.class, 30), // V6|V7|V201909|V202012
127127
```
128128

@@ -142,13 +142,13 @@ public static List<ValidatorTypeCode> getNonFormatKeywords(SpecVersion.VersionFl
142142

143143
#### JsonMetaSchema
144144

145-
We have created four different static classes V4, V6, V7, V201909 and V202012 to build different JsonMetaSchema instances.
145+
We have created four different static classes V4, V6, V7, V201909 and V202012 to build different `JsonMetaSchema` instances.
146146

147147
For the BUILDIN_FORMATS, there is a common section, and each static class has its version-specific BUILDIN_FORMATS section.
148148

149149
#### JsonSchemaFactory
150150

151-
The getInstance supports a parameter SpecVersion.VersionFlag to get the right instance of the JsonMetaShema to create the factory. If there is no parameter, then V4 is used by default.
151+
The getInstance supports a parameter `SpecVersion.VersionFlag` to get the right instance of the `JsonMetaShema` to create the factory. If there is no parameter, then V4 is used by default.
152152

153153
```java
154154
@Deprecated

doc/validators.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If `if` is valid, `then` must also be valid (and `else` is ignored.) If `if` is
1414
For usage, please refer to the test cases at https://github.com/networknt/json-schema-validator/blob/master/src/test/resources/draft7/if-then-else.json
1515

1616
### Custom Validators
17-
````
17+
````java
1818
@Bean
1919
public JsonSchemaFactory mySchemaFactory() {
2020
// base on JsonMetaSchema.V201909 copy code below
@@ -69,7 +69,7 @@ public class GroovyKeyword extends AbstractKeyword {
6969
}
7070
````
7171
You can use GroovyKeyword like below:
72-
````
72+
````json
7373
{
7474
"type": "object",
7575
"properties": {
@@ -87,7 +87,7 @@ In this library, if the format keyword is "email", "uuid", "date", "date-time",
8787

8888
If you want to override this behavior, do as below.
8989

90-
```
90+
```java
9191
public JsonSchemaFactory mySchemaFactory() {
9292
// base on JsonMetaSchema.V201909 copy code below
9393
String URI = "https://json-schema.org/draft/2019-09/schema";
@@ -103,4 +103,4 @@ public JsonSchemaFactory mySchemaFactory() {
103103
.addMetaSchema(overrideEmailValidatorMetaSchema)
104104
.build();
105105
}
106-
```
106+
```

doc/yaml-line-numbers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A great feature of json-schema-validator is it's ability to validate YAML docume
88

99
One solution is to use a custom [JsonNodeFactory](https://fasterxml.github.io/jackson-databind/javadoc/2.10/com/fasterxml/jackson/databind/node/JsonNodeFactory.html) that returns custom JsonNode objects which are created during initial parsing, and which record the original YAML locations that were being parsed at the time they were created. The example below shows this
1010

11-
```
11+
```java
1212
public static class MyNodeFactory extends JsonNodeFactory
1313
{
1414
YAMLParser yp;
@@ -69,7 +69,7 @@ We can be as simple or fancy as we like in the `JsonNode` subclassses, but basic
6969

7070
Those could be the same thing of course, but in our case we separated them as shown in the following example
7171

72-
```
72+
```java
7373
public interface LocationProvider
7474
{
7575
LocationDetails getLocationDetails();
@@ -193,7 +193,7 @@ Those could be the same thing of course, but in our case we separated them as sh
193193

194194
With the pieces we now have, we just need to tell the YAML library to make of use them, which involves a minor and simple modification to the normal sequence of processing.
195195

196-
```
196+
```java
197197
this.yamlFactory = new YAMLFactory();
198198

199199
try (YAMLParser yp = yamlFactory.createParser(f);)
@@ -235,7 +235,7 @@ Some notes on what is happening here:
235235
Having got everything prepared, actually getting the line locations is rather easy
236236

237237

238-
```
238+
```java
239239
void processJsonItems(JsonNode item)
240240
{
241241
Iterator<Map.Entry<String, JsonNode>> iter = item.fields();
@@ -268,7 +268,7 @@ Any failures validation against the schema come back in the form of a set of `Va
268268

269269
Within the `ValidationMessage` object is something called the 'path' of the error, which we can access with the `getPath()` method. The syntax of this path is not exactly the same as a regular [JsonPointer](https://fasterxml.github.io/jackson-core/javadoc/2.10/com/fasterxml/jackson/core/JsonPointer.html) object, but it is sufficiently close as to be convertible. And, once converted, we can use that pointer for locating the appropriate `JsonNode`. The following couple of methods can be used to automate this process
270270

271-
```
271+
```java
272272
JsonNode findJsonNode(ValidationMessage msg, JsonNode rootNode)
273273
{
274274
// munge the ValidationMessage path

doc/yaml.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ One of the features of this library is to validate the YAML file in addition to
44

55
Add the dependency
66

7-
```
7+
```xml
88
<dependency>
99
<groupId>com.fasterxml.jackson.dataformat</groupId>
1010
<artifactId>jackson-dataformat-yaml</artifactId>
@@ -15,7 +15,7 @@ Add the dependency
1515
and create object mapper using yaml factory i.e `ObjectMapper objMapper =new ObjectMapper(new YAMLFactory());`
1616

1717
#### Example
18-
```
18+
```java
1919
JsonSchemaFactory factory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).objectMapper(mapper).build(); /* Using draft-07. You can choose anyother draft.*/
2020
JsonSchema schema = factory.getSchema(YamlOperations.class.getClassLoader().getResourceAsStream("your-schema.json"));
2121

0 commit comments

Comments
 (0)