Skip to content

Commit c22362a

Browse files
committed
Change accessibility checks
1 parent 196bd95 commit c22362a

20 files changed

+294
-431
lines changed

src/OpenApi/gen/Helpers/AssemblyTypeSymbolsVisitor.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.Collections.Immutable;
66
using System.Threading;
7-
using Microsoft.AspNetCore.OpenApi.SourceGenerators.Xml;
87
using Microsoft.CodeAnalysis;
98

109
namespace Microsoft.AspNetCore.OpenApi.SourceGenerators;
@@ -45,7 +44,7 @@ public override void VisitNamedType(INamedTypeSymbol type)
4544
{
4645
_cancellationToken.ThrowIfCancellationRequested();
4746

48-
if (!IsDeclaredInAssembly(type) || !type.IsAccessibleType() || !_exportedTypes.Add(type))
47+
if (!IsDeclaredInAssembly(type) || !_exportedTypes.Add(type))
4948
{
5049
return;
5150
}
@@ -62,7 +61,7 @@ public override void VisitNamedType(INamedTypeSymbol type)
6261
foreach (var property in properties)
6362
{
6463
_cancellationToken.ThrowIfCancellationRequested();
65-
if (IsDeclaredInAssembly(property) && property.IsAccessibleType() && _exportedProperties.Add(property))
64+
if (IsDeclaredInAssembly(property) && _exportedProperties.Add(property))
6665
{
6766
property.Type.Accept(this);
6867
}
@@ -71,7 +70,7 @@ public override void VisitNamedType(INamedTypeSymbol type)
7170
foreach (var method in methods)
7271
{
7372
_cancellationToken.ThrowIfCancellationRequested();
74-
if (IsDeclaredInAssembly(method) && method.IsAccessibleType() && _exportedMethods.Add(method))
73+
if (IsDeclaredInAssembly(method) && _exportedMethods.Add(method))
7574
{
7675
method.Accept(this);
7776
}

src/OpenApi/gen/XmlCommentGenerator.Parser.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ public sealed partial class XmlCommentGenerator
9292
foreach (var (name, value) in input.RawComments)
9393
{
9494
if (DocumentationCommentId.GetFirstSymbolForDeclarationId(name, compilation) is ISymbol symbol &&
95-
symbol.IsAccessibleType() &&
95+
// Only include symbols that are declared in the application assembly or are
96+
// accessible from the application assembly.
97+
(SymbolEqualityComparer.Default.Equals(symbol.ContainingAssembly, input.Compilation.Assembly) || symbol.IsAccessibleType()) &&
9698
// Skip static classes that are just containers for members with annotations
9799
// since they cannot be instantiated.
98100
symbol is not INamedTypeSymbol { TypeKind: TypeKind.Class, IsStatic: true })

src/OpenApi/sample/Controllers/TestController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class RouteParamsContainer
4040
[FromRoute]
4141
[MinLength(5)]
4242
[UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", Justification = "MinLengthAttribute works without reflection on string properties.")]
43-
public string Name { get; set; }
43+
public string? Name { get; set; }
4444
}
4545

4646
public record MvcTodo(string Title, string Description, bool IsCompleted);

src/OpenApi/sample/Sample.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
5-
<!-- Disable to match nullability annotations in test environment. -->
6-
<Nullable>disable</Nullable>
5+
<Nullable>enable</Nullable>
76
<ImplicitUsings>enable</ImplicitUsings>
87
<!-- Required to generated trimmable Map-invocations. -->
98
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
@@ -25,6 +24,11 @@
2524
<Reference Include="Microsoft.AspNetCore.Mvc" />
2625
</ItemGroup>
2726

27+
<ItemGroup>
28+
<Compile Include="../test/Microsoft.AspNetCore.OpenApi.Tests/Shared/SharedTypes.cs" />
29+
<Compile Include="../test/Microsoft.AspNetCore.OpenApi.Tests/Shared/SharedTypes.Polymorphism.cs" />
30+
</ItemGroup>
31+
2832
<!-- Required to generated trimmable Map-invocations. -->
2933
<ItemGroup>
3034
<ProjectReference Include="$(RepoRoot)/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

src/OpenApi/sample/Shared/SharedTypes.DeeplyNestedType.cs

Lines changed: 0 additions & 181 deletions
This file was deleted.

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=controllers.verified.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,10 @@
118118
"type": "object",
119119
"properties": {
120120
"title": {
121-
"type": "string",
122-
"nullable": true
121+
"type": "string"
123122
},
124123
"description": {
125-
"type": "string",
126-
"nullable": true
124+
"type": "string"
127125
},
128126
"isCompleted": {
129127
"type": "boolean"

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=forms.verified.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
"content": {
146146
"multipart/form-data": {
147147
"schema": {
148+
"required": [
149+
"file"
150+
],
148151
"type": "object",
149152
"allOf": [
150153
{
@@ -200,7 +203,6 @@
200203
},
201204
"title": {
202205
"type": "string",
203-
"nullable": true,
204206
"description": "The title of the to-do item."
205207
},
206208
"completed": {

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=responses.verified.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@
123123
"format": "double"
124124
},
125125
"color": {
126-
"type": "string",
127-
"nullable": true
126+
"type": "string"
128127
},
129128
"sides": {
130129
"type": "integer",
@@ -145,8 +144,7 @@
145144
"format": "double"
146145
},
147146
"color": {
148-
"type": "string",
149-
"nullable": true
147+
"type": "string"
150148
},
151149
"sides": {
152150
"type": "integer",
@@ -170,7 +168,6 @@
170168
},
171169
"title": {
172170
"type": "string",
173-
"nullable": true,
174171
"description": "The title of the to-do item."
175172
},
176173
"completed": {
@@ -193,8 +190,7 @@
193190
"format": "double"
194191
},
195192
"color": {
196-
"type": "string",
197-
"nullable": true
193+
"type": "string"
198194
},
199195
"sides": {
200196
"type": "integer",

0 commit comments

Comments
 (0)