Allow leafref type to have require-instance substatement in Yang 1.1 models.
Change-Id: I96cc337176abbb3e2fdb1ae22a83ba7810190fbe
Signed-off-by: Igor Foltin <ifoltin@cisco.com>
final class BaseLeafrefType extends AbstractBaseType<LeafrefTypeDefinition> implements LeafrefTypeDefinition {
private final RevisionAwareXPath pathStatement;
+ private final boolean requireInstance;
- BaseLeafrefType(final SchemaPath path, final RevisionAwareXPath pathStatement, final List<UnknownSchemaNode> unknownSchemaNodes) {
+ BaseLeafrefType(final SchemaPath path, final RevisionAwareXPath pathStatement, final boolean requireInstance,
+ final List<UnknownSchemaNode> unknownSchemaNodes) {
super(path, unknownSchemaNodes);
this.pathStatement = Preconditions.checkNotNull(pathStatement);
+ this.requireInstance = requireInstance;
}
@Override
return pathStatement;
}
+ @Override
+ public boolean requireInstance() {
+ return requireInstance;
+ }
+
@Override
public int hashCode() {
return TypeDefinitions.hashCode(this);
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
final class DerivedLeafrefType extends AbstractDerivedType<LeafrefTypeDefinition> implements LeafrefTypeDefinition {
+
DerivedLeafrefType(final LeafrefTypeDefinition baseType, final SchemaPath path, final Object defaultValue,
final String description, final String reference, final Status status, final String units,
final Collection<UnknownSchemaNode> unknownSchemaNodes) {
return baseType().getPathStatement();
}
+ @Override
+ public boolean requireInstance() {
+ return baseType().requireInstance();
+ }
+
@Override
public int hashCode() {
return TypeDefinitions.hashCode(this);
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
-public final class InstanceIdentifierTypeBuilder extends AbstractRestrictedTypeBuilder<InstanceIdentifierTypeDefinition> {
- private boolean requireInstance;
+public final class InstanceIdentifierTypeBuilder extends RequireInstanceRestrictedTypeBuilder<InstanceIdentifierTypeDefinition> {
InstanceIdentifierTypeBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
super(Preconditions.checkNotNull(baseType), path);
- this.requireInstance = baseType.requireInstance();
- }
-
- public InstanceIdentifierTypeBuilder setRequireInstance(final boolean requireInstance) {
- if (this.requireInstance) {
- Preconditions.checkArgument(!requireInstance, "Cannot switch require-instance off in type %s", getPath());
- }
-
- this.requireInstance = requireInstance;
- touch();
- return this;
}
@Override
InstanceIdentifierTypeDefinition buildType() {
- if (requireInstance == getBaseType().requireInstance()) {
+ if (getRequireInstance() == getBaseType().requireInstance()) {
return getBaseType();
}
- return new RestrictedInstanceIdentifierType(getBaseType(), getPath(), getUnknownSchemaNodes(), requireInstance);
+ return new RestrictedInstanceIdentifierType(getBaseType(), getPath(), getUnknownSchemaNodes(), getRequireInstance());
}
}
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-public final class LeafrefTypeBuilder extends TypeBuilder<LeafrefTypeDefinition> {
+public final class LeafrefTypeBuilder extends RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition> {
private RevisionAwareXPath pathStatement;
LeafrefTypeBuilder(final SchemaPath path) {
}
@Override
- public LeafrefTypeDefinition build() {
- return new BaseLeafrefType(getPath(), pathStatement, getUnknownSchemaNodes());
+ LeafrefTypeDefinition buildType() {
+ return new BaseLeafrefType(getPath(), pathStatement, getRequireInstance(), getUnknownSchemaNodes());
}
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yangtools.yang.model.util.type;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+
+@Beta
+public abstract class RequireInstanceRestrictedTypeBuilder<T extends TypeDefinition<T>>
+ extends AbstractRestrictedTypeBuilder<T> {
+
+ private boolean requireInstance;
+
+ RequireInstanceRestrictedTypeBuilder(final T baseType, final SchemaPath path) {
+ super(baseType, path);
+ }
+
+ public final void setRequireInstance(final boolean requireInstance) {
+ if (this.requireInstance) {
+ Preconditions.checkArgument(requireInstance, "Cannot switch off require-instance in type %s", getPath());
+ }
+
+ this.requireInstance = requireInstance;
+ touch();
+ }
+
+ final boolean getRequireInstance() {
+ return requireInstance;
+ }
+}
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
final class RestrictedLeafrefType extends AbstractRestrictedType<LeafrefTypeDefinition> implements LeafrefTypeDefinition {
+
+ private final boolean requireInstance;
+
RestrictedLeafrefType(final LeafrefTypeDefinition baseType, final SchemaPath path,
- final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+ final Collection<UnknownSchemaNode> unknownSchemaNodes, final boolean requireInstance) {
super(baseType, path, unknownSchemaNodes);
+
+ this.requireInstance = requireInstance;
}
@Override
return getBaseType().getPathStatement();
}
+ @Override
+ public boolean requireInstance() {
+ return requireInstance;
+ }
+
@Override
public int hashCode() {
return TypeDefinitions.hashCode(this);
return new InstanceIdentifierTypeBuilder(baseType, path);
}
- public static TypeBuilder<LeafrefTypeDefinition> newLeafrefBuilder(final LeafrefTypeDefinition baseType, final SchemaPath path) {
- return new AbstractRestrictedTypeBuilder<LeafrefTypeDefinition>(baseType, path) {
+ public static RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition> newLeafrefBuilder(
+ final LeafrefTypeDefinition baseType, final SchemaPath path) {
+ return new RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition>(baseType, path) {
@Override
LeafrefTypeDefinition buildType() {
- return new RestrictedLeafrefType(getBaseType(), getPath(), getUnknownSchemaNodes());
+ if (getRequireInstance() == getBaseType().requireInstance()) {
+ return getBaseType();
+ }
+ return new RestrictedLeafrefType(getBaseType(), getPath(), getUnknownSchemaNodes(), getRequireInstance());
}
};
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.util.type.LeafrefTypeBuilder;
public class LeafrefTest {
assertFalse("Objects shouldn't be equal.", leafref.equals(null));
assertFalse("Objects shouldn't be equal.", leafref.equals("test"));
}
+
+ @Test
+ public void testRequireInstanceSubstatement() {
+ final SchemaPath schemaPath = SchemaPath.create(true, QName.create("my-cont"), QName.create("my-leafref"));
+ final RevisionAwareXPathImpl path = new RevisionAwareXPathImpl("../my-leaf", false);
+
+ LeafrefTypeBuilder leafrefTypeBuilder = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(path);
+
+ leafrefTypeBuilder.setRequireInstance(false);
+ LeafrefTypeDefinition leafref = leafrefTypeBuilder.build();
+ assertFalse(leafref.requireInstance());
+
+ leafrefTypeBuilder.setRequireInstance(true);
+ leafref = leafrefTypeBuilder.build();
+ assertTrue(leafref.requireInstance());
+
+ leafrefTypeBuilder.setRequireInstance(true);
+ leafref = leafrefTypeBuilder.build();
+ assertTrue(leafref.requireInstance());
+
+ try {
+ leafrefTypeBuilder.setRequireInstance(false);
+ fail("An IllegalArgumentException should have been thrown.");
+ } catch (IllegalArgumentException ex) {
+ assertEquals("Cannot switch off require-instance in type AbsoluteSchemaPath{path=[my-cont, my-leafref]}",
+ ex.getMessage());
+ }
+
+ }
}
import com.google.common.base.Verify;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Multimap;
+import com.google.common.collect.Table;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnionSpecificationImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.LeafrefSpecificationRfc7950Support;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
private static final Logger LOG = LoggerFactory.getLogger(SourceSpecificContext.class);
- private static final Map<String, StatementSupport<?, ?, ?>> BUILTIN_TYPE_SUPPORTS =
- ImmutableMap.<String, StatementSupport<?, ?, ?>>builder()
- .put(TypeUtils.DECIMAL64, new Decimal64SpecificationImpl.Definition())
- .put(TypeUtils.UNION, new UnionSpecificationImpl.Definition())
- .put(TypeUtils.ENUMERATION, new EnumSpecificationImpl.Definition())
- .put(TypeUtils.LEAF_REF, new LeafrefSpecificationImpl.Definition())
- .put(TypeUtils.BITS, new BitsSpecificationImpl.Definition())
- .put(TypeUtils.IDENTITY_REF, new IdentityRefSpecificationImpl.Definition())
- .put(TypeUtils.INSTANCE_IDENTIFIER, new InstanceIdentifierSpecificationImpl.Definition())
- .build();
+ private static final Table<YangVersion, String, StatementSupport<?, ?, ?>> BUILTIN_TYPE_SUPPORTS =
+ ImmutableTable.<YangVersion, String, StatementSupport<?, ?, ?>>builder()
+ .put(YangVersion.VERSION_1, TypeUtils.DECIMAL64, new Decimal64SpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.UNION, new UnionSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.ENUMERATION, new EnumSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.LEAF_REF, new LeafrefSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1_1, TypeUtils.LEAF_REF, new LeafrefSpecificationRfc7950Support())
+ .put(YangVersion.VERSION_1, TypeUtils.BITS, new BitsSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.IDENTITY_REF, new IdentityRefSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.INSTANCE_IDENTIFIER, new InstanceIdentifierSpecificationImpl.Definition())
+ .build();
+
private static final QName TYPE = YangStmtMapping.TYPE.getStatementName();
private final Multimap<ModelProcessingPhase, ModifierImpl> modifiers = HashMultimap.create();
def = new StatementDefinitionContext<>(extension);
} else {
// type-body-stmts
- def = resolveTypeBodyStmts(name.getLocalName());
+ def = resolveTypeBodyStmts(name.getLocalName(), getRootVersion());
}
} else if (current != null && current.definition().getRepresentingClass().equals(UnknownStatementImpl.class)) {
/*
}
}
- private static StatementDefinitionContext<?, ?, ?> resolveTypeBodyStmts(final String typeArgument) {
- final StatementSupport<?, ?, ?> support = BUILTIN_TYPE_SUPPORTS.get(typeArgument);
+ private static StatementDefinitionContext<?, ?, ?> resolveTypeBodyStmts(final String typeArgument,
+ final YangVersion version) {
+ StatementSupport<?, ?, ?> support = BUILTIN_TYPE_SUPPORTS.get(version, typeArgument);
+
+ if (support == null) {
+ support = BUILTIN_TYPE_SUPPORTS.get(YangVersion.VERSION_1, typeArgument);
+ }
+
return support == null ? null : new StatementDefinitionContext<>(support);
}
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PathStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.LeafrefSpecification;
import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
.TYPE)
.addMandatory(YangStmtMapping.PATH)
- .addOptional(YangStmtMapping.REQUIRE_INSTANCE)
.build();
protected LeafrefSpecificationImpl(
return firstDeclared(PathStatement.class);
}
+ @Nullable
+ @Override
+ public RequireInstanceStatement getRequireInstance() {
+ return firstDeclared(RequireInstanceStatement.class);
+ }
+
}
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PathEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.RequireInstanceEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementImpl;
public final class LeafrefSpecificationEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, LeafrefSpecification>
for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
if (stmt instanceof PathEffectiveStatementImpl) {
builder.setPathStatement(((PathEffectiveStatementImpl) stmt).argument());
- }
- if (stmt instanceof UnknownEffectiveStatementImpl) {
+ } else if(stmt instanceof RequireInstanceEffectiveStatementImpl) {
+ builder.setRequireInstance(((RequireInstanceEffectiveStatementImpl)stmt).argument());
+ } else if (stmt instanceof UnknownEffectiveStatementImpl) {
builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt);
}
}
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.type.RequireInstanceRestrictedTypeBuilder;
import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.RequireInstanceEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementImpl;
+
+public final class LeafrefTypeEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, TypeStatement>
+ implements TypeEffectiveStatement<TypeStatement> {
+
+ private final LeafrefTypeDefinition typeDefinition;
-public final class LeafrefTypeEffectiveStatementImpl extends AbstractTypeEffectiveStatement<LeafrefTypeDefinition> {
public LeafrefTypeEffectiveStatementImpl(
final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
final LeafrefTypeDefinition baseType) {
- super(ctx, RestrictedTypes.newLeafrefBuilder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx)));
+ super(ctx);
+
+ final RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition> builder =
+ RestrictedTypes.newLeafrefBuilder(baseType, TypeUtils.typeEffectiveSchemaPath(ctx));
+
+ for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
+ if (stmt instanceof RequireInstanceEffectiveStatementImpl) {
+ builder.setRequireInstance(((RequireInstanceEffectiveStatementImpl) stmt).argument());
+ } else if (stmt instanceof UnknownEffectiveStatementImpl) {
+ builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt);
+ }
+ }
+
+ typeDefinition = builder.build();
+ }
+
+ @Nonnull
+ @Override
+ public LeafrefTypeDefinition getTypeDefinition() {
+ return typeDefinition;
}
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.LeafrefSpecificationImpl;
+
+/**
+ * Class providing necessary support for processing YANG 1.1 leafref statement.
+ */
+@Beta
+public class LeafrefSpecificationRfc7950Support extends LeafrefSpecificationImpl.Definition {
+ private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
+ .TYPE)
+ .addMandatory(YangStmtMapping.PATH)
+ .addOptional(YangStmtMapping.REQUIRE_INSTANCE)
+ .build();
+
+ @Override
+ protected SubstatementValidator getSubstatementValidator() {
+ return SUBSTATEMENT_VALIDATOR;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+
+public class LeafrefStatementTest {
+
+ @Test
+ public void testRequireInstanceInLeafrefs() throws ReactorException, FileNotFoundException, URISyntaxException,
+ ParseException {
+ final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/leafref-stmt/foo.yang");
+ assertNotNull(schemaContext);
+
+ final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-12-20");
+
+ final Module foo = schemaContext.findModuleByName("foo", revision);
+ assertNotNull(foo);
+
+ final Set<TypeDefinition<?>> typeDefinitions = foo.getTypeDefinitions();
+ assertEquals(1, typeDefinitions.size());
+
+ final TypeDefinition<?> typeDefinition = typeDefinitions.iterator().next();
+ final LeafrefTypeDefinition leafrefTypeDefinition = (LeafrefTypeDefinition) typeDefinition;
+ assertTrue(leafrefTypeDefinition.requireInstance());
+
+ final LeafSchemaNode leafrefA = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
+ "leafref-a"));
+ assertNotNull(leafrefA);
+ assertRequireInstanceInLeafref(leafrefA, true);
+
+ final LeafSchemaNode leafrefB = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
+ "leafref-b"));
+ assertNotNull(leafrefB);
+ assertRequireInstanceInLeafref(leafrefB, true);
+
+ final LeafSchemaNode leafrefC = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
+ "leafref-c"));
+ assertNotNull(leafrefC);
+ assertRequireInstanceInLeafref(leafrefC, false);
+ }
+
+ private static void assertRequireInstanceInLeafref(final LeafSchemaNode leaf, final boolean requireInstance) {
+ final LeafrefTypeDefinition leafrefTypeDefnition = (LeafrefTypeDefinition) leaf.getType();
+ assertEquals(requireInstance, leafrefTypeDefnition.requireInstance());
+ }
+
+ @Test
+ public void testInvalidYang10() throws ReactorException, FileNotFoundException, URISyntaxException, ParseException {
+ try {
+ StmtTestUtils.parseYangSource("/rfc7950/leafref-stmt/foo10.yang");
+ fail("Test should fail due to invalid Yang 1.0");
+ } catch (final ReactorException e) {
+ assertTrue(e.getCause().getMessage().startsWith("REQUIRE_INSTANCE is not valid for TYPE"));
+ }
+ }
+}
--- /dev/null
+module foo {
+ namespace foo-ns;
+ prefix foo-prfx;
+ yang-version 1.1;
+
+ revision 2016-12-20;
+
+ leaf leafref-a {
+ type leafref {
+ path "../leaf-a";
+ require-instance true;
+ }
+ }
+
+ leaf leaf-a {
+ type string;
+ }
+
+ leaf leafref-b {
+ type leafref-typedef;
+ }
+
+ leaf leaf-b {
+ type string;
+ }
+
+ typedef leafref-typedef {
+ type leafref {
+ path "../leaf-b";
+ require-instance true;
+ }
+ }
+
+ leaf leafref-c {
+ type leafref {
+ path "../leaf-c";
+ }
+ }
+
+ leaf leaf-c {
+ type string;
+ }
+}
\ No newline at end of file
--- /dev/null
+module foo10 {
+ namespace foo10-ns;
+ prefix foo10-prfx;
+ yang-version 1;
+
+ revision 2016-12-20;
+
+ leaf leafref-a {
+ type leafref {
+ path "../leaf-a";
+ require-instance false;
+ }
+ }
+
+ leaf leaf-a {
+ type string;
+ }
+}
\ No newline at end of file