Skip to content

Fixed issue with type of value from <example> when using IncludeXmlCommentsFromInheritDocs#35

Open
patadata wants to merge 12 commits intounchase:masterfrom
patadata:master
Open

Fixed issue with type of value from <example> when using IncludeXmlCommentsFromInheritDocs#35
patadata wants to merge 12 commits intounchase:masterfrom
patadata:master

Conversation

@patadata
Copy link
Copy Markdown

Se description of problem here Issue 34

@unchase
Copy link
Copy Markdown
Owner

unchase commented Dec 17, 2024

Hi @patadata
Could you resolve conflicts?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses an issue with the type of value returned from <example> tags when using IncludeXmlCommentsFromInheritDocs. The main fix introduces proper type handling for XML example values by parsing them according to their underlying property type instead of treating all examples as strings.

Key Changes

  • Added type-aware parsing for XML <example> tags that converts values to appropriate OpenAPI types (integers, floats, arrays, objects) using OpenApiAnyFactory.CreateFromJson
  • Extended test models with additional properties demonstrating various primitive types and collections with example values
  • Updated Swashbuckle.AspNetCore.SwaggerGen dependency from 6.4.0 to 6.5.0
  • Added new WebApi8-Swashbuckle test project

Reviewed changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Unchase.Swashbuckle.AspNetCore.Extensions/Extensions/XmlCommentsExtensions.cs Core fix: Added GetExampleValue, GetExampleValueAsIOpenApiAny, and GetUnderlyingType methods to properly parse example values based on property types
test/Unchase.Swashbuckle.AspNetCore.Extensions.Tests/Models/IInheritDocClass.cs Added 8 new properties with example tags demonstrating various types (int, float, byte, short, long, string[], collection)
test/Unchase.Swashbuckle.AspNetCore.Extensions.Tests/Models/InheritDocClass.cs Implemented the 8 new properties from the interface using <inheritdoc/>
test/Unchase.Swashbuckle.AspNetCore.Extensions.Tests/Models/FreeText.cs New model class to support complex object examples
test/WebApi8-Swashbuckle/* New test project for .NET 8.0 demonstrating the fix
src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj Updated package metadata and dependencies
Multiple files Code formatting improvements (using statements reordering, whitespace cleanup, comment typo fixes)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

default:
throw new ArgumentException
(
"Input MemberInfo must be if type EventInfo, FieldInfo, MethodInfo, or PropertyInfo"
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the error message: "if type" should be "of type".

Suggested change
"Input MemberInfo must be if type EventInfo, FieldInfo, MethodInfo, or PropertyInfo"
"Input MemberInfo must be of type EventInfo, FieldInfo, MethodInfo, or PropertyInfo"

Copilot uses AI. Check for mistakes.
Comment on lines +236 to +242
if (!propType.Name.ToLower().Contains("nullable"))
{
return propType;
}

return propType.GenericTypeArguments?.Length > 0 ? propType.GenericTypeArguments[0] : propType;

Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nullable type detection using propType.Name.ToLower().Contains("nullable") is fragile and could produce false positives. For example, a class named MyNullableValue would match this condition. Consider using Nullable.GetUnderlyingType(propType) instead, which returns the underlying type if it's nullable, or null otherwise.

Suggested change
if (!propType.Name.ToLower().Contains("nullable"))
{
return propType;
}
return propType.GenericTypeArguments?.Length > 0 ? propType.GenericTypeArguments[0] : propType;
var underlyingType = Nullable.GetUnderlyingType(propType);
if (underlyingType != null)
{
return underlyingType;
}
return propType;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants