remade swagger lol

This commit is contained in:
DESKTOP-T0O5CDB\DESK-555BD 2026-01-03 14:58:01 -07:00
parent 4509eff284
commit bb751b6fec
7 changed files with 476 additions and 1097 deletions

View File

@ -6,6 +6,7 @@ using CarCareTracker.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using System.Text.Json;
namespace CarCareTracker.Controllers
{
@ -103,7 +104,23 @@ namespace CarCareTracker.Controllers
}
public IActionResult Index()
{
return View();
//load up documentation
var apiDocFilePath = _fileHelper.GetFullFilePath("/defaults/api.json");
var apiDocText = _fileHelper.GetFileText(apiDocFilePath);
var apiDocData = JsonSerializer.Deserialize<List<APIDocumentation>>(apiDocText);
var apiSerializeOptions = StaticHelper.GetNoEncodingOption();
apiSerializeOptions.WriteIndented = true;
foreach(APIDocumentation apiDocumentation in apiDocData)
{
foreach(APIMethod apiMethod in apiDocumentation.Methods)
{
if (apiMethod.HasBody)
{
apiMethod.BodySampleString = JsonSerializer.Serialize(apiMethod.BodySample, apiSerializeOptions);
}
}
}
return View(apiDocData);
}
private int GetUserID()
{

10
Enum/APIMethodType.cs Normal file
View File

@ -0,0 +1,10 @@
namespace CarCareTracker.Models
{
public enum APIMethodType
{
GET = 0,
POST = 1,
PUT = 2,
DELETE = 3
}
}

View File

@ -976,5 +976,21 @@ namespace CarCareTracker.Helper
JsonSerializerOptions serializerOption = new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) };
return serializerOption;
}
public static string GetAPIMethodColor(APIMethodType method)
{
switch (method)
{
case APIMethodType.GET:
return "primary";
case APIMethodType.POST:
return "success";
case APIMethodType.PUT:
return "warning";
case APIMethodType.DELETE:
return "danger";
default:
return "primary";
}
}
}
}

View File

