private void ApplyPropertyTags(OpenApiRequestBody requestBody, PropertyInfo propertyInfo) { var propertyMemberName = XmlCommentsNodeNameHelper.GetMemberNameForFieldOrProperty(propertyInfo); var propertySummaryNode = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{propertyMemberName}']/summary"); if (propertySummaryNode != null) { requestBody.Description = XmlCommentsTextHelper.Humanize(propertySummaryNode.InnerXml); } }
private void ApplyTypeTags(OpenApiSchema schema, Type type) { var typeMemberName = XmlCommentsNodeNameHelper.GetMemberNameForType(type); var typeSummaryNode = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{typeMemberName}']/summary"); if (typeSummaryNode != null) { schema.Description = XmlCommentsTextHelper.Humanize(typeSummaryNode.InnerXml); } }
private void ApplyResponseTags(OpenApiOperation operation, XPathNodeIterator responseNodes) { while (responseNodes.MoveNext()) { var code = responseNodes.Current.GetAttribute("code", ""); var response = operation.Responses.ContainsKey(code) ? operation.Responses[code] : operation.Responses[code] = new OpenApiResponse(); response.Description = XmlCommentsTextHelper.Humanize(responseNodes.Current.InnerXml); } }
private void ApplyParamTags(OpenApiParameter parameter, ParameterFilterContext context) { if (!(context.ParameterInfo.Member is MethodInfo methodInfo)) { return; } // If method is from a constructed generic type, look for comments from the generic type method var targetMethod = methodInfo.DeclaringType.IsConstructedGenericType ? methodInfo.GetUnderlyingGenericTypeMethod() : methodInfo; if (targetMethod == null) { return; } var methodMemberName = XmlCommentsNodeNameHelper.GetMemberNameForMethod(targetMethod); var paramNode = _xmlNavigator.SelectSingleNode( $"/doc/members/member[@name='{methodMemberName}']/param[@name='{context.ParameterInfo.Name}']"); if (paramNode != null) { parameter.Description = XmlCommentsTextHelper.Humanize(paramNode.InnerXml); var example = paramNode.GetAttribute("example", ""); if (!string.IsNullOrEmpty(example)) { var exampleAsJson = (parameter.Schema?.ResolveType(context.SchemaRepository) == "string") ? $"\"{example}\"" : example; parameter.Example = OpenApiAnyFactory.CreateFromJson(exampleAsJson); } } }