Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add FakeControllerWithInheritance + add a 'response' test
  • Loading branch information
John-Paul-R committed Dec 3, 2025
commit 6a8d28dff3f93e3cb9fc8773d6d3d042ab8f2c71
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,6 @@ public void ActionWithAuthorizationFromHeaderParameter([FromHeader] string autho
public void ActionWithObjectParameter(XmlAnnotatedType param)
{ }

public void ActionWithDerivedObjectParameter(AbcTests_C param)
{ }

// Helper test types for GenerateSchema_PreservesIntermediateBaseProperties_WhenUsingOneOfPolymorphism
public abstract class AbcTests_A
{
public string PropA { get; set; }
}

public class AbcTests_B : AbcTests_A
{
public string PropB { get; set; }
}

public class AbcTests_C : AbcTests_B
{
public string PropC { get; set; }
}

public class TypeWithRequiredProperty
{
public required string RequiredProperty { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Mvc;

namespace Swashbuckle.AspNetCore.SwaggerGen.Test;

public class FakeControllerWithInheritance
{
public void ActionWithDerivedObjectParameter([FromBody] AbcTests_C param)
{ }

public List<AbcTests_A> ActionWithDerivedObjectResponse()
{
return null!;
}

// Helper test types for GenerateSchema_PreservesIntermediateBaseProperties_WhenUsingOneOfPolymorphism
public abstract class AbcTests_A
{
public string PropA { get; set; }
}

public class AbcTests_B : AbcTests_A
{
public string PropB { get; set; }
}

public class AbcTests_C : AbcTests_B
{
public string PropC { get; set; }
}
}
28 changes: 23 additions & 5 deletions test/Swashbuckle.AspNetCore.SwaggerGen.Test/VerifyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ public async Task GenerateSchema_PreservesIntermediateBaseProperties_WhenUsingOn
var subject = Subject(
apiDescriptions:
[
ApiDescriptionFactory.Create<FakeController>(
ApiDescriptionFactory.Create<FakeControllerWithInheritance>(
c => nameof(c.ActionWithDerivedObjectParameter),
groupName: "v1",
httpMethod: "POST",
Expand All @@ -1129,8 +1129,26 @@ public async Task GenerateSchema_PreservesIntermediateBaseProperties_WhenUsingOn
{
Name = "param1",
Source = BindingSource.Body,
Type = typeof(FakeController.AbcTests_C), // most derived type
ModelMetadata = ModelMetadataFactory.CreateForType(typeof(FakeController.AbcTests_C)),
Type = typeof(FakeControllerWithInheritance.AbcTests_C), // most derived type
ModelMetadata = ModelMetadataFactory.CreateForType(typeof(FakeControllerWithInheritance.AbcTests_C)),
},
],
supportedRequestFormats:
[
new ApiRequestFormat { MediaType = "application/json" },
]),
ApiDescriptionFactory.Create<FakeControllerWithInheritance>(
c => nameof(c.ActionWithDerivedObjectResponse),
groupName: "v1",
httpMethod: "GET",
relativePath: "resource",
parameterDescriptions: [],
supportedResponseTypes: [
new ApiResponseType
{
ApiResponseFormats = [new ApiResponseFormat { MediaType = "application/json" }],
StatusCode = 200,
Type = typeof(FakeControllerWithInheritance.AbcTests_A),
},
]),
],
Expand All @@ -1139,8 +1157,8 @@ public async Task GenerateSchema_PreservesIntermediateBaseProperties_WhenUsingOn
c.UseOneOfForPolymorphism = true;
c.SubTypesSelector =
(type) => (Type[])(
type == typeof(FakeController.AbcTests_A)
? [typeof(FakeController.AbcTests_C)]
type == typeof(FakeControllerWithInheritance.AbcTests_A)
? [typeof(FakeControllerWithInheritance.AbcTests_C)]
: []
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,46 @@
"/resource": {
"post": {
"tags": [
"Fake"
"FakeWithInheritance"
],
"requestBody": {
"content": { }
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AbcTests_C"
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
},
"get": {
"tags": [
"FakeWithInheritance"
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/AbcTests_C"
}
]
}
}
}
}
}
}
}
}
},
Expand Down Expand Up @@ -56,7 +86,7 @@
},
"tags": [
{
"name": "Fake"
"name": "FakeWithInheritance"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,46 @@
"/resource": {
"post": {
"tags": [
"Fake"
"FakeWithInheritance"
],
"requestBody": {
"content": { }
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AbcTests_C"
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
},
"get": {
"tags": [
"FakeWithInheritance"
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/AbcTests_C"
}
]
}
}
}
}
}
}
}
}
},
Expand Down Expand Up @@ -56,7 +86,7 @@
},
"tags": [
{
"name": "Fake"
"name": "FakeWithInheritance"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,46 @@
"/resource": {
"post": {
"tags": [
"Fake"
"FakeWithInheritance"
],
"requestBody": {
"content": { }
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AbcTests_C"
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
},
"get": {
"tags": [
"FakeWithInheritance"
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/AbcTests_C"
}
]
}
}
}
}
}
}
}
}
},
Expand Down Expand Up @@ -56,7 +86,7 @@
},
"tags": [
{
"name": "Fake"
"name": "FakeWithInheritance"
}
]
}