public void Apply(Schema model, ModelFilterContext context) { var commentId = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType); var typeNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, commentId)); if (typeNode != null) { var summaryNode = typeNode.SelectSingleNode(SummaryTag); if (summaryNode != null) { model.Description = summaryNode.ExtractContent(); } } foreach (var entry in model.Properties) { var jsonProperty = context.JsonObjectContract.Properties[entry.Key]; if (jsonProperty == null) { continue; } ApplyPropertyComments(entry.Value, jsonProperty.PropertyInfo()); } }
public void Apply(Operation operation, OperationFilterContext context) { var controllerActionDescriptor = context.ApiDescription.ActionDescriptor as ControllerActionDescriptor; if (controllerActionDescriptor == null) { return; } var commentId = XmlCommentsIdHelper.GetCommentIdForMethod(controllerActionDescriptor.MethodInfo); var methodNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, commentId)); if (methodNode == null) { return; } var summaryNode = methodNode.SelectSingleNode(SummaryTag); if (summaryNode != null) { operation.Summary = summaryNode.ExtractContent(); } var remarksNode = methodNode.SelectSingleNode(RemarksTag); if (remarksNode != null) { operation.Description = remarksNode.ExtractContent(); } ApplyParamComments(operation, methodNode); }
public void GetCommentIdForType_ReturnsCorrectXmlCommentId_ForGivenType( Type type, string expectedCommentId ) { var commentId = XmlCommentsIdHelper.GetCommentIdForType(type); Assert.Equal(expectedCommentId, commentId); }
public void GetCommentIdForMethod_ReturnsCorrectXmlCommentId_ForGivenMethodInfo( string actionFixtureName, string expectedCommentId ) { var methodInfo = typeof(FakeActions).GetMethod(actionFixtureName); var commentId = XmlCommentsIdHelper.GetCommentIdForMethod(methodInfo); Assert.Equal(expectedCommentId, commentId); }
public void GetCommentIdForProperty_ReturnsCorrectXmlCommentId_ForGivenPropertyInfo( Type type, string propertyName, string expectedCommentId ) { var propertyInfo = type.GetProperty(propertyName); var commentId = XmlCommentsIdHelper.GetCommentIdForProperty(propertyInfo); Assert.Equal(expectedCommentId, commentId); }
private void ApplyPropertyComments(Schema propertySchema, PropertyInfo propertyInfo) { var commentId = XmlCommentsIdHelper.GetCommentIdForProperty(propertyInfo); var propertyNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, commentId)); if (propertyNode == null) { return; } var summaryNode = propertyNode.SelectSingleNode(SummaryTag); if (summaryNode != null) { propertySchema.Description = summaryNode.ExtractContent(); } }
public void Apply(Schema schema, SchemaFilterContext context) { var jsonObjectContract = context.JsonContract as JsonObjectContract; if (jsonObjectContract == null) { return; } var commentId = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType); var typeNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, commentId)); if (typeNode != null) { var summaryNode = typeNode.SelectSingleNode(SummaryTag); if (summaryNode != null) { schema.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml); } } if (schema.Properties == null) { return; } foreach (var entry in schema.Properties) { var jsonProperty = jsonObjectContract.Properties[entry.Key]; if (jsonProperty == null) { continue; } var propertyInfo = jsonProperty.PropertyInfo(); if (propertyInfo != null) { ApplyPropertyComments(entry.Value, propertyInfo); } } }