Skip to content

Commit b08ab9b

Browse files
committed
Corrections in openapi documentation
1 parent 5c85c3a commit b08ab9b

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

docs/usage/openapi-client.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ The easiest way to get started is by using the built-in capabilities of Visual S
1616
Optionally provide a class name and namespace and click **Finish**.
1717
Visual Studio now downloads your swagger.json and updates your project file. This results in a pre-build step that generates the client code.
1818

19-
Tip: To later re-download swagger.json and regenerate the client code, right-click **Dependencies** > **Manage Connected Services** and click the **Refresh** icon.
19+
> [!TIP]
20+
> To later re-download swagger.json and regenerate the client code, right-click **Dependencies** > **Manage Connected Services** and click the **Refresh** icon.
21+
2022
3. Although not strictly required, we recommend to run package update now, which fixes some issues and removes the `Stream` parameter from generated calls.
2123

2224
4. Add some demo code that calls one of your JSON:API endpoints. For example:
@@ -41,7 +43,7 @@ The easiest way to get started is by using the built-in capabilities of Visual S
4143
dotnet add package JsonApiDotNetCore.OpenApi.Client
4244
```
4345
44-
6. Add the following glue code to connect our package with your generated code. The code below assumes you specified `ExampleApiClient` as class name in step 2.
46+
6. Add the following glue code to connect our package with your generated code. The code below assumes you specified `ExampleApiClient` as the class name in step 2.
4547
4648
```c#
4749
using JsonApiDotNetCore.OpenApi.Client;
@@ -56,6 +58,9 @@ The easiest way to get started is by using the built-in capabilities of Visual S
5658
}
5759
```
5860
61+
> [!NOTE]
62+
> If you specified a namespace in step 2, put this class in the same namespace. For example, add `namespace GeneratedCode;` below the `using` lines.
63+
5964
7. Extend your demo code to send a partial PATCH request with the help of our package:
6065
6166
```c#
@@ -72,11 +77,11 @@ The easiest way to get started is by using the built-in capabilities of Visual S
7277
};
7378
7479
// This line results in sending "lastName: null" instead of omitting it.
75-
using (apiClient.RegisterAttributesForRequestDocument<PersonPatchRequestDocument,
76-
PersonAttributesInPatchRequest>(patchRequest, person => person.LastName))
80+
using (apiClient.WithPartialAttributeSerialization<PersonPatchRequestDocument, PersonAttributesInPatchRequest>(patchRequest,
81+
person => person.LastName))
7782
{
7883
PersonPrimaryResponseDocument patchResponse =
79-
await apiClient.PatchPersonAsync("1", patchRequest);
84+
await apiClient.PatchPersonAsync(1, patchRequest);
8085
8186
// The sent request looks like this:
8287
// {
@@ -100,19 +105,19 @@ Alternatively, the next section shows what to add to your client project file di
100105
101106
```xml
102107
<ItemGroup>
103-
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="3.0.0">
108+
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="7.0.11">
104109
<PrivateAssets>all</PrivateAssets>
105110
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
106111
</PackageReference>
107-
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
108-
<PackageReference Include="NSwag.ApiDescription.Client" Version="13.0.5">
112+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
113+
<PackageReference Include="NSwag.ApiDescription.Client" Version="13.20.0">
109114
<PrivateAssets>all</PrivateAssets>
110115
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
111116
</PackageReference>
112117
</ItemGroup>
113118
114119
<ItemGroup>
115-
<OpenApiReference Include="OpenAPIs\swagger.json" CodeGenerator="NSwagCSharp" ClassName="ExampleApiClient">
120+
<OpenApiReference Include="OpenAPIs\swagger.json" CodeGenerator="NSwagCSharp" Namespace="GeneratedCode" ClassName="ExampleApiClient">
116121
<SourceUri>http://localhost:14140/swagger/v1/swagger.json</SourceUri>
117122
</OpenApiReference>
118123
</ItemGroup>

docs/usage/openapi.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,26 @@ JsonApiDotNetCore provides an extension package that enables you to produce an [
1616
```c#
1717
IMvcCoreBuilder mvcCoreBuilder = builder.Services.AddMvcCore();
1818
19+
// Include the mvcBuilder parameter.
1920
builder.Services.AddJsonApi<AppDbContext>(mvcBuilder: mvcCoreBuilder);
2021
21-
// Configures Swashbuckle for JSON:API.
22+
// Configure Swashbuckle for JSON:API.
2223
builder.Services.AddOpenApi(mvcCoreBuilder);
2324
2425
var app = builder.Build();
2526
2627
app.UseRouting();
2728
app.UseJsonApi();
2829
29-
// Adds the Swashbuckle middleware.
30+
// Add the Swashbuckle middleware.
3031
app.UseSwagger();
3132
```
3233
3334
By default, the OpenAPI specification will be available at `http://localhost:<port>/swagger/v1/swagger.json`.
3435
3536
## Documentation
3637
37-
Swashbuckle also ships with [SwaggerUI](https://swagger.io/tools/swagger-ui/), tooling for a generated documentation page. This can be enabled by installing the `Swashbuckle.AspNetCore.SwaggerUI` NuGet package and adding the following to your `Program.cs` file:
38+
Swashbuckle also ships with [SwaggerUI](https://swagger.io/tools/swagger-ui/), which enables to visualize and interact with the API endpoints through a web page. This can be enabled by installing the `Swashbuckle.AspNetCore.SwaggerUI` NuGet package and adding the following to your `Program.cs` file:
3839
3940
```c#
4041
app.UseSwaggerUI();

0 commit comments

Comments
 (0)