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

Adds discriminator tests #602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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