You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-4Lines changed: 66 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -345,11 +345,70 @@ public class CoreModuleMapperRegister : IRegister
345
345
}
346
346
```
347
347
348
-
### Testing the API
348
+
Perfect 🚀 — let’s make it **short and developer‑oriented**, but also **informative** about how the OpenAPI part is setup (MSBuild, package references, and post‑build step).
349
349
350
-
#### Swagger UI
350
+
Here’s a **drop‑in section** for your README that matches the style of what you already have:
351
+
352
+
---
353
+
354
+
### OpenAPI Specification and Swagger UI
355
+
356
+
The project uses **build‑time OpenAPI** documentation creation.
357
+
358
+
- On **build**, the OpenAPI specification is generated to `wwwroot/openapi.json`.
359
+
- ASP.NET Core serves this as a **static file** at [https://localhost:7144/openapi.json](https://localhost:7144/openapi.json).
360
+
-**Swagger UI** ([https://localhost:7144/swagger/index.html](https://localhost:7144/swagger/index.html)) is configured to use the generated specification.
361
+
362
+
This ensures the specification is **consistent across environments** and available as a build artifact.
363
+
364
+
#### Setup
365
+
366
+
-**Packages used**:
367
+
-`Microsoft.AspNetCore.OpenApi`
368
+
-`Microsoft.Extensions.ApiDescription.Server`
369
+
-`Swashbuckle.AspNetCore.SwaggerUI` (for the UI only)
-**OpenApi services and static files** (`Program.cs`):
382
+
```csharp
383
+
builder.Services.AddEndpointsApiExplorer();
384
+
builder.Services.AddOpenApi();
385
+
...
386
+
app.UseSwaggerUI(o=>
387
+
{
388
+
o.SwaggerEndpoint("/openapi.json", "v1");
389
+
app.MapOpenApi();
390
+
});
391
+
app.UseStaticFiles();
392
+
```
351
393
352
-
Start the application (CTRL-F5) and test via [Swagger UI](https://localhost:7144/swagger/index.html).
394
+
395
+
This ensures `openapi.json` is automatically created **after each build**. More information can be found in the [Microsoft Docs](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/aspnetcore-openapi#generate-openapi-documents-at-build-time).
396
+
397
+
#### Client generation
398
+
399
+
The generated specification can be used to build strongly‑typed clients:
Since Swagger UI serves the exact same specification as a static asset, it can be targeted at the following endpoint: `https://localhost:7144/openapi.json`
410
+
411
+
### Testing
353
412
354
413
#### Unit Tests
355
414
@@ -361,9 +420,12 @@ Run tests in `CoreModule.IntegrationTests` (e.g., CustomerEndpointTests for HTTP
361
420
362
421
#### HTTP Tests
363
422
364
-
Use tools like Postman or VS HTTP file to test endpoints:
423
+
Use tools like Bruno/Postman or VS HTTP file to test endpoints:
365
424
- GET /api/core/customers
366
425
- POST /api/core/customers with body { "firstName": "John", "lastName": "Doe", "email": "john.doe@example.com" }
426
+
427
+
A few example requests are in [Core-API.http](./src/Modules/CoreModule/Core-API.http).
0 commit comments