-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor program.cs and update API documentation
- Loading branch information
1 parent
d43f3fb
commit 9146bba
Showing
2 changed files
with
40 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,51 @@ | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.OpenApi.Models; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace WebApiCICDWorkFlow | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
builder.Services.AddAuthorization(); | ||
|
||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(c => | ||
{ | ||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(c => | ||
{ | ||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApiCICDWorkFlow API V1"); | ||
}); | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
} | ||
// Add services to the container. | ||
builder.Services.AddAuthorization(); | ||
|
||
app.UseAuthorization(); | ||
|
||
|
||
//create enum type for calculator operations, opertion is body parameter for the post request | ||
|
||
app.MapGet("/calculator/{operation}/{a}/{b}", ([FromQuery]Operation operation, float a, float b) => | ||
{ | ||
float result = operation switch | ||
{ | ||
Operation.Add => a + b, | ||
Operation.Subtract => a - b, | ||
Operation.Multiply => a * b, | ||
Operation.Divide => a / b, | ||
_ => 0 | ||
}; | ||
return result; | ||
}).WithName("WebApiCICDWorkFlow") | ||
.WithOpenApi(); | ||
// Configure Swagger/OpenAPI | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(c => | ||
{ | ||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(c => | ||
{ | ||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApiCICDWorkFlow API V1"); | ||
}); | ||
|
||
app.Run(); | ||
} | ||
} | ||
app.UseAuthorization(); | ||
|
||
//create enum for the operation | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public enum Operation | ||
app.MapGet("/calculator/{operation}/{a}/{b}", ([FromQuery] Operation operation, float a, float b) => | ||
{ | ||
float result = operation switch | ||
{ | ||
Add, | ||
Subtract, | ||
Multiply, | ||
Divide | ||
} | ||
Operation.Add => a + b, | ||
Operation.Subtract => a - b, | ||
Operation.Multiply => a * b, | ||
Operation.Divide => a / b, | ||
_ => 0 | ||
}; | ||
return result; | ||
}).WithName("WebApiCICDWorkFlow").WithOpenApi(); | ||
|
||
await app.RunAsync(); | ||
|
||
// Enum for the operation | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public enum Operation | ||
{ | ||
Add, | ||
Subtract, | ||
Multiply, | ||
Divide | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
@WebApiCICDWorkFlow_HostAddress = http://localhost:5118 | ||
|
||
GET {{WebApiCICDWorkFlow_HostAddress}}/weatherforecast/ | ||
GET {{WebApiCICDWorkFlow_HostAddress}}/swagger/ | ||
Accept: application/json | ||
|
||
### |