Fixed issue with type of value from <example> when using IncludeXmlCommentsFromInheritDocs#35
Fixed issue with type of value from <example> when using IncludeXmlCommentsFromInheritDocs#35patadata wants to merge 12 commits intounchase:masterfrom
Conversation
…mmentsFromInheritDocs, unchase#34
…to solve a Github Action issue
<Deterministic>False</Deterministic>
|
Hi @patadata |
There was a problem hiding this comment.
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) usingOpenApiAnyFactory.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" |
There was a problem hiding this comment.
There's a typo in the error message: "if type" should be "of type".
| "Input MemberInfo must be if type EventInfo, FieldInfo, MethodInfo, or PropertyInfo" | |
| "Input MemberInfo must be of type EventInfo, FieldInfo, MethodInfo, or PropertyInfo" |
| if (!propType.Name.ToLower().Contains("nullable")) | ||
| { | ||
| return propType; | ||
| } | ||
|
|
||
| return propType.GenericTypeArguments?.Length > 0 ? propType.GenericTypeArguments[0] : propType; | ||
|
|
There was a problem hiding this comment.
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.
| 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; |
Se description of problem here Issue 34