Yoana Gancheva
Yoana Gancheva

Reputation: 629

Is there <NonBodyParameter> equivalent

I updated Swashbuckle v5 and operation.Parameters() is not valid anymore.Is there any replacement?

        {
            var apiDescription = context.ApiDescription;

            operation.Deprecated |= apiDescription.IsDeprecated();

            if (operation.Parameters == null)
            {
                return;
            }

            // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/412
            // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/413
            foreach (var parameter in operation.Parameters<NonBodyParameter>())
            {

                var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);

                if (parameter.Description == null)
                {
                    parameter.Description = description.ModelMetadata?.Description;
                }

                if (parameter.Default == null)
                {
                    parameter.Default = description.DefaultValue;
                }

                parameter.Required |= description.IsRequired;
            }
        }

Error CS0307 The property 'OpenApiOperation.Parameters' cannot be used with type arguments

Upvotes: 8

Views: 5254

Answers (1)

Harry Biscuit
Harry Biscuit

Reputation: 186

From Swashbuckle.AspNetCore GitHub site

In OpenAPI v3, body parameters are split out into a separate property called RequestBody. So, I think you may be able to remove OfType filter entirely as all values in the collection are "non-body"

I think you should be able to use OpenApiParameter.

Upvotes: 8

Related Questions