Class AutoProducesResponseTypeConvention
Namespace: Momentum.ServiceDefaults.Api.OpenApi
Assembly: Momentum.ServiceDefaults.Api.dll
Convention that automatically adds response type metadata to actions returning ActionResult<T>.
public class AutoProducesResponseTypeConvention : IActionModelConvention
Inheritance
object ← AutoProducesResponseTypeConvention
Implements
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
This convention ensures that OpenAPI documentation includes proper response types for actions that don't explicitly declare them via attributes. It uses a special placeholder status code that is later replaced by the XML documentation transformer with the actual documented status code.
Constructors
AutoProducesResponseTypeConvention()
public AutoProducesResponseTypeConvention()
Methods
Apply(ActionModel)
Applies the convention to an action model.
public void Apply(ActionModel action)
Parameters
action
ActionModel
The action model to apply the convention to.
Remarks
This method:
- Checks if the action already has a success response type declared
- Extracts the response type from ActionResult<T> return types
- Adds a ProducesResponseTypeAttribute with a placeholder status code
- Handles async return types (Task<T> and ValueTask<T>)