Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Adds discriminator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jam01 committed Oct 2, 2019
1 parent 7c69a95 commit 04c56a4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeDeclaration> 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());
}

}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 04c56a4

Please sign in to comment.