public void InitializeModificationQueryOptionsTypeWorksWithCsdl() { // Arrange string annotation = @"<Annotation Term=""NS.MyOperationRestriction""> <Record> <PropertyValue Property=""CustomHeaders"" > <Collection> <Record> <PropertyValue Property=""Name"" String=""head name"" /> <PropertyValue Property=""Description"" String=""head desc"" /> <PropertyValue Property=""DocumentationURL"" String=""http://any3"" /> <PropertyValue Property=""Required"" Bool=""true"" /> </Record> </Collection> </PropertyValue> </Record> </Annotation>"; IEdmModel model = GetEdmModel(annotation); Assert.NotNull(model); // guard IEdmOperation edmOperation = model.SchemaElements.OfType <IEdmFunction>().First(); Assert.NotNull(edmOperation); // Act OperationRestrictionsType operation = model.GetRecord <OperationRestrictionsType>(edmOperation, "NS.MyOperationRestriction"); // Assert VerifyOperationRestrictions(operation); }
/// <inheritdoc/> protected override void SetSecurity(OpenApiOperation operation) { OperationRestrictionsType restriction = Context.Model.GetRecord <OperationRestrictionsType>(EdmOperationImport, CapabilitiesConstants.OperationRestrictions); if (restriction == null || restriction.Permissions == null) { return; } operation.Security = Context.CreateSecurityRequirements(restriction.Permissions).ToList(); }
private static void VerifyOperationRestrictions(OperationRestrictionsType operation) { Assert.NotNull(operation); Assert.Null(operation.FilterSegmentSupported); Assert.Null(operation.Permissions); Assert.Null(operation.CustomQueryOptions); Assert.NotNull(operation.CustomHeaders); CustomParameter parameter = Assert.Single(operation.CustomHeaders); Assert.Equal("head name", parameter.Name); Assert.Equal("http://any3", parameter.DocumentationURL); Assert.Equal("head desc", parameter.Description); Assert.True(parameter.Required.Value); Assert.Null(parameter.ExampleValues); }
/// <inheritdoc/> protected override void AppendCustomParameters(OpenApiOperation operation) { OperationRestrictionsType restriction = Context.Model.GetRecord <OperationRestrictionsType>(EdmOperationImport, CapabilitiesConstants.OperationRestrictions); if (restriction == null) { return; } if (restriction.CustomHeaders != null) { AppendCustomParameters(operation, restriction.CustomHeaders, ParameterLocation.Header); } if (restriction.CustomQueryOptions != null) { AppendCustomParameters(operation, restriction.CustomQueryOptions, ParameterLocation.Query); } }
public void InitializOperationRestrictionTypeWithRecordSuccess() { // Assert IEdmRecordExpression record = new EdmRecordExpression( new EdmPropertyConstructor("CustomHeaders", new EdmCollectionExpression( new EdmRecordExpression( new EdmPropertyConstructor("Name", new EdmStringConstant("head name")), new EdmPropertyConstructor("Description", new EdmStringConstant("head desc")), new EdmPropertyConstructor("DocumentationURL", new EdmStringConstant("http://any3")), new EdmPropertyConstructor("Required", new EdmBooleanConstant(true))))) // Permissions // CustomQueryOptions ); // Act OperationRestrictionsType operation = new OperationRestrictionsType(); operation.Initialize(record); // Assert VerifyOperationRestrictions(operation); }