diff --git a/raml-parser-2/src/test/java/org/raml/v2/api/TypeDeclarationValidationTestCase.java b/raml-parser-2/src/test/java/org/raml/v2/api/TypeDeclarationValidationTestCase.java index 179a489c..67b13e4a 100644 --- a/raml-parser-2/src/test/java/org/raml/v2/api/TypeDeclarationValidationTestCase.java +++ b/raml-parser-2/src/test/java/org/raml/v2/api/TypeDeclarationValidationTestCase.java @@ -59,4 +59,27 @@ private void arrayValidation(RamlModelResult ramlModelResult) assertFalse(validationResults.isEmpty()); assertEquals(validationResults.get(0).getMessage(), "Invalid type String, expected Float"); } + + @Test + public void discriminatorValidation() + { + File input = new File("src/test/resources/org/raml/v2/api/v10/validation/discriminator-validation.raml"); + assertTrue(input.isFile()); + RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(input); + + subTypeValidation(ramlModelResult); + } + + private void subTypeValidation(RamlModelResult ramlModelResult) + { + List typeDeclarations = ramlModelResult.getApiV10().resources().get(0).methods().get(0).body(); + + // valid + assertTrue(typeDeclarations.get(0).validate("{\"eventType\":\"foo\", \"bar\":\"\"}").isEmpty()); + // invalid + assertFalse(typeDeclarations.get(0).validate("{\"eventType\":\"foo\"}").isEmpty()); + // invalid + assertFalse(typeDeclarations.get(0).validate("{}").isEmpty()); + } + } diff --git a/raml-parser-2/src/test/resources/org/raml/v2/api/v10/validation/discriminator-validation.raml b/raml-parser-2/src/test/resources/org/raml/v2/api/v10/validation/discriminator-validation.raml new file mode 100644 index 00000000..a7a341dd --- /dev/null +++ b/raml-parser-2/src/test/resources/org/raml/v2/api/v10/validation/discriminator-validation.raml @@ -0,0 +1,21 @@ +#%RAML 1.0 +title: test validate + +types: + event: + type: object + discriminator: eventType + properties: + eventType: string + + fooEvent: + type: event + discriminatorValue: foo + properties: + bar: string + +/resource: + post: + body: + application/json: + type: fooEvent