Skip to content

Class AutoProducesResponseTypeConvention

Namespace: Momentum.ServiceDefaults.Api.OpenApi
Assembly: Momentum.ServiceDefaults.Api.dll

Convention that automatically adds response type metadata to actions returning ActionResult<T>.

csharp
public class AutoProducesResponseTypeConvention : IActionModelConvention

Inheritance

objectAutoProducesResponseTypeConvention

Implements

IActionModelConvention

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()

csharp
public AutoProducesResponseTypeConvention()

Methods

Apply(ActionModel)

Applies the convention to an action model.

csharp
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>)