diff --git a/pom.xml b/pom.xml
index b543ad69..a0d30353 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
org.raml
raml-parser-parent
- 1.0.46-SNAPSHOT
+ 1.0.48-SNAPSHOT
pom
Raml Java Parser 2nd generation parent
Raml parser implemented in java
diff --git a/raml-parser-2/pom.xml b/raml-parser-2/pom.xml
index 6fe5f2a9..befd612e 100644
--- a/raml-parser-2/pom.xml
+++ b/raml-parser-2/pom.xml
@@ -3,7 +3,7 @@
org.raml
raml-parser-parent
- 1.0.46-SNAPSHOT
+ 1.0.48-SNAPSHOT
raml-parser-2
jar
diff --git a/raml-parser-2/src/test/java/org/raml/yagi/framework/grammar/rule/BooleanTypeRuleTest.java b/raml-parser-2/src/test/java/org/raml/yagi/framework/grammar/rule/BooleanTypeRuleTest.java
new file mode 100644
index 00000000..fe6c6612
--- /dev/null
+++ b/raml-parser-2/src/test/java/org/raml/yagi/framework/grammar/rule/BooleanTypeRuleTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2013 (c) MuleSoft, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package org.raml.yagi.framework.grammar.rule;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.raml.yagi.framework.nodes.BooleanNode;
+import org.raml.yagi.framework.nodes.StringNodeImpl;
+import org.raml.yagi.framework.nodes.jackson.JBooleanNode;
+import org.raml.yagi.framework.nodes.snakeyaml.SYBooleanNode;
+import org.raml.yagi.framework.nodes.snakeyaml.SYStringNode;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created. There, you have it.
+ */
+public class BooleanTypeRuleTest
+{
+
+ @Test
+ public void booleanWillMatchString()
+ {
+
+ BooleanTypeRule rule = new BooleanTypeRule(true);
+ assertFalse(rule.matches(new StringNodeImpl("false")));
+ assertFalse(rule.matches(new StringNodeImpl("true")));
+ assertFalse(rule.matches(new StringNodeImpl("anythingElse")));
+ }
+
+ @Test
+ public void booleanWontMatchString()
+ {
+
+ BooleanTypeRule rule = new BooleanTypeRule(false);
+ assertTrue(rule.matches(new StringNodeImpl("false")));
+ assertTrue(rule.matches(new StringNodeImpl("true")));
+ assertFalse(rule.matches(new StringNodeImpl("anythingElse")));
+ }
+
+ @Test
+ public void booleanMatchesBoolean()
+ {
+
+ BooleanNode booleanNode = Mockito.mock(BooleanNode.class);
+ BooleanTypeRule rule = new BooleanTypeRule(true);
+ assertTrue(rule.matches(booleanNode));
+ }
+
+}
\ No newline at end of file
diff --git a/raml-parser-2/src/test/resources/org/raml/v2/parser/examples/stringbooleans/input.raml b/raml-parser-2/src/test/resources/org/raml/v2/parser/examples/stringbooleans/input.raml
new file mode 100644
index 00000000..4ded3e13
--- /dev/null
+++ b/raml-parser-2/src/test/resources/org/raml/v2/parser/examples/stringbooleans/input.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/raml-parser-2/src/test/resources/org/raml/v2/parser/examples/stringbooleans/output.txt b/raml-parser-2/src/test/resources/org/raml/v2/parser/examples/stringbooleans/output.txt
new file mode 100644
index 00000000..c5096f74
--- /dev/null
+++ b/raml-parser-2/src/test/resources/org/raml/v2/parser/examples/stringbooleans/output.txt
@@ -0,0 +1,97 @@
+RamlDocumentNode (Start: 11 , End: 291, On: input.raml, Source: SYObjectNode)
+ KeyValueNodeImpl (Start: 11 , End: 28, On: input.raml)
+ SYStringNode: "title" (Start: 11 , End: 16, On: input.raml)
+ OverlayableObjectNodeImpl (Start: 18 , End: 28, On: input.raml, Source: SYStringNode)
+ KeyValueNodeImpl (Start: 11 , End: 28, On: input.raml)
+ StringNodeImpl: "value" (Start: -1 , End: -1)
+ OverlayableStringNode: "Sample API" (Start: 18 , End: 28, On: input.raml)
+ TypesNode (Start: 29 , End: 144, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "types" (Start: 29 , End: 34, On: input.raml)
+ SYObjectNode (Start: 38 , End: 144, On: input.raml)
+ TypeDeclarationField (Start: 38 , End: 144, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "TestType" (Start: 38 , End: 46, On: input.raml)
+ TypeDeclarationNode (Start: 52 , End: 144, On: input.raml, Source: SYObjectNode)
+ KeyValueNodeImpl (Start: 52 , End: 64, On: input.raml)
+ SYStringNode: "type" (Start: 52 , End: 56, On: input.raml)
+ NativeTypeExpressionNode: "object" (Start: 58 , End: 64, On: input.raml, Source: SYStringNode)
+ FacetNode (Start: 69 , End: 144, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "properties" (Start: 69 , End: 79, On: input.raml)
+ SYObjectNode (Start: 87 , End: 144, On: input.raml)
+ PropertyNode (Start: 87 , End: 102, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "count?" (Start: 87 , End: 93, On: input.raml)
+ TypeDeclarationNode (Start: 95 , End: 102, On: input.raml, Source: SYStringNode)
+ KeyValueNodeImpl (Start: -1 , End: 102)
+ StringNodeImpl: "type" (Start: -1 , End: -1)
+ NativeTypeExpressionNode: "integer" (Start: 95 , End: 102, On: input.raml, Source: NativeTypeExpressionNode)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "displayName" (Start: -1 , End: -1)
+ ObjectNodeImpl (Start: -1 , End: -1)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "value" (Start: -1 , End: -1)
+ OverlayableStringNode: "count?" (Start: -1 , End: -1, Source: SYStringNode)
+ PropertyNode (Start: 109 , End: 123, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "flag?" (Start: 109 , End: 114, On: input.raml)
+ TypeDeclarationNode (Start: 116 , End: 123, On: input.raml, Source: SYStringNode)
+ KeyValueNodeImpl (Start: -1 , End: 123)
+ StringNodeImpl: "type" (Start: -1 , End: -1)
+ NativeTypeExpressionNode: "boolean" (Start: 116 , End: 123, On: input.raml, Source: NativeTypeExpressionNode)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "displayName" (Start: -1 , End: -1)
+ ObjectNodeImpl (Start: -1 , End: -1)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "value" (Start: -1 , End: -1)
+ OverlayableStringNode: "flag?" (Start: -1 , End: -1, Source: SYStringNode)
+ PropertyNode (Start: 130 , End: 143, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "name?" (Start: 130 , End: 135, On: input.raml)
+ TypeDeclarationNode (Start: 137 , End: 143, On: input.raml, Source: SYStringNode)
+ KeyValueNodeImpl (Start: -1 , End: 143)
+ StringNodeImpl: "type" (Start: -1 , End: -1)
+ NativeTypeExpressionNode: "string" (Start: 137 , End: 143, On: input.raml, Source: NativeTypeExpressionNode)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "displayName" (Start: -1 , End: -1)
+ ObjectNodeImpl (Start: -1 , End: -1)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "value" (Start: -1 , End: -1)
+ OverlayableStringNode: "name?" (Start: -1 , End: -1, Source: SYStringNode)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "displayName" (Start: -1 , End: -1)
+ ObjectNodeImpl (Start: -1 , End: -1)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "value" (Start: -1 , End: -1)
+ OverlayableStringNode: "TestType" (Start: -1 , End: -1, Source: SYStringNode)
+ ResourceNode (Start: 144 , End: 291, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "/test" (Start: 144 , End: 149, On: input.raml)
+ SYObjectNode (Start: 153 , End: 291, On: input.raml)
+ MethodNode (Start: 153 , End: 291, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "post" (Start: 153 , End: 157, On: input.raml)
+ SYObjectNode (Start: 163 , End: 291, On: input.raml)
+ BodyNode (Start: 163 , End: 291, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "body" (Start: 163 , End: 167, On: input.raml)
+ SYObjectNode (Start: 175 , End: 291, On: input.raml)
+ KeyValueNodeImpl (Start: 175 , End: 291, On: input.raml)
+ SYStringNode: "application/json" (Start: 175 , End: 191, On: input.raml)
+ TypeDeclarationNode (Start: 201 , End: 291, On: input.raml, Source: SYObjectNode)
+ KeyValueNodeImpl (Start: 201 , End: 215, On: input.raml)
+ SYStringNode: "type" (Start: 201 , End: 205, On: input.raml)
+ NamedTypeExpressionNode TestType -> {TypeDeclarationNode RefStart: 52 , RefEnd: 144} (Start: 207 , End: 215, On: input.raml, Source: SYStringNode)
+ ExampleDeclarationNode (Start: 224 , End: 291, On: input.raml, Source: KeyValueNodeImpl)
+ SYStringNode: "example" (Start: 224 , End: 231, On: input.raml)
+ SYStringNode: "{ "count": 12, "flag": "true", "name": "Joe" }" (Start: 233 , End: 291, On: input.raml)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "displayName" (Start: -1 , End: -1)
+ ObjectNodeImpl (Start: -1 , End: -1)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "value" (Start: -1 , End: -1)
+ OverlayableStringNode: "application/json" (Start: -1 , End: -1, Source: SYStringNode)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "displayName" (Start: -1 , End: -1)
+ ObjectNodeImpl (Start: -1 , End: -1)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "value" (Start: -1 , End: -1)
+ OverlayableStringNode: "post" (Start: -1 , End: -1, Source: SYStringNode)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "displayName" (Start: -1 , End: -1)
+ ObjectNodeImpl (Start: -1 , End: -1)
+ KeyValueNodeImpl (Start: -1 , End: -1)
+ StringNodeImpl: "value" (Start: -1 , End: -1)
+ OverlayableStringNode: "/test" (Start: -1 , End: -1, Source: SYStringNode)
\ No newline at end of file
diff --git a/yagi/pom.xml b/yagi/pom.xml
index a9575f3e..cc2b2fd3 100644
--- a/yagi/pom.xml
+++ b/yagi/pom.xml
@@ -3,7 +3,7 @@
org.raml
raml-parser-parent
- 1.0.46-SNAPSHOT
+ 1.0.48-SNAPSHOT
yagi
jar
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 df52c941..f536e507 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,9 +29,23 @@
public class BooleanTypeRule extends AbstractTypeRule
{
+ private static final String STRICT_BOOLEANS = "org.raml.strict_booleans";
+
private final static String TRUE = "true";
private final static String FALSE = "false";
+ private final boolean strictBoolean;
+
+ public BooleanTypeRule()
+ {
+ this.strictBoolean = Boolean.parseBoolean(System.getProperty(STRICT_BOOLEANS, "false"));
+ }
+
+ BooleanTypeRule(boolean strictBoolean)
+ {
+ this.strictBoolean = strictBoolean;
+ }
+
@Nonnull
@Override
public List getSuggestions(Node node, ParsingContext context)
@@ -42,7 +56,7 @@ public List getSuggestions(Node node, ParsingContext context)
@Override
public boolean matches(@Nonnull Node node)
{
- if (node instanceof StringNode)
+ if (!strictBoolean && (node instanceof StringNode))
{
String value = ((StringNode) node).getValue();
return TRUE.equals(value) || FALSE.equals(value);