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

Commit

Permalink
Revive call to FormattingUtilities in XmlDataContractSerializerOutput…
Browse files Browse the repository at this point in the history
…Formatter

Fixes #6235
  • Loading branch information
pranavkm committed Jul 7, 2017
1 parent 05f5d59 commit fc106ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ protected virtual DataContractSerializer CreateSerializer(Type type)

try
{
// Use FormattingUtilities here when https://github.com/aspnet/Mvc/issues/6235 is resolved.
// Verify that type is a valid data contract by forcing the serializer to try to create a data contract
FormattingUtilities.XsdDataContractExporter.GetRootElementName(type);

// If the serializer does not support this type it will throw an exception.
return new DataContractSerializer(type, _serializerSettings);
}
Expand Down
13 changes: 6 additions & 7 deletions test/Microsoft.AspNetCore.Mvc.FunctionalTests/ApiExplorerTest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Testing.xunit;
using Newtonsoft.Json;
using Xunit;
using Microsoft.AspNetCore.Http;
using System.Net;

namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{
Expand Down Expand Up @@ -571,7 +570,7 @@ public async Task ExplicitResponseTypeDecoration_SuppressesDefaultStatus()
{
// Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName;
var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "application/json", "text/json", "application/xml", "text/xml" };

// Act
Expand Down Expand Up @@ -603,7 +602,7 @@ public async Task ExplicitResponseTypeDecoration_SuppressesDefaultStatus_AlsoHon
{
// Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName;
var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "text/xml" };

// Act
Expand Down Expand Up @@ -635,7 +634,7 @@ public async Task ExplicitResponseTypeDecoration_WithExplicitDefaultStatus()
{
// Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName;
var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "application/json", "text/json", "application/xml", "text/xml" };

// Act
Expand Down Expand Up @@ -667,7 +666,7 @@ public async Task ExplicitResponseTypeDecoration_WithExplicitDefaultStatus_Speci
{
// Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName;
var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "text/xml" };

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace ApiExplorerWebSite
{
Expand Down Expand Up @@ -58,29 +57,29 @@ public Product GetProduct()
}

[ProducesResponseType(typeof(Product), 201)]
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
[ProducesResponseType(typeof(SerializableError), 400)]
public Product CreateProductWithDefaultResponseContentTypes(Product product)
{
return null;
}

[Produces("text/xml")] // Has status code as 200 but is not applied as it does not set 'Type'
[ProducesResponseType(typeof(Product), 201)]
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
[ProducesResponseType(typeof(SerializableError), 400)]
public Product CreateProductWithLimitedResponseContentTypes(Product product)
{
return null;
}

[ProducesResponseType(typeof(Product), 200)]
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
[ProducesResponseType(typeof(SerializableError), 400)]
public Product UpdateProductWithDefaultResponseContentTypes(Product product)
{
return null;
}

[Produces("text/xml", Type = typeof(Product))] // Has status code as 200
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
[ProducesResponseType(typeof(SerializableError), 400)]
public Product UpdateProductWithLimitedResponseContentTypes(Product product)
{
return null;
Expand Down

0 comments on commit fc106ab

Please sign in to comment.