Skip to content

Commit

Permalink
feature(all): merge swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed May 24, 2024
1 parent 0dcb01b commit fd5f3c6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/Fibonacci/Fibonacci.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.6.1" />
</ItemGroup>

</Project>
55 changes: 49 additions & 6 deletions src/Fibonacci/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
serviceCollection.AddSingleton<Fibonacci, Fibonacci>();
serviceCollection.AddCors();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();


WebApplication app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
);



app.MapPost("/fibonacci", (
[FromServices] ILogger<Fibonacci> logger,
[FromServices] Fibonacci fibonacci,
Expand All @@ -24,22 +28,34 @@
output.Result = fibonacci.Run(input.Input);
return output;
});
/*
app.MapPost("/crazy-fibonacci", (
[FromServices] ILogger<Fibonacci> logger,
[FromServices] Fibonacci fibonacci,
FibonacciInput input) =>
{
logger.LogDebug("Fibonacci Called");
var output = new FibonacciOutput();
output.Result = fibonacci.Run(input.Input);
return output;
});*/

// http://localhost:30021/function/fibonacci1/hello/guillaume

app.MapGet("/download", ([FromServices] ILogger<Fibonacci> logger) =>
{
logger.LogDebug("Download Called");
string path = Path.Combine(Directory.GetCurrentDirectory(), "dog.png");
return Results.File(path, "image/png");
});
}).WithDescription("Some Method Description");

app.MapGet("/hello/{name}", ([FromServices] ILogger<Fibonacci> logger, string name) =>
{
logger.LogDebug("Hello Called");
return $"Hello {name}!";
});

}).WithDescription("Some Method Description");

app.MapGet("/health", () => "OK");
app.MapGet("/health", () => "OK").WithDescription("Some Method Description");

app.Run();

Expand All @@ -55,6 +71,33 @@ public int Run(int i)
return Run(i - 1) + Run(i - 2);
}
}
/*
internal class CrazyFibonacci
{
private readonly HttpClient _httpClient;
public CrazyFibonacci(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<int> Run(int i)
{
if (i <= 2)
{
return 1;
}
var random =new Random();
var value = random.Next(1, 3);
var response = await _httpClient.PostAsJsonAsync($"http://localhost:30021/function/fibonacci{value}", new FibonacciInput(){Input = i});
var content = await response.Content.ReadAsStringAsync();
return Run(i - 1) + Run(i - 2);
}
}*/

public record FibonacciInput{
public int Input { get; set; }
Expand Down

0 comments on commit fd5f3c6

Please sign in to comment.