@ -0,0 +1,39 @@
using System.Text.Json.Serialization;
namespace CarCareTracker.Models
{
public class APIDocumentation
{
[JsonPropertyName("categoryName")]
public string CategoryName { get; set; }
[JsonPropertyName("methods")]
public List<APIMethod> Methods { get; set; } = new List<APIMethod>();
}
public class APIMethod
{
[JsonPropertyName("path")]
public string Path { get; set; }
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonPropertyName("methodType")]
public APIMethodType MethodType { get; set; }
[JsonPropertyName("queryParams")]
public List<APIQueryParam> QueryParams { get; set; } = new List<APIQueryParam>();
[JsonPropertyName("hasBody")]
public bool HasBody { get; set; }
[JsonPropertyName("bodySample")]
public object BodySample { get; set; } = new object();
public string BodySampleString { get; set; }
[JsonPropertyName("bodyParamName")]
public string BodyParamName { get; set; }
}
public class APIQueryParam
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("required")]
public bool Required { get; set; }
[JsonPropertyName("description")]
public string Description { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@ -691,4 +691,11 @@ html[data-bs-theme="light"] .frosted {
html[data-bs-theme="dark"] .swal2-validation-message {
background-color: #2d2d2e !important;
}
.api-chevron{
transition: all 0.35s;
}
.collapsed .api-chevron {
transform: rotate(180deg);
transition: all 0.35s;
}

252
wwwroot/defaults/api.json Normal file
View File

@ -0,0 +1,252 @@
[
{
"categoryName": "Vehicles",
"methods": [
{
"path": "/api/vehicles",
"description": "Gets list of vehicles user has access to",
"methodType": 0,
"queryParams": [],
"hasBody": false,
"bodySample": null
},
{
"path": "/api/vehicle/info",
"description": "Gets details for list of vehicles or a specific vehicle",
"methodType": 0,
"queryParams": [
{
"name": "vehicleId",
"description": "Id of the vehicle",
"required": false
}
],
"hasBody": false,
"bodySample": null
},
{
"path": "/api/vehicle/adjustedodometer",
"description": "Gets odometer reading with adjustments applied",
"methodType": 0,
"queryParams": [
{
"name": "vehicleId",
"description": "Id of the vehicle",
"required": true
},
{
"name": "odometer",
"description": "Unadjusted odometer",
"required": true
}
],
"hasBody": false,
"bodySample": null
},
{
"path": "/api/vehicles/add",
"description": "Adds a vehicle",
"methodType": 1,
"queryParams": [],
"hasBody": true,
"bodyParamName": "input",
"bodySample": {
"year": 2019,
"make": "Nissan",
"model": "Altima",
"identifier": "LicensePlate",
"licensePlate": "HITNCURBS",
"fuelType": "Gasoline",
"tags": "sedan nissan",
"extraFields": [
{
"name": "VIN",
"value": "0000"
}
]
}
},
{
"path": "/api/vehicles/update",
"description": "Updates a vehicle",
"methodType": 2,
"queryParams": [],
"hasBody": true,
"bodyParamName": "input",
"bodySample": {
"id": 1,
"year": 2019,
"make": "Nissan",
"model": "Altima",
"identifier": "LicensePlate",
"licensePlate": "HITNCURBS",
"fuelType": "Diesel",
"tags": "sedan nissan",
"extraFields": [
{
"name": "VIN",
"value": "0000"
}
]
}
}
]
},
{
"categoryName": "Odometer Records",
"methods": [
{
"path": "/api/vehicle/odometerrecords/all",
"description": "Gets Odometer Records for all vehicles in user's garage",
"methodType": 0,
"queryParams": [
{
"name": "id",
"description": "Id of the specific record",
"required": false
},
{
"name": "startDate",
"description": "Minimum date for records",
"required": false
},
{
"name": "endDate",
"description": "Maximum date for records",
"required": false
},
{
"name": "tags",
"description": "Tags separated by space",
"required": false
}
],
"hasBody": false,
"bodySample": null
},
{
"path": "/api/vehicle/odometerrecords",
"description": "Gets Odometer Records for a vehicle in user's garage",
"methodType": 0,
"queryParams": [
{
"name": "vehicleId",
"description": "Id of the vehicle",
"required": true
},
{
"name": "id",
"description": "Id of the specific record",
"required": false
},
{
"name": "startDate",
"description": "Minimum date for records",
"required": false
},
{
"name": "endDate",
"description": "Maximum date for records",
"required": false
},
{
"name": "tags",
"description": "Tags separated by space",
"required": false
}
],
"hasBody": false,
"bodySample": null
},
{
"path": "/api/vehicle/odometerrecords/latest",
"description": "Gets latest odometer reading for a vehicle",
"methodType": 0,
"queryParams": [
{
"name": "vehicleId",
"description": "Id of the vehicle",
"required": true
}
],
"hasBody": false,
"bodySample": null
},
{
"path":"/api/vehicle/odometerrecords/add",
"description": "Adds an odometer record for a vehicle",
"methodType": 1,
"queryParams": [
{
"name": "vehicleId",
"description": "Id of the vehicle",
"required": true
}
],
"hasBody": true,
"bodyParamName": "input",
"bodySample": {
"date": "2026-01-03",
"initialOdometer": 15000,
"odometer": 16500,
"notes": "test",
"tags": "testing",
"extraFields": [
{
"name": "location",
"value": "Price Utah"
}
],
"files": [
{
"name": "Attachment Example",
"location": "https://lubelogger.com"
}
]
}
},
{
"path":"/api/vehicle/odometerrecords/update",
"description": "Updates an odometer record for a vehicle",
"methodType": 2,
"queryParams": [],
"hasBody": true,
"bodyParamName": "input",
"bodySample": {
"id": 1,
"date": "2026-01-03",
"initialOdometer": 15000,
"odometer": 16500,
"notes": "test",
"tags": "testing",
"extraFields": [
{
"name": "location",
"value": "Price Utah"
}
],
"files": [
{
"name": "Attachment Example",
"location": "https://lubelogger.com"
}
]
}
},
{
"path": "/api/vehicle/odometerrecords/delete",
"description": "Deletes an odometer record",
"methodType": 3,
"queryParams": [
{
"name": "id",
"description": "Id of the odometer record",
"required": true
}
],
"hasBody": false,
"bodySample": null
}
]
}
]