phenopackets / phenopacket-tools

An app and library for building, conversion, and validation of GA4GH Phenopackets.
http://phenopackets.org/phenopacket-tools/stable/
GNU General Public License v3.0
12 stars 5 forks source link

refactoring #82

Closed pnrobinson closed 2 years ago

pnrobinson commented 2 years ago

Next attempt to define API. Still it is a bit clumsy, see example use in JsonSchemaValidatorTest, e.g.

@Test
    public void testValidationOfSimpleInValidPhenopacket() {
        PhenopacketValidatorOld validator = FACTORY.getValidatorForType(ValidatorInfo.generic()).get();
        String invalidPhenopacketJson = "{\"disney\" : \"donald\"}";

        List<? extends ValidationItem> errors = validator.validate(invalidPhenopacketJson);
        assertEquals(3, errors.size());
        ValidationItem error = errors.get(0);
        // JsonError.CATEGORY is "JSON"
        assertEquals(JsonError.CATEGORY, error.errorType().category());
        assertEquals(JsonError.REQUIRED, error.errorType().subcategory());
        assertEquals("$.id: is missing but it is required", error.errorType().message());
        error = errors.get(1);
        assertEquals(JsonError.CATEGORY, error.errorType().category());
        assertEquals(JsonError.REQUIRED, error.errorType().subcategory());
       assertEquals("$.metaData: is missing but it is required", error.errorType().message());
        error = errors.get(2);

        assertEquals(JsonError.CATEGORY, error.errorType().category());
        assertEquals(JsonError.ADDITIONAL_PROPERTIES, error.errorType().subcategory());
        assertEquals("$.disney: is not defined in the schema and the schema does not allow additional properties", 
       error.errorType().message());
    }
pnrobinson commented 2 years ago

I will merge this now and continue