private void ApplyPropertyTags(OpenApiParameter parameter, ParameterFilterContext context)
        {
            var propertyMemberName = XmlCommentsNodeNameHelper.GetMemberNameForFieldOrProperty(context.PropertyInfo);
            var propertyNode       = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{propertyMemberName}']");

            if (propertyNode == null)
            {
                return;
            }

            var summaryNode = propertyNode.SelectSingleNode("summary");

            if (summaryNode != null)
            {
                parameter.Description        = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
                parameter.Schema.Description = null; // no need to duplicate
            }

            var exampleNode = propertyNode.SelectSingleNode("example");

            if (exampleNode == null)
            {
                return;
            }

            var exampleAsJson = (parameter.Schema?.ResolveType(context.SchemaRepository) == "string")
                ? $"\"{exampleNode.ToString()}\""
                : exampleNode.ToString();

            parameter.Example = OpenApiAnyFactory.CreateFromJson(exampleAsJson);
        }
Ejemplo n.º 2
0
        private void ApplyFieldOrPropertyTags(OpenApiSchema schema, MemberInfo fieldOrPropertyInfo)
        {
            var fieldOrPropertyMemberName = XmlCommentsNodeNameHelper.GetMemberNameForFieldOrProperty(fieldOrPropertyInfo);
            var fieldOrPropertyNode       = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{fieldOrPropertyMemberName}']");

            if (fieldOrPropertyNode == null)
            {
                return;
            }

            var summaryNode = fieldOrPropertyNode.SelectSingleNode("summary");

            if (summaryNode != null)
            {
                schema.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
            }

            var exampleNode = fieldOrPropertyNode.SelectSingleNode("example");

            if (exampleNode != null)
            {
                var exampleString = XmlCommentsTextHelper.Humanize(exampleNode.InnerXml);

                if (fieldOrPropertyInfo is FieldInfo fieldInfo)
                {
                    schema.Example = ConvertToOpenApiType(fieldInfo.FieldType, schema, exampleString);
                }
                else if (fieldOrPropertyInfo is PropertyInfo propertyInfo)
                {
                    schema.Example = ConvertToOpenApiType(propertyInfo.PropertyType, schema, exampleString);
                }
            }
        }
Ejemplo n.º 3
0
        private void ApplyPropertyTags(OpenApiRequestBody requestBody, RequestBodyFilterContext context, PropertyInfo propertyInfo)
        {
            var propertyMemberName = XmlCommentsNodeNameHelper.GetMemberNameForFieldOrProperty(propertyInfo);
            var propertyNode       = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{propertyMemberName}']");

            if (propertyNode == null)
            {
                return;
            }

            var summaryNode = propertyNode.SelectSingleNode("summary");

            if (summaryNode != null)
            {
                requestBody.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
            }

            var exampleNode = propertyNode.SelectSingleNode("example");

            if (exampleNode == null)
            {
                return;
            }

            foreach (var mediaType in requestBody.Content.Values)
            {
                var exampleAsJson = (mediaType.Schema?.ResolveType(context.SchemaRepository) == "string")
                    ? $"\"{exampleNode.ToString()}\""
                    : exampleNode.ToString();

                mediaType.Example = OpenApiAnyFactory.CreateFromJson(exampleAsJson);
            }
        }
Ejemplo n.º 4
0
        private void ApplyMemberTags(OpenApiSchema schema, SchemaFilterContext context)
        {
            var fieldOrPropertyMemberName = XmlCommentsNodeNameHelper.GetMemberNameForFieldOrProperty(context.MemberInfo);
            var fieldOrPropertyNode       = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{fieldOrPropertyMemberName}']");

            if (fieldOrPropertyNode == null)
            {
                return;
            }

            var summaryNode = fieldOrPropertyNode.SelectSingleNode("summary");

            if (summaryNode != null)
            {
                schema.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
            }

            var exampleNode = fieldOrPropertyNode.SelectSingleNode("example");

            if (exampleNode != null)
            {
                var exampleAsJson = (schema.ResolveType(context.SchemaRepository) == "string")
                    ? $"\"{exampleNode.InnerXml}\""
                    : exampleNode.InnerXml;

                schema.Example = OpenApiAnyFactory.CreateFromJson(exampleAsJson);
            }
        }
        private void ApplyPropertyTags(OpenApiParameter parameter, PropertyInfo propertyInfo)
        {
            var propertyMemberName = XmlCommentsNodeNameHelper.GetMemberNameForFieldOrProperty(propertyInfo);
            var propertyNode       = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{propertyMemberName}']");

            if (propertyNode == null)
            {
                return;
            }

            var summaryNode = propertyNode.SelectSingleNode("summary");

            if (summaryNode != null)
            {
                parameter.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
            }

            var exampleNode = propertyNode.SelectSingleNode("example");

            if (exampleNode != null)
            {
                var exampleString = XmlCommentsTextHelper.Humanize(exampleNode.InnerXml);
                parameter.Example = ConvertToOpenApiType(propertyInfo.PropertyType, parameter.Schema, exampleString);
            }
        }
        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);
            }
        }
Ejemplo n.º 7
0
        private void ApplyFieldOrPropertyTags(OpenApiSchema schema, MemberInfo fieldOrPropertyInfo)
        {
            var fieldOrPropertyMemberName = XmlCommentsNodeNameHelper.GetMemberNameForFieldOrProperty(fieldOrPropertyInfo);
            var fieldOrPropertyNode       = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{fieldOrPropertyMemberName}']");

            if (fieldOrPropertyNode == null)
            {
                return;
            }

            var summaryNode = fieldOrPropertyNode.SelectSingleNode("summary");

            if (summaryNode != null)
            {
                schema.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
            }

            var exampleNode = fieldOrPropertyNode.SelectSingleNode("example");

            if (exampleNode != null)
            {
                schema.Example = OpenApiAnyFactory.CreateFromJson(exampleNode.InnerXml);
            }
        }