Skip to content

Commit

Permalink
Update CHANGELOG and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubfijalkowski committed Jan 3, 2025
1 parent 35b703c commit 50df404
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ but this project DOES NOT adhere to [Semantic Versioning](http://semver.org/).
* Remove LeanCode.PdfRocket
* Remove StyleCop completely
* JSON serializer for CQRS now shares options with ASP.NET Core's `JsonOptions` by default
* Integrates with Microsoft.AspNetCore.OpenApi better

## 8.1

Expand Down
29 changes: 9 additions & 20 deletions docs/external_integrations/api_explorer/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# API Explorer/Swagger integration

[CQRS](../../cqrs/index.md) implementation integrates seamlessly with the [API Explorer](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.apiexplorer) functionality of ASP.NET Core. This means that every endpoint can be automatically documented by other tools that leverage it, e.g. [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) or [NSwag](https://github.com/RicoSuter/NSwag).

By using these tools, you get OpenAPI definitions, along the [Swagger UI](https://swagger.io/tools/swagger-ui/) tooling.
[CQRS](../../cqrs/index.md) implementation integrates seamlessly with the [OpenAPI](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/overview) support of ASP.NET Core. This means that every endpoint can be automatically documented by other tools that leverage it, e.g. [SwaggerUI](https://swagger.io/tools/swaggerhub/) or [ReDoc](https://github.com/Redocly/redoc).

## Packages

Expand All @@ -22,24 +20,15 @@ public override void ConfigureServices(IServiceCollection services)
```

The `AddCQRSApiExplorer` method has an optional parameter that accepts a configuration override.
For now, it only allows to set a custom mapping of the `RouteValues` parameter,
which is used by OpenAPI generation tools to pass some metadata, by which the endpoints
could be grouped on the OpenAPI UI, for example. Usage of this metadata varies between
different OpenAPI UI implementations, so please check the tools documentation before overriding it.

## JSON Casing
It allows configuring what metadata is passed to the OpenAPI tooling, including:

Every integration uses different configuration for the generated payload types. It is highly probable that the default configuration of JSON serializer for these integrations will use wrong property casing. Unfortunately, every tool is configured differently.
1. Tags,
2. Summary,
3. Description.

### Swashbuckle
See the [implementation] for defaults.

To configure Swashbuckle, you need to register custom `ISerializerDataContractResolver` that has the same configurtion as the `ISerializer` of CQRS.
To better accomodate common tag patterns, we also provide [ApiDescriptionTags] class with predefined tag generation based on the namespace of the command/query/operation.

```csharp
// This will use default JSON serialization, with unchanged property names (this is the default of System.Text.Json) & CQRS
builder
.Services
.AddTransient<ISerializerDataContractResolver>(
_ => new JsonSerializerDataContractResolver(new JsonSerializerOptions { PropertyNamingPolicy = null })
);
```
[implementation]: https://github.com/leancodepl/corelibrary/blob/HEAD/src/CQRS/LeanCode.CQRS.AspNetCore/Registration/CQRSApiDescriptionConfiguration.cs
[ApiDescriptionTags]: https://github.com/leancodepl/corelibrary/blob/HEAD/src/CQRS/LeanCode.CQRS.AspNetCore/Registration/ApiDescriptionTags.cs

0 comments on commit 50df404

Please sign in to comment.