public class Source
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Destination
{
public int Id { get; set; }
public string Name { get; set; }
}
public class MappingProfile : Profile
{
public MappingProfile()
{
CreateMap();
}
}
将映射配置添加到AutoMapper服务中。例如:
services.AddAutoMapper(typeof(MappingProfile));
确保在Swagger中正确配置了API消费者。请检查如下示例配置:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
c.AddSecurityDefinition("ApiKey", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter your Unique ApiKey Here!",
Name = "Authorization",
Type = SecuritySchemeType.ApiKey
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "ApiKey"
}
},
new string[] {}
}
});
c.EnableAnnotations();
c.IncludeXmlComments("MyApi.xml");
c.IncludeXmlComments("MyExternalApi.xml");
});