From 457ee9b3f89456c2acbcf1d77bc60320834ea9d6 Mon Sep 17 00:00:00 2001 From: jpbelang Date: Wed, 8 Jan 2020 20:10:30 -0500 Subject: [PATCH] Final commit for #678 --- .../raml/v2/api/SystemPropertiesTestCase.java | 22 +++++++++++++++++-- .../v10/system-properties/string-boolean.raml | 16 ++++++++++++++ .../grammar/rule/BooleanTypeRule.java | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 raml-parser-2/src/test/resources/org/raml/v2/api/v10/system-properties/string-boolean.raml diff --git a/raml-parser-2/src/test/java/org/raml/v2/api/SystemPropertiesTestCase.java b/raml-parser-2/src/test/java/org/raml/v2/api/SystemPropertiesTestCase.java index e7aebc55..62962b47 100644 --- a/raml-parser-2/src/test/java/org/raml/v2/api/SystemPropertiesTestCase.java +++ b/raml-parser-2/src/test/java/org/raml/v2/api/SystemPropertiesTestCase.java @@ -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; @@ -36,6 +37,7 @@ public void clearProperties() { clearFailOnWarning(); DateUtils.FOUR_YEARS_VALIDATION = true; + System.clearProperty(BooleanTypeRule.STRICT_BOOLEANS); // DateUtils.setFormatters(); } @@ -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) diff --git a/raml-parser-2/src/test/resources/org/raml/v2/api/v10/system-properties/string-boolean.raml b/raml-parser-2/src/test/resources/org/raml/v2/api/v10/system-properties/string-boolean.raml new file mode 100644 index 00000000..4ded3e13 --- /dev/null +++ b/raml-parser-2/src/test/resources/org/raml/v2/api/v10/system-properties/string-boolean.raml @@ -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" } \ No newline at end of file diff --git a/yagi/src/main/java/org/raml/yagi/framework/grammar/rule/BooleanTypeRule.java b/yagi/src/main/java/org/raml/yagi/framework/grammar/rule/BooleanTypeRule.java index f536e507..7aa43f52 100644 --- a/yagi/src/main/java/org/raml/yagi/framework/grammar/rule/BooleanTypeRule.java +++ b/yagi/src/main/java/org/raml/yagi/framework/grammar/rule/BooleanTypeRule.java @@ -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";