C
C#3d ago
khamas

nswag openapi add a global return type for a specific response code

Hey, I have an API that has routes which are defined like below; but I return some 401s and others via middleware, is there a way to say that all routes could return a specific response type using openAPI?
[HttpPost("UpdatePersonalInformation")]
[ProducesResponseType(typeof(UpdatePersonalInformationResponse), 200)]
[ProducesResponseType(typeof(AppError), 400)]
public async Task<IActionResult> UpdatePersonalInformation(
[FromBody] UpdatePersonalInformationRequest request)
[HttpPost("UpdatePersonalInformation")]
[ProducesResponseType(typeof(UpdatePersonalInformationResponse), 200)]
[ProducesResponseType(typeof(AppError), 400)]
public async Task<IActionResult> UpdatePersonalInformation(
[FromBody] UpdatePersonalInformationRequest request)
4 Replies
Anton
Anton3d ago
You make a filter It can look at the middlewares A schema filter
khamas
khamasOP3d ago
I made a filter, but how does it register in the openapi document?
Anton
Anton3d ago
look for docs I don't remember you probably just add it to their options in the di
khamas
khamasOP2d ago
I guess yeah

Did you find this page helpful?