Skip to content

Commit a870c68

Browse files
Enhance OpenAPI docs
1 parent 0007a08 commit a870c68

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/Modules/Grand.Module.Api/Extensions/OpenApiOptionsExtensions.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Grand.Module.Api.Attributes;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.AspNetCore.OpenApi;
4+
using Microsoft.OpenApi.Any;
45
using Microsoft.OpenApi.Models;
56

67
namespace Grand.Module.Api.Infrastructure.Extensions
@@ -45,7 +46,8 @@ public static void AddOperationTransformer(this OpenApiOptions options)
4546
Name = "$orderby",
4647
AllowReserved = true,
4748
In = ParameterLocation.Query,
48-
Description = "Order items by property values",
49+
Description = "Order items by property values (LINQ notation)",
50+
Example = new OpenApiString("Name, DisplayOrder"),
4951
Required = false,
5052
Schema = new OpenApiSchema {
5153
Type = "string"
@@ -55,7 +57,8 @@ public static void AddOperationTransformer(this OpenApiOptions options)
5557
Name = "$filter",
5658
AllowReserved = true,
5759
In = ParameterLocation.Query,
58-
Description = "Filter items by property values",
60+
Description = "Filter items by property values (LINQ notation) ",
61+
Example = new OpenApiString("Name == \"John\""),
5962
Required = false,
6063
Schema = new OpenApiSchema {
6164
Type = "string"
@@ -65,7 +68,8 @@ public static void AddOperationTransformer(this OpenApiOptions options)
6568
Name = "$select",
6669
AllowReserved = true,
6770
In = ParameterLocation.Query,
68-
Description = "Select specific properties from the model",
71+
Description = "Select specific properties from the model (LINQ notation)",
72+
Example = new OpenApiString("Id, Name"),
6973
Required = false,
7074
Schema = new OpenApiSchema {
7175
Type = "string"
@@ -98,7 +102,7 @@ public static void AddCsrfTokenTransformer(this OpenApiOptions options)
98102
public static void AddContactDocumentTransformer(this OpenApiOptions options, string name, string version)
99103
{
100104
options.AddDocumentTransformer((document, context, cancellationToken) =>
101-
{
105+
{
102106
document.Info = new OpenApiInfo {
103107
Description = "Grandnode API",
104108
Title = name,
@@ -117,5 +121,13 @@ public static void AddContactDocumentTransformer(this OpenApiOptions options, st
117121
return Task.CompletedTask;
118122
});
119123
}
124+
public static void AddClearServerDocumentTransformer(this OpenApiOptions options)
125+
{
126+
options.AddDocumentTransformer((document, context, cancellationToken) =>
127+
{
128+
document.Servers.Clear();
129+
return Task.CompletedTask;
130+
});
131+
}
120132
}
121133
}

src/Modules/Grand.Module.Api/Infrastructure/OpenApiStartup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ private void ConfigureBackendApi(IServiceCollection services)
7474
options.AddDocumentTransformer<BearerSecuritySchemeTransformer>();
7575
options.AddSchemaTransformer<EnumSchemaTransformer>();
7676
options.AddOperationTransformer();
77+
options.AddClearServerDocumentTransformer();
7778
});
7879
}
7980

@@ -87,6 +88,7 @@ private void ConfigureFrontendApi(IServiceCollection services)
8788
options.AddSchemaTransformer<EnumSchemaTransformer>();
8889
options.AddSchemaTransformer<IgnoreFieldSchemaTransformer>();
8990
options.AddCsrfTokenTransformer();
91+
options.AddClearServerDocumentTransformer();
9092
});
9193

9294
//api description provider

0 commit comments

Comments
 (0)