public void InitializInsertRestrictionsTypeWithRecordSuccess() { // Assert IEdmRecordExpression primitiveExampleValue = new EdmRecordExpression( new EdmPropertyConstructor("Description", new EdmStringConstant("example desc")), new EdmPropertyConstructor("Value", new EdmStringConstant("example value"))); IEdmRecordExpression record = new EdmRecordExpression( new EdmPropertyConstructor("Insertable", new EdmBooleanConstant(false)), new EdmPropertyConstructor("NonInsertableProperties", new EdmCollectionExpression(new EdmPathExpression("abc/xyz"))), new EdmPropertyConstructor("NonInsertableNavigationProperties", new EdmCollectionExpression(new EdmNavigationPropertyPathExpression("abc"), new EdmNavigationPropertyPathExpression("RelatedEvents"))), new EdmPropertyConstructor("MaxLevels", new EdmIntegerConstant(8)), new EdmPropertyConstructor("CustomQueryOptions", new EdmCollectionExpression( new EdmRecordExpression( new EdmPropertyConstructor("Name", new EdmStringConstant("primitive name")), new EdmPropertyConstructor("Description", new EdmStringConstant("primitive desc")), new EdmPropertyConstructor("DocumentationURL", new EdmStringConstant("http://any3")), new EdmPropertyConstructor("Required", new EdmBooleanConstant(true)), new EdmPropertyConstructor("ExampleValues", new EdmCollectionExpression(primitiveExampleValue))))) // QueryOptions // Permission // CustomHeaders ); // Act InsertRestrictionsType insert = new InsertRestrictionsType(); insert.Initialize(record); // Assert VerifyInsertRestrictions(insert); }
private static void VerifyInsertRestrictions(InsertRestrictionsType insert) { Assert.NotNull(insert); Assert.NotNull(insert.Insertable); Assert.False(insert.Insertable.Value); Assert.NotNull(insert.NonInsertableNavigationProperties); Assert.Equal(2, insert.NonInsertableNavigationProperties.Count); Assert.Equal("abc|RelatedEvents", String.Join("|", insert.NonInsertableNavigationProperties)); Assert.True(insert.IsNonInsertableNavigationProperty("RelatedEvents")); Assert.False(insert.IsNonInsertableNavigationProperty("MyUnknownNavigationProperty")); Assert.Null(insert.QueryOptions); Assert.Null(insert.Permissions); Assert.Null(insert.CustomHeaders); Assert.NotNull(insert.MaxLevels); Assert.Equal(8, insert.MaxLevels.Value); Assert.NotNull(insert.CustomQueryOptions); CustomParameter parameter = Assert.Single(insert.CustomQueryOptions); Assert.Equal("primitive name", parameter.Name); Assert.Equal("http://any3", parameter.DocumentationURL); Assert.NotNull(parameter.ExampleValues); PrimitiveExampleValue example = Assert.Single(parameter.ExampleValues); Assert.Equal("example desc", example.Description); Assert.Equal("example value", example.Value.Value); }
private void AddInsertOperation(OpenApiPathItem item, NavigationPropertyRestriction restriction) { InsertRestrictionsType insert = restriction?.InsertRestrictions; if (insert == null || insert.IsInsertable) { AddOperation(item, OperationType.Post); } }
/// <inheritdoc/> protected override void SetOperations(OpenApiPathItem item) { IEdmEntitySet entitySet = NavigationSource as IEdmEntitySet; IEdmVocabularyAnnotatable target = entitySet; if (target == null) { target = NavigationSource as IEdmSingleton; } NavigationRestrictionsType navSourceRestrictionType = Context.Model.GetRecord <NavigationRestrictionsType>(target, CapabilitiesConstants.NavigationRestrictions); NavigationRestrictionsType navPropRestrictionType = Context.Model.GetRecord <NavigationRestrictionsType>(NavigationProperty, CapabilitiesConstants.NavigationRestrictions); NavigationPropertyRestriction restriction = navSourceRestrictionType?.RestrictedProperties? .FirstOrDefault(r => r.NavigationProperty == Path.NavigationPropertyPath()) ?? navPropRestrictionType?.RestrictedProperties?.FirstOrDefault(); // Check whether the navigation property should be part of the path if (EdmModelHelper.NavigationRestrictionsAllowsNavigability(navSourceRestrictionType, restriction) == false || EdmModelHelper.NavigationRestrictionsAllowsNavigability(navPropRestrictionType, restriction) == false) { return; } // containment: Get / (Post - Collection | Patch - Single) // non-containment: Get AddGetOperation(item, restriction); if (NavigationProperty.ContainsTarget) { if (NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many) { if (LastSegmentIsKeySegment) { UpdateRestrictionsType updateEntity = Context.Model.GetRecord <UpdateRestrictionsType>(_entityType); if (updateEntity?.IsUpdatable ?? true) { AddUpdateOperation(item, restriction); } } else { InsertRestrictionsType insert = restriction?.InsertRestrictions; if (insert?.IsInsertable ?? true) { AddOperation(item, OperationType.Post); } } } else { AddUpdateOperation(item, restriction); } } AddDeleteOperation(item, restriction); }
protected override void SetSecurity(OpenApiOperation operation) { InsertRestrictionsType insert = Context.Model.GetRecord <InsertRestrictionsType>(EntitySet, CapabilitiesConstants.InsertRestrictions); if (insert == null || insert.Permissions == null) { return; } operation.Security = Context.CreateSecurityRequirements(insert.Permissions).ToList(); }
/// <inheritdoc/> protected override void SetOperations(OpenApiPathItem item) { ReadRestrictionsType read = Context.Model.GetRecord <ReadRestrictionsType>(EntitySet); if (read == null || read.IsReadable) { AddOperation(item, OperationType.Get); } InsertRestrictionsType insert = Context.Model.GetRecord <InsertRestrictionsType>(EntitySet); if (insert == null || insert.IsInsertable) { AddOperation(item, OperationType.Post); } }
protected override void AppendCustomParameters(OpenApiOperation operation) { InsertRestrictionsType insert = Context.Model.GetRecord <InsertRestrictionsType>(EntitySet, CapabilitiesConstants.InsertRestrictions); if (insert == null) { return; } if (insert.CustomQueryOptions != null) { AppendCustomParameters(operation, insert.CustomQueryOptions, ParameterLocation.Query); } if (insert.CustomHeaders != null) { AppendCustomParameters(operation, insert.CustomHeaders, ParameterLocation.Header); } }
public void TargetOnEntitySetReturnsCorrectInsertRestrictionsValue(EdmVocabularyAnnotationSerializationLocation location) { // Arrange const string template = @" <Annotations Target=""NS.Default/Calendars""> {0} </Annotations>"; IEdmModel model = GetEdmModel(template, location); Assert.NotNull(model); // guard IEdmEntitySet calendars = model.EntityContainer.FindEntitySet("Calendars"); Assert.NotNull(calendars); // guard // Act InsertRestrictionsType insert = model.GetRecord <InsertRestrictionsType>(calendars); // Assert VerifyInsertRestrictions(insert); }
/// <inheritdoc/> protected override void SetOperations(OpenApiPathItem item) { IEdmEntitySet entitySet = NavigationSource as IEdmEntitySet; IEdmVocabularyAnnotatable target = entitySet; if (target == null) { target = NavigationSource as IEdmSingleton; } string navigationPropertyPath = String.Join("/", Path.Segments.Where(s => !(s is ODataKeySegment || s is ODataNavigationSourceSegment)).Select(e => e.Identifier)); NavigationRestrictionsType navigation = Context.Model.GetRecord <NavigationRestrictionsType>(target, CapabilitiesConstants.NavigationRestrictions); NavigationPropertyRestriction restriction = navigation?.RestrictedProperties?.FirstOrDefault(r => r.NavigationProperty == navigationPropertyPath); // verify using individual first if (restriction != null && restriction.Navigability != null && restriction.Navigability.Value == NavigationType.None) { return; } if (restriction == null || restriction.Navigability == null) { // if the individual has not navigability setting, use the global navigability setting if (navigation != null && navigation.Navigability != null && navigation.Navigability.Value == NavigationType.None) { // Default navigability for all navigation properties of the annotation target. // Individual navigation properties can override this value via `RestrictedProperties/Navigability`. return; } } // how about delete? // contaiment: Get / (Post - Collection | Patch - Single) // non-containment: only Get AddGetOperation(item, restriction); if (NavigationProperty.ContainsTarget) { if (NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many) { if (LastSegmentIsKeySegment) { // Need to check this scenario is valid or not? UpdateRestrictionsType update = restriction?.UpdateRestrictions; if (update == null || update.IsUpdatable) { AddOperation(item, OperationType.Patch); } } else { InsertRestrictionsType insert = restriction?.InsertRestrictions; if (insert == null || insert.IsInsertable) { AddOperation(item, OperationType.Post); } } } else { UpdateRestrictionsType update = restriction?.UpdateRestrictions; if (update == null || update.IsUpdatable) { AddOperation(item, OperationType.Patch); } } } }
/// <inheritdoc/> protected override void SetOperations(OpenApiPathItem item) { IEdmEntitySet entitySet = NavigationSource as IEdmEntitySet; IEdmVocabularyAnnotatable target = entitySet; if (target == null) { target = NavigationSource as IEdmSingleton; } string navigationPropertyPath = String.Join("/", Path.Segments.Where(s => !(s is ODataKeySegment || s is ODataNavigationSourceSegment)).Select(e => e.Identifier)); NavigationRestrictionsType navigation = Context.Model.GetRecord <NavigationRestrictionsType>(target, CapabilitiesConstants.NavigationRestrictions); NavigationPropertyRestriction restriction = navigation?.RestrictedProperties?.FirstOrDefault(r => r.NavigationProperty == navigationPropertyPath); // verify using individual first if (restriction != null && restriction.Navigability != null && restriction.Navigability.Value == NavigationType.None) { return; } if (restriction == null || restriction.Navigability == null) { // if the individual has not navigability setting, use the global navigability setting if (navigation != null && navigation.Navigability != null && navigation.Navigability.Value == NavigationType.None) { // Default navigability for all navigation properties of the annotation target. // Individual navigation properties can override this value via `RestrictedProperties/Navigability`. return; } } // So far, we only consider the non-containment Debug.Assert(!NavigationProperty.ContainsTarget); // It seems OData supports to "GetRef, DeleteRef", // Here at this time,let's only consider the "delete" ReadRestrictionsType read = restriction?.ReadRestrictions; if (read == null || read.IsReadable) { AddOperation(item, OperationType.Get); } // Create the ref if (NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many) { InsertRestrictionsType insert = restriction?.InsertRestrictions; if (insert == null || insert.IsInsertable) { AddOperation(item, OperationType.Post); } } else { UpdateRestrictionsType update = restriction?.UpdateRestrictions; if (update == null || update.IsUpdatable) { AddOperation(item, OperationType.Put); } // delete the link DeleteRestrictionsType delete = restriction?.DeleteRestrictions; if (delete == null || delete.IsDeletable) { AddOperation(item, OperationType.Delete); } } }
protected override void Initialize(ODataContext context, ODataPath path) { base.Initialize(context, path); _insertRestrictions = Context.Model.GetRecord <InsertRestrictionsType>(EntitySet, CapabilitiesConstants.InsertRestrictions); }