This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new attribute ProducesResponseTypeAttribute to enable ApiExplor…
…er to expose response type and StatusCode. [Fixes #4101] StatusCode Metadata
- Loading branch information
Showing
9 changed files
with
263 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/Microsoft.AspNetCore.Mvc.Core/ProducesResponseTypeAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using Microsoft.AspNetCore.Mvc.ApiExplorer; | ||
using Microsoft.AspNetCore.Mvc.Core; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.AspNetCore.Mvc.Formatters; | ||
using Microsoft.AspNetCore.Mvc.Formatters.Internal; | ||
using Microsoft.Net.Http.Headers; | ||
|
||
namespace Microsoft.AspNetCore.Mvc | ||
{ | ||
/// <summary> | ||
/// Specifies the allowed content types and the type of the value returned by the action | ||
/// which can be used to select a formatter while executing <see cref="ObjectResult"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] | ||
public class ProducesResponseTypeAttribute : Attribute, IApiResponseMetadataProvider | ||
{ | ||
/// <summary> | ||
/// Initializes an instance of <see cref="ProducesAttribute"/>. | ||
/// </summary> | ||
/// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param> | ||
/// <param name="statusCode"></param> | ||
public ProducesResponseTypeAttribute(Type type, int statusCode) | ||
{ | ||
if (type == null) | ||
{ | ||
throw new ArgumentNullException(nameof(type)); | ||
} | ||
|
||
Type = type; | ||
StatusCode = statusCode; | ||
} | ||
|
||
public Type Type { get; set; } | ||
|
||
public int StatusCode { get; set; } | ||
|
||
public void SetContentTypes(MediaTypeCollection contentTypes) | ||
{ | ||
// do not do anything here | ||
} | ||
} | ||
} |
Oops, something went wrong.