Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
seungyongshim committed Feb 18, 2024
1 parent 98de6f6 commit df3c090
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ app.UseExceptionHandler();
```csharp

```

## Swagger Request Exapmle 작성
* https://medium.com/@niteshsinghal85/multiple-request-response-examples-for-swagger-ui-in-asp-net-core-864c0bdc6619
5 changes: 1 addition & 4 deletions src/WebApplicationMinimalApi8/Dto/MessageDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ namespace WebApplicationMinimalApi8.Dto;

public record MessageDto
{
/// <summary>
///
/// </summary>
/// <example>안녕하세요</example>
[SwaggerParameterExample]
public required string Body { get; init; }

}
Expand Down
29 changes: 7 additions & 22 deletions src/WebApplicationMinimalApi8/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using System.Reflection.Metadata.Ecma335;
using FluentValidation;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Filters;
using WebApplicationMinimalApi8.Dto;
using WebApplicationMinimalApi8.ExceptionHandlers;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(c =>
{
c.ExampleFilters();
});
builder.Services.AddSwaggerExamplesFromAssemblyOf<Program>();
builder.Services.AddValidatorsFromAssemblyContaining<Program>();
builder.AddFluentValidationEndpointFilter();

Expand All @@ -32,27 +37,7 @@
.WithDescription("메시지를 검증합니다.")

.AddFluentValidationFilter()
.WithOpenApi(x =>
{
x.RequestBody = new OpenApiRequestBody
{
Content =
{
["application/json"] = new OpenApiMediaType
{
Schema = new OpenApiSchema
{
Reference = new OpenApiReference
{
Id = "MessageDto",
Type = ReferenceType.Schema
}
}
}
}
};
return x;
});
.WithOpenApi();

app.MapGet("/500", () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="ForEvolve.FluentValidation.AspNetCore.Http" Version="1.0.26" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit df3c090

Please sign in to comment.