Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit fc106ab

Browse files
committed
Revive call to FormattingUtilities in XmlDataContractSerializerOutputFormatter
Fixes #6235
1 parent 05f5d59 commit fc106ab

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerOutputFormatter.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ protected virtual DataContractSerializer CreateSerializer(Type type)
132132

133133
try
134134
{
135-
// Use FormattingUtilities here when https://github.com/aspnet/Mvc/issues/6235 is resolved.
135+
// Verify that type is a valid data contract by forcing the serializer to try to create a data contract
136+
FormattingUtilities.XsdDataContractExporter.GetRootElementName(type);
137+
136138
// If the serializer does not support this type it will throw an exception.
137139
return new DataContractSerializer(type, _serializerSettings);
138140
}

test/Microsoft.AspNetCore.Mvc.FunctionalTests/ApiExplorerTest.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System.Linq;
54
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Net;
67
using System.Net.Http;
78
using System.Threading.Tasks;
89
using Microsoft.AspNetCore.Mvc.Formatters;
910
using Microsoft.AspNetCore.Mvc.ModelBinding;
1011
using Microsoft.AspNetCore.Testing.xunit;
1112
using Newtonsoft.Json;
1213
using Xunit;
13-
using Microsoft.AspNetCore.Http;
14-
using System.Net;
1514

1615
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
1716
{
@@ -571,7 +570,7 @@ public async Task ExplicitResponseTypeDecoration_SuppressesDefaultStatus()
571570
{
572571
// Arrange
573572
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
574-
var type2 = typeof(ModelStateDictionary).FullName;
573+
var type2 = typeof(SerializableError).FullName;
575574
var expectedMediaTypes = new[] { "application/json", "text/json", "application/xml", "text/xml" };
576575

577576
// Act
@@ -603,7 +602,7 @@ public async Task ExplicitResponseTypeDecoration_SuppressesDefaultStatus_AlsoHon
603602
{
604603
// Arrange
605604
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
606-
var type2 = typeof(ModelStateDictionary).FullName;
605+
var type2 = typeof(SerializableError).FullName;
607606
var expectedMediaTypes = new[] { "text/xml" };
608607

609608
// Act
@@ -635,7 +634,7 @@ public async Task ExplicitResponseTypeDecoration_WithExplicitDefaultStatus()
635634
{
636635
// Arrange
637636
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
638-
var type2 = typeof(ModelStateDictionary).FullName;
637+
var type2 = typeof(SerializableError).FullName;
639638
var expectedMediaTypes = new[] { "application/json", "text/json", "application/xml", "text/xml" };
640639

641640
// Act
@@ -667,7 +666,7 @@ public async Task ExplicitResponseTypeDecoration_WithExplicitDefaultStatus_Speci
667666
{
668667
// Arrange
669668
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
670-
var type2 = typeof(ModelStateDictionary).FullName;
669+
var type2 = typeof(SerializableError).FullName;
671670
var expectedMediaTypes = new[] { "text/xml" };
672671

673672
// Act

test/WebSites/ApiExplorerWebSite/Controllers/ApiExplorerResponseTypeWithAttributeController.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Threading.Tasks;
55
using Microsoft.AspNetCore.Mvc;
6-
using Microsoft.AspNetCore.Mvc.ModelBinding;
76

87
namespace ApiExplorerWebSite
98
{
@@ -58,29 +57,29 @@ public Product GetProduct()
5857
}
5958

6059
[ProducesResponseType(typeof(Product), 201)]
61-
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
60+
[ProducesResponseType(typeof(SerializableError), 400)]
6261
public Product CreateProductWithDefaultResponseContentTypes(Product product)
6362
{
6463
return null;
6564
}
6665

6766
[Produces("text/xml")] // Has status code as 200 but is not applied as it does not set 'Type'
6867
[ProducesResponseType(typeof(Product), 201)]
69-
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
68+
[ProducesResponseType(typeof(SerializableError), 400)]
7069
public Product CreateProductWithLimitedResponseContentTypes(Product product)
7170
{
7271
return null;
7372
}
7473

7574
[ProducesResponseType(typeof(Product), 200)]
76-
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
75+
[ProducesResponseType(typeof(SerializableError), 400)]
7776
public Product UpdateProductWithDefaultResponseContentTypes(Product product)
7877
{
7978
return null;
8079
}
8180

8281
[Produces("text/xml", Type = typeof(Product))] // Has status code as 200
83-
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
82+
[ProducesResponseType(typeof(SerializableError), 400)]
8483
public Product UpdateProductWithLimitedResponseContentTypes(Product product)
8584
{
8685
return null;

0 commit comments

Comments
 (0)