Set default value for ApiResponse attribute

Hello,

Now we put something like this for every api:
[ApiResponse(HttpStatusCode.BadRequest, CommonText.BadRequest)]
[ApiResponse(HttpStatusCode.InternalServerError, CommonText.InternalServerError)]

Can we set default value for all the api and only override the one that we want to customize?

Also we add this but if I think it is still OK if we lets Name and DataType is default?
[ApiMember(Name = “AppId”, Description = “Application Id”,
ParameterType = “path”, DataType = “string”, IsRequired = true)]
public string AppId { get; set; }

Thank you,

I’m assuming the purpose of this API Metadata documentation is for documenting your API for Open API, in which case you can programmatically modify the returned Open API Schema (which map 1:1 with the C# DTOs) via the Operation Filters, e.g:

Plugins.Add(new OpenApiFeature
{
    OperationFilter = (verb, operation) => {
        var badRequestCode = ((int) HttpStatusCode.BadRequest).ToString();
        if (!operation.Responses.ContainsKey(badRequestCode))
            operation.Responses[badRequestCode] = new OpenApiResponse { 
                Description = "..."  };
    }
});
1 Like