Skip to content

makintsian/schema-validator

Repository files navigation

schema-validator

Build Status Maven Central GitHub release

Validates json and xml paths

Download

Maven

<dependency>
    <groupId>io.github.makintsian</groupId>
    <artifactId>schema-validator</artifactId>
    <version>0.0.1</version>
</dependency>

Gradle

implementation 'io.github.makintsian:schema-validator:0.0.1'

Example

Files .json and .xml

{
  "firstName": "John",
  "lastName": "Doe",
  "age": 26,
  "address": {
    "streetAddress": "naist street",
    "city": "Nara",
    "postalCode": "630-0192"
  }
  "phoneNumbers": [
    {
      "type": "iPhone",
      "number": "0123-4567-8888"
    },
    {
      "type": "home",
      "number": "0123-4567-8910"
    }
  ]
}
<breakfast_menu>
    <food>
        <name>Belgian Waffles</name>
        <price>$5.95</price>
        <description>Two of our famous Belgian Waffles</description>
        <calories>650</calories>
    </food>
</breakfast_menu>

Schema .yaml

json_schema:
  - 'firstName'
  - 'lastName'
  - 'age'
  - 'address.streetAddress'
  - 'address.city'
  - 'address.postalCode'
  - 'phoneNumbers[*].type'
  - 'phoneNumbers[*].number'
xml_schema:
  - 'breakfast_menu/food/name'
  - 'breakfast_menu/food/price'
  - 'breakfast_menu/food/description'
  - 'breakfast_menu/food/calories'

Parse json and xml

ParsePaths parsePaths = new JsonParsePaths(${json});
List<String> paths = parsePaths.getPathsList();
ParsePaths parsePaths = new XmlParsePaths(${xml});
List<String> paths = parsePaths.getPathsList();

Validate json and xml

SchemaValidator schemaValidator = SchemaValidator.newBuilder()
                .withSchema(${schema})
                .build();
schemaValidator.validateJson(${json}, "json_schema");
SchemaValidator schemaValidator = SchemaValidator.newBuilder()
                .withSchema(${schema})
                .build();
schemaValidator.validateXml(${xml}, "xml_schema");