Hey, I updated .netcore3 and swashbuckle v5 so now I have problem with Microsoft.AspNetCore.Mvc.Versioning project.My filter look like this :
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
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.OfType<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.
The type or namespace name 'NonBodyParameter' could not be found (are you missing a using directive or an assembly reference?
Is there any equivalent of this?
related https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1147
I think we just need to create a OpenApiParameter. There is a OpenApiBodyParameter but it's defined as internal https://github.com/microsoft/OpenAPI.NET/blob/578e5870d299992b9cd8414c1a1e655a56e0403c/src/Microsoft.OpenApi/Models/OpenApiParameter.cs#L319
Same thing happened to me. I switched to OpenApiParameter and used the In = ParameterLocation.Header property. It's not exactly your usage, but hopefully this helps.
BEFORE
operation.Parameters?.Add( new NonBodyParameter
{
Name = "Authorization",
In = "header",
Description = "Bearer access token",
Required = true,
Type = "string"
});
AFTER
operation.Parameters?.Add( new OpenApiParameter
{
Name = "Authorization",
In = ParameterLocation.Header,
Description = "Bearer access token",
Required = true,
Schema = new OpenApiSchema { Type = "string" }
});
EDIT: Nevermind, it seems v5 detects file uploads and annotates them automatically now, a good thing! Before I needed an IOperationFilter, seems I can ditch that now.
What is the new equivalent for file uploads? This works in v4:
operation.Parameters.Add(new NonBodyParameter
{
Name = "uploadedFile",
In = "formData",
Description = "Upload File",
Required = true,
Type = "file"
})
In v5 OpenApiParameter does not have a FormData type for In and there is not Type field at all.
Just to provide another example, I used this to add the following headers per-request:

operation.Parameters.Add(new NonBodyParameter
{
Name = "Accept-Language",
In = "header",
Type = "string",
Enum = new List<object> { "pt-BR", "en-US" },
Default = "pt-BR"
});
Is there any way to replicate this behavior with the new OpenApiParameter, since it doesn't have the Type, Enum, and Default fields?
@CleytonGoncalves looks like it might have all been moved into the Schema property and wrapped:
operation.Parameters.Add(new OpenApiParameter
{
Name = "Accept-Language"
In = ParameterLocation.Header,
Schema = new OpenApiSchema
{
Type = "string",
Enum = new List<IOpenApiAny>
{
new OpenApiString("pt-BR"),
new OpenApiString("en-US")
},
Default = new OpenApiString("pt-BR")
}
});
@joannayankova can this be closed?
Closing due to inactivity
@domaindrivendev please answer this question
EDIT: Nevermind, it seems v5 detects file uploads and annotates them automatically now, a good thing! Before I needed an IOperationFilter, seems I can ditch that now.
What is the new equivalent for file uploads? This works in v4:
operation.Parameters.Add(new NonBodyParameter
{
Name = "uploadedFile",
In = "formData",
Description = "Upload File",
Required = true,
Type = "file"
})In v5 OpenApiParameter does not have a FormData type for In and there is not Type field at all.
First of all, you guys completely broke this for no reason. So there's that.
And then nobody answered this question - what did you break it to? Nobody can figure it out.
Why is it broken? Nobody knows. Stop breaking stuff.
Most helpful comment
Same thing happened to me. I switched to
OpenApiParameterand used theIn = ParameterLocation.Headerproperty. It's not exactly your usage, but hopefully this helps.BEFORE
AFTER