Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.
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 @@ -65,7 +65,7 @@ public NodeBuilder getBuilderForTuple(NodeTuple tuple)
return tupleBuilder;
}
}
throw new RuntimeException("Builder not found for " + tuple);
return null;
}

protected Map<String, TupleBuilder<?, ?>> getBuilders()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ public boolean onTupleStart(NodeTuple nodeTuple)
if (currentBuilder != null)
{
NodeBuilder<?> builder = currentBuilder.getBuilderForTuple(nodeTuple);
if (builder == null)
{
return false;
}
builderContext.push(builder);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ public boolean onTupleStart(NodeTuple nodeTuple)
{
try
{
builder.onTupleStart(nodeTuple);
boolean found = builder.onTupleStart(nodeTuple);
if (!found)
{
return false;
}
MappingNode mapping = nodeTuple.getValueNode().getNodeId() == NodeId.mapping ? (MappingNode) nodeTuple.getValueNode() : null;
pushNode(nodeTuple.getKeyNode(), mapping);
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/raml/validation/ValidationTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.raml.validation;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
Expand All @@ -28,11 +29,13 @@

import org.junit.Ignore;
import org.junit.Test;
import org.raml.model.ActionType;
import org.raml.model.Raml;
import org.raml.parser.builder.AbstractRamlTestCase;
import org.raml.parser.rule.ValidationResult;
import org.raml.parser.tagresolver.ContextPath;
import org.raml.parser.visitor.IncludeInfo;
import org.raml.parser.visitor.RamlDocumentBuilder;

public class ValidationTestCase extends AbstractRamlTestCase
{
Expand Down Expand Up @@ -222,6 +225,21 @@ public void circularInclude()
assertThat(includeInfo.getLine() + 1, is(3));
}

@Test
public void unknownKey()
{
String resource = "org/raml/validation/unknown-key.yaml";

// validation reports the unknown key...
List<ValidationResult> validationResults = validateRaml(resource);
assertThat(validationResults.size(), is(1));
assertThat(validationResults.get(0).getMessage(), is("Unknown key: unknown"));

// ... but the parser doesn't choke on it
Raml validContent = new RamlDocumentBuilder().build(resource);
assertThat(validContent.getResource("/partiallyInvalid").getAction(ActionType.POST), is(notNullValue()));
}

@Test
public void badMediaTypeName()
{
Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/org/raml/validation/unknown-key.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#%RAML 0.8
title: unknown key
/partiallyInvalid:
post:
unknown:
body:
application/json: