Skip to content

Updates the OpenApiSpecGeneratorPlugin to ignore OPTIONS requests by default. Closes #752 #753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion dev-proxy-plugins/RequestLogs/OpenApiSpecGeneratorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
}
}

internal class OpenApiSpecGeneratorPluginConfiguration
{
public bool IncludeOptionsRequests { get; set; } = false;
}

public class OpenApiSpecGeneratorPlugin : BaseReportingPlugin
{
// from: https://github.com/jonluca/har-to-openapi/blob/0d44409162c0a127cdaccd60b0a270ecd361b829/src/utils/headers.ts
Expand Down Expand Up @@ -281,13 +286,15 @@ public OpenApiSpecGeneratorPlugin(IPluginEvents pluginEvents, IProxyContext cont
}

public override string Name => nameof(OpenApiSpecGeneratorPlugin);
private OpenApiSpecGeneratorPluginConfiguration _configuration = new();
public static readonly string GeneratedOpenApiSpecsKey = "GeneratedOpenApiSpecs";


public override void Register()
{
base.Register();

ConfigSection?.Bind(_configuration);

PluginEvents.AfterRecordingStop += AfterRecordingStop;
}

Expand All @@ -312,6 +319,13 @@ request.Context is null ||
continue;
}

if (!_configuration.IncludeOptionsRequests &&
request.Context.Session.HttpClient.Request.Method.ToUpperInvariant() == "OPTIONS")
{
Logger.LogDebug("Skipping OPTIONS request {url}...", request.Context.Session.HttpClient.Request.RequestUri);
continue;
}

var methodAndUrlString = request.MessageLines.First();
Logger.LogDebug("Processing request {methodAndUrlString}...", methodAndUrlString);

Expand Down