Skip to content

Commit

Permalink
Final commit for raml-org#678
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbelang authored and juanchib committed Mar 4, 2020
1 parent 8b76911 commit 457ee9b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.junit.After;
import org.junit.Test;
import org.raml.yagi.framework.grammar.rule.BooleanTypeRule;
import org.raml.yagi.framework.util.DateUtils;

import java.io.File;
Expand All @@ -36,6 +37,7 @@ public void clearProperties()
{
clearFailOnWarning();
DateUtils.FOUR_YEARS_VALIDATION = true;
System.clearProperty(BooleanTypeRule.STRICT_BOOLEANS);
// DateUtils.setFormatters();
}

Expand All @@ -56,14 +58,30 @@ public void doNotFailOnWarning() throws IOException
assertThat(ramlModelResult.hasErrors(), is(false));
}

@Test
public void failOnString() throws IOException
{
System.setProperty(BooleanTypeRule.STRICT_BOOLEANS, "true");
RamlModelResult ramlModelResult = getStringBoolean();
assertThat(ramlModelResult.hasErrors(), is(true));
assertThat(ramlModelResult.getValidationResults().size(), is(1));
}

@Test
public void doNotFailString() throws IOException
{
RamlModelResult ramlModelResult = getStringBoolean();
assertThat(ramlModelResult.hasErrors(), is(false));
}

private RamlModelResult getJsonSchemaApi()
{
return getApi("src/test/resources/org/raml/v2/api/v10/system-properties/jsonschema-fail-on-warning.raml");
}

private RamlModelResult getDateTimeApi()
private RamlModelResult getStringBoolean()
{
return getApi("src/test/resources/org/raml/v2/api/v10/system-properties/date-only-validation.raml");
return getApi("src/test/resources/org/raml/v2/api/v10/system-properties/string-boolean.raml");
}

private RamlModelResult getApi(String pathname)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#%RAML 1.0
title: Sample API
types:
TestType:
type: object
properties:
count?: integer
flag?: boolean
name?: string
/test:
post:
body:
application/json:
type: TestType
example: |
{ "count": 12, "flag": "true", "name": "Joe" }
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class BooleanTypeRule extends AbstractTypeRule
{
private static final String STRICT_BOOLEANS = "org.raml.strict_booleans";
public static final String STRICT_BOOLEANS = "org.raml.strict_booleans";

private final static String TRUE = "true";
private final static String FALSE = "false";
Expand Down

0 comments on commit 457ee9b

Please sign in to comment.