private void TryApplyMemberComments(OpenApiSchema schema, MemberInfo memberInfo) { var memberNodeName = OpenApiXmlCommentsHelper.GetNodeNameForMember(memberInfo); var memberNode = _xmlNavigator.SelectSingleNode(string.Format(NodeXPath, memberNodeName)); if (memberNode == null) { return; } var summaryNode = memberNode.SelectSingleNode(SummaryTag); if (summaryNode != null) { schema.Description = OpenApiXmlCommentsHelper.Humanize(summaryNode.InnerXml); } var exampleNode = memberNode.SelectSingleNode(ExampleXPath); if (exampleNode != null) { var exampleString = OpenApiXmlCommentsHelper.Humanize(exampleNode.InnerXml); var memberType = (memberInfo.MemberType & MemberTypes.Field) != 0 ? ((FieldInfo)memberInfo).FieldType : ((PropertyInfo)memberInfo).PropertyType; schema.Example = ConvertToOpenApiType(memberType, schema, exampleString); } }
private void TryApplyTypeComments(OpenApiSchema schema, Type type) { var typeNodeName = OpenApiXmlCommentsHelper.GetMemberNameForType(type); var typeNode = _xmlNavigator.SelectSingleNode(string.Format(NodeXPath, typeNodeName)); if (typeNode != null) { var summaryNode = typeNode.SelectSingleNode(SummaryTag); if (summaryNode != null) { schema.Description = OpenApiXmlCommentsHelper.Humanize(summaryNode.InnerXml); } } }
private static IOpenApiAny ConvertToOpenApiType(Type memberType, OpenApiSchema schema, string stringValue) { object typedValue; try { typedValue = TypeDescriptor.GetConverter(memberType).ConvertFrom(stringValue); } catch (Exception) { return(null); } return(OpenApiXmlCommentsHelper.TryCreateFor(schema, typedValue, out IOpenApiAny openApiAny) ? openApiAny : null); }