The Wayback Machine - https://web.archive.org/web/20211105082744/https://github.com/dotnet/aspnetcore/issues/38108
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How does ProducesResponseType inference work for ActionResult<T>? #38108

Open
voroninp opened this issue Nov 5, 2021 · 0 comments
Open

Comments

Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
@voroninp
Copy link
Contributor

@voroninp voroninp commented Nov 5, 2021

Docs say:

  • The [ProducesResponseType] attribute's Type property can be excluded. For example, [ProducesResponseType(200, Type = typeof(Product))] is simplified to [ProducesResponseType(200)]. The action's expected return type is instead inferred from the T in ActionResult<T>.

Does produced type inference work exclusively for ActionResult<T> or is there any convention, so I can create my own result type, and OpenApi doc generator will be able to infer the produced type?

I want to write:

Task<ApiResult<T>> Action() {} 

but the actual shape of the output is the following record:

public sealed Result<T>(bool isSuccess, T? result, string[] errors);

and I want swagger to show the correct shape of the result without the need to explicitly write the type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment