Skip to content

Commit

Permalink
Set correct parameter position (#4499)
Browse files Browse the repository at this point in the history
* Set correct parameter position

* Improve if readability

* Use Array.Empty instead of allocating

* Set position to to-be-added element

* do not count body parameters
  • Loading branch information
trejjam authored Sep 27, 2023
1 parent 95ce46b commit 40875b4
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public OperationParameterProcessor(AspNetCoreOpenApiDocumentGeneratorSettings se
/// <returns>true if the operation should be added to the Swagger specification.</returns>
public bool Process(OperationProcessorContext operationProcessorContext)
{
if (!(operationProcessorContext is AspNetCoreOperationProcessorContext context))
if (operationProcessorContext is not AspNetCoreOperationProcessorContext context)
{
return false;
}

var httpPath = context.OperationDescription.Path;
var parameters = context.ApiDescription.ParameterDescriptions;
var methodParameters = context.MethodInfo?.GetParameters() ?? new ParameterInfo[0];
var methodParameters = context.MethodInfo?.GetParameters() ?? Array.Empty<ParameterInfo>();

var position = 1;
var position = operationProcessorContext.Parameters.Count(x => x.Value.Kind is not OpenApiParameterKind.Body) + 1;
foreach (var apiParameter in parameters.Where(p =>
p.Source != null &&
(p.ModelMetadata == null || p.ModelMetadata.IsBindingAllowed)))
Expand Down

0 comments on commit 40875b4

Please sign in to comment.