Skip to content

Expose the header in Swagger UI when debugging

Registers a Swagger operation filter that adds an OnBehalfOfUser header parameter to every operation, but only when Debugger.IsAttached is true at the moment Swagger options are configured.

Field Value
Operation ID OP-11
Trigger Swagger configuration (startup)
Inputs System.Diagnostics.Debugger.IsAttached
Outputs Operation filter registered (or not)
Primary components SwaggerGenOptionsExtensions.AddDebuggerOnBehalfOfHeader(), OnBehalfOfUserHeaderParameterFilter.Apply
Entry point src/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Extensions/SwaggerGenOptionsExtensions.cs

Steps

  1. At configuration time, check Debugger.IsAttached; if true, register the operation filter. (BR-NTLM-014)
  2. Per operation (when the filter is registered), ensure operation.Parameters exists and append a header parameter named OnBehalfOfUser (not marked required, no schema).

Process flow

flowchart TD
    Start([Swagger configuration]) --> S1{Debugger.IsAttached?}
    S1 -->|No| End([Filter not registered])
    S1 -->|Yes| S2[Register OnBehalfOfUserHeaderParameterFilter]
    S2 --> S3["Per operation: append OnBehalfOfUser header parameter"]
    S3 --> End2([Swagger UI shows the header])

Failure and edge-case behavior

  • The decision is made once, at startup; attaching a debugger afterward does not retroactively enable the filter.
  • Hiding the header from Swagger UI in non-debug environments does not stop the server from honoring the header — it is documentation-only, not a control.

Sources

  • src/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Extensions/SwaggerGenOptionsExtensions.cs
  • src/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Swagger/OnBehalfOfUserHeaderParameterFilter.cs