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

Commit

Permalink
Addressed more feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kichalla committed Mar 25, 2016
1 parent bdcb504 commit bef2a4f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
7 changes: 5 additions & 2 deletions src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiResponseFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

namespace Microsoft.AspNetCore.Mvc.ApiExplorer
{
/// <summary>
/// Possible format for an <see cref="ApiResponseType"/>.
/// </summary>
public class ApiResponseFormat
{
/// <summary>
/// The formatter used to output this response.
/// Gets or sets the formatter used to output this response.
/// </summary>
public IOutputFormatter Formatter { get; set; }

/// <summary>
/// The media type of the response.
/// Gets or sets the media type of the response.
/// </summary>
public string MediaType { get; set; }
}
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiResponseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Microsoft.AspNetCore.Mvc.ApiExplorer
{
/// <summary>
/// Represents a possible format for the body of a response.
/// Possible type of the response body which is formatted by <see cref="ApiResponseFormats"/>.
/// </summary>
public class ApiResponseType
{
Expand All @@ -18,7 +18,7 @@ public ApiResponseType()
}

/// <summary>
/// Response formats supported by this type
/// Gets or sets the response formats supported by this type.
/// </summary>
public IList<ApiResponseFormat> ApiResponseFormats { get; set; }

Expand All @@ -40,7 +40,7 @@ public ApiResponseType()
public Type Type { get; set; }

/// <summary>
/// HTTP response status code
/// Gets or sets the HTTP response status code.
/// </summary>
public int StatusCode { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer
public interface IApiResponseMetadataProvider
{
/// <summary>
/// Optimistic return type of the action.
/// Gets the optimistic return type of the action.
/// </summary>
Type Type { get; }

/// <summary>
/// HTTP status code of the response.
/// Gets the HTTP status code of the response.
/// </summary>
int StatusCode { get; }

Expand Down
10 changes: 2 additions & 8 deletions src/Microsoft.AspNetCore.Mvc.Core/ProducesAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.AspNetCore.Mvc.Filters;
Expand Down Expand Up @@ -64,13 +64,7 @@ public ProducesAttribute(string contentType, params string[] additionalContentTy

public MediaTypeCollection ContentTypes { get; set; }

public int StatusCode
{
get
{
return (int)HttpStatusCode.OK;
}
}
public int StatusCode => StatusCodes.Status200OK;

public override void OnResultExecuting(ResultExecutingContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ProducesResponseTypeAttribute : Attribute, IApiResponseMetadataProv
/// Initializes an instance of <see cref="ProducesResponseTypeAttribute"/>.
/// </summary>
/// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param>
/// <param name="statusCode">Http response status code</param>
/// <param name="statusCode">HTTP response status code</param>
public ProducesResponseTypeAttribute(Type type, int statusCode)
{
if (type == null)
Expand All @@ -31,12 +31,12 @@ public ProducesResponseTypeAttribute(Type type, int statusCode)
}

/// <summary>
/// The type of the value returned by an action.
/// Gets or sets the type of the value returned by an action.
/// </summary>
public Type Type { get; set; }

/// <summary>
/// HTTP status code of the response.
/// Gets or sets the HTTP status code of the response.
/// </summary>
public int StatusCode { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ public void GetApiDescription_ReturnsActionResultWithProduces_And_ProducesConten
// Arrange
var action = CreateActionDescriptor(methodName, controllerType);
action.FilterDescriptors = filterDescriptors;
var expectedMediaTypes = new[] { "application/json", "text/json" };

// Act
var descriptions = GetApiDescriptions(action);
Expand All @@ -470,31 +471,29 @@ public void GetApiDescription_ReturnsActionResultWithProduces_And_ProducesConten
var description = Assert.Single(descriptions);
Assert.Equal(3, description.SupportedResponseTypes.Count);

var responseType = Assert.Single(description.SupportedResponseTypes.Where(frmt => frmt.Type == typeof(Customer)));
var responseType = Assert.Single(
description.SupportedResponseTypes.Where(respType => respType.Type == typeof(Customer)));
Assert.Equal(200, responseType.StatusCode);
Assert.NotNull(responseType.ModelMetadata);
var responseFormat = Assert.Single(
responseType.ApiResponseFormats.Where(respFormat => respFormat.MediaType == "text/json"));
responseFormat = Assert.Single(
responseType.ApiResponseFormats.Where(respFormat => respFormat.MediaType == "application/json"));
Assert.Equal(
expectedMediaTypes,
responseType.ApiResponseFormats.OrderBy(format => format.MediaType).Select(format => format.MediaType));

responseType = Assert.Single(
description.SupportedResponseTypes.Where(respType => respType.Type == typeof(BadData)));
Assert.Equal(400, responseType.StatusCode);
Assert.NotNull(responseType.ModelMetadata);
responseFormat = Assert.Single(
responseType.ApiResponseFormats.Where(respFormat => respFormat.MediaType == "text/json"));
responseFormat = Assert.Single(
responseType.ApiResponseFormats.Where(respFormat => respFormat.MediaType == "application/json"));
Assert.Equal(
expectedMediaTypes,
responseType.ApiResponseFormats.OrderBy(format => format.MediaType).Select(format => format.MediaType));

responseType = Assert.Single(
description.SupportedResponseTypes.Where(respFormat => respFormat.Type == typeof(ErrorDetails)));
Assert.Equal(500, responseType.StatusCode);
Assert.NotNull(responseType.ModelMetadata);
responseFormat = Assert.Single(
responseType.ApiResponseFormats.Where(respFormat => respFormat.MediaType == "text/json"));
responseFormat = Assert.Single(
responseType.ApiResponseFormats.Where(respFormat => respFormat.MediaType == "application/json"));
Assert.Equal(
expectedMediaTypes,
responseType.ApiResponseFormats.OrderBy(format => format.MediaType).Select(format => format.MediaType));
}

public static TheoryData<Type, string, List<FilterDescriptor>> ReturnsVoidOrTaskWithProducesContentTypeData
Expand Down Expand Up @@ -717,9 +716,9 @@ public void GetApiDescription_IncludesResponseFormats_FilteredByType()
var responseType = Assert.Single(description.SupportedResponseTypes);
Assert.Equal(typeof(Order), responseType.Type);
Assert.NotNull(responseType.ModelMetadata);
var responseFormat = Assert.Single(
responseType.ApiResponseFormats.Where(respFormat => respFormat.MediaType == "text/json"));
Assert.Same(formatters[0], responseFormat.Formatter);
var apiResponseFormat = Assert.Single(
responseType.ApiResponseFormats.Where(responseFormat => responseFormat.MediaType == "text/json"));
Assert.Same(formatters[0], apiResponseFormat.Formatter);
}

[Fact]
Expand Down

0 comments on commit bef2a4f

Please sign in to comment.