Skip to content

Swashbuckle 10 and SwaggerDefaultValues.cs #1158

@martinRocks

Description

@martinRocks

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I'm upgrading my project for dot net 9 to dot net 10. I figured it would be good to use Swashbuckle.AspNetCore 10.1.0 also. The example code to get the swagger page to show my versions is SwaggerDefaultValues.cs and it seem that the parameter.Schema.Default is now only a getter so there is no setting it. Also, OpenApiAnyFactory is no longer a thing. And parameter.Required is a getter only. What do we do? I think the example needs to be updated.

``
foreach (var parameter in operation.Parameters)
{
var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);

parameter.Description ??= description.ModelMetadata?.Description;

if (parameter.Schema.Default == null && description.DefaultValue != null)
{
    var json = JsonSerializer.Serialize(description.DefaultValue, description.ModelMetadata.ModelType);
    parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson(json);
}

parameter.Required |= description.IsRequired;

}
``

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions