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

Commit 04c56a4

Browse files
committed
Adds discriminator tests
1 parent 7c69a95 commit 04c56a4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

raml-parser-2/src/test/java/org/raml/v2/api/TypeDeclarationValidationTestCase.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,27 @@ private void arrayValidation(RamlModelResult ramlModelResult)
5959
assertFalse(validationResults.isEmpty());
6060
assertEquals(validationResults.get(0).getMessage(), "Invalid type String, expected Float");
6161
}
62+
63+
@Test
64+
public void discriminatorValidation()
65+
{
66+
File input = new File("src/test/resources/org/raml/v2/api/v10/validation/discriminator-validation.raml");
67+
assertTrue(input.isFile());
68+
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(input);
69+
70+
subTypeValidation(ramlModelResult);
71+
}
72+
73+
private void subTypeValidation(RamlModelResult ramlModelResult)
74+
{
75+
List<TypeDeclaration> typeDeclarations = ramlModelResult.getApiV10().resources().get(0).methods().get(0).body();
76+
77+
// valid
78+
assertTrue(typeDeclarations.get(0).validate("{\"eventType\":\"foo\", \"bar\":\"\"}").isEmpty());
79+
// invalid
80+
assertFalse(typeDeclarations.get(0).validate("{\"eventType\":\"foo\"}").isEmpty());
81+
// invalid
82+
assertFalse(typeDeclarations.get(0).validate("{}").isEmpty());
83+
}
84+
6285
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#%RAML 1.0
2+
title: test validate
3+
4+
types:
5+
event:
6+
type: object
7+
discriminator: eventType
8+
properties:
9+
eventType: string
10+
11+
fooEvent:
12+
type: event
13+
discriminatorValue: foo
14+
properties:
15+
bar: string
16+
17+
/resource:
18+
post:
19+
body:
20+
application/json:
21+
type: fooEvent

0 commit comments

Comments
 (0)