Skip to content

Commit 2e65584

Browse files
authored
Merge pull request #308 from neuroglia-io/swagger-fix
Removed most non-essential external schemas (introducedby ODATA) from the OpenAPI documentation file
2 parents 3c5e886 + 26d3d6a commit 2e65584

File tree

5 files changed

+119
-4
lines changed

5 files changed

+119
-4
lines changed

src/apis/management/Synapse.Apis.Management.Http/Extensions/ISynapseApplicationBuilderExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Neuroglia;
2626
using Newtonsoft.Json;
2727
using Newtonsoft.Json.Serialization;
28+
using Synapse.Apis.Management.Http.Services;
2829
using Synapse.Application.Configuration;
2930
using Synapse.Application.Services;
3031
using Synapse.Integration.Serialization.Converters;
@@ -33,7 +34,7 @@ namespace Synapse.Apis.Management.Http
3334
{
3435

3536
/// <summary>
36-
/// Defines extensions for <see cref="ISynapseApplicationBuilder"/>s
37+
/// Defines extensions for <see cref="ISynapseApplicationBuilder"/>s
3738
/// </summary>
3839
public static class ISynapseApplicationBuilderExtensions
3940
{
@@ -73,6 +74,9 @@ public static ISynapseApplicationBuilder UseHttpManagementApi(this ISynapseAppli
7374
.AddApplicationPart(typeof(MetadataController).Assembly);
7475
synapse.Services.AddSwaggerGen(builder =>
7576
{
77+
builder.OperationFilter<IgnoreODataQueryOptionOperationFilter>();
78+
builder.SchemaFilter<IgnorExternalSchemaFilter>();
79+
builder.DocumentFilter<IgnorExternalSchemaFilter>();
7680
builder.CustomOperationIds(o =>
7781
{
7882
if (!string.IsNullOrWhiteSpace(o.RelativePath) && o.RelativePath.StartsWith("odata")) return o.RelativePath;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright © 2022-Present The Synapse Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using Microsoft.OpenApi.Models;
19+
using Swashbuckle.AspNetCore.SwaggerGen;
20+
21+
namespace Synapse.Apis.Management.Http.Services
22+
{
23+
/// <summary>
24+
/// Represents the object used to filter schemas described by the generated OpenAPI documentation
25+
/// </summary>
26+
public class IgnorExternalSchemaFilter
27+
: ISchemaFilter, IDocumentFilter
28+
{
29+
30+
/// <summary>
31+
/// Gets a <see cref="List{T}"/> containing all the schemas to include in the generated OpenAPI documentation
32+
/// </summary>
33+
internal protected static readonly List<string> IncludedSchemas = new();
34+
35+
/// <inheritdoc/>
36+
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
37+
{
38+
if (context.Type.Namespace!.StartsWith("Neuroglia")
39+
|| context.Type.Namespace!.StartsWith("Synapse")
40+
|| context.Type.Namespace.StartsWith("ServerlessWorkflow")
41+
|| context.Type.Namespace == "System")
42+
IncludedSchemas.Add(context.Type.Name);
43+
}
44+
45+
/// <inheritdoc/>
46+
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
47+
{
48+
foreach(var schema in swaggerDoc.Components.Schemas.ToList())
49+
{
50+
if (IncludedSchemas.Contains(schema.Key)) continue;
51+
swaggerDoc.Components.Schemas.Remove(schema.Key);
52+
}
53+
}
54+
55+
}
56+
57+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright © 2022-Present The Synapse Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using Microsoft.OpenApi.Models;
19+
using Swashbuckle.AspNetCore.SwaggerGen;
20+
21+
namespace Synapse.Apis.Management.Http.Services
22+
{
23+
24+
/// <summary>
25+
/// Represents the <see cref="IOperationFilter"/> used to ignore <see cref="ODataQueryOptions"/> parameters
26+
/// </summary>
27+
public class IgnoreODataQueryOptionOperationFilter
28+
: IOperationFilter
29+
{
30+
31+
/// <inheritdoc/>
32+
public virtual void Apply(OpenApiOperation operation, OperationFilterContext context)
33+
{
34+
context.ApiDescription.ParameterDescriptions
35+
.Where(param => param.ParameterDescriptor.ParameterType.IsGenericType && param.ParameterDescriptor.ParameterType.GetGenericTypeDefinition() == typeof(ODataQueryOptions<>))
36+
.ToList()
37+
.ForEach(param =>
38+
{
39+
var parameter = operation.Parameters.SingleOrDefault(p => p.Name == param.Name);
40+
if (parameter != null) operation.Parameters.Remove(parameter);
41+
});
42+
}
43+
44+
}
45+
46+
}

src/dashboard/Synapse.Dashboard/Pages/Workflows/View/View.razor

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
ValueProvider="source => source.Key"
7878
PropertyPath="@PropertyPath.Parse(nameof(V1WorkflowInstance.Key))" />
7979
<Column T="V1WorkflowInstance"
80+
Name="ActivationType"
81+
ValueProvider="source => source.ActivationType"
82+
PropertyPath="@PropertyPath.Parse(nameof(V1WorkflowInstance.ActivationType))">
83+
<CellTemplate Context="context">
84+
<span class="badge rounded-pill bg-secondary">@(EnumHelper.Stringify((V1WorkflowInstanceActivationType)context.Value))</span>
85+
</CellTemplate>
86+
</Column>
87+
<Column T="V1WorkflowInstance"
8088
Name="Status"
8189
ValueProvider="source => source.Status"
8290
PropertyPath="@PropertyPath.Parse(nameof(V1WorkflowInstance.Status))">
@@ -314,9 +322,9 @@ else
314322
await this.workflowToolbar.OnShowWorkflowInputModal(serializedInput);
315323
}
316324

317-
protected string GetCssClassFor(V1WorkflowInstanceStatus workflowInstanceStatus)
325+
protected string GetCssClassFor(V1WorkflowInstanceStatus status)
318326
{
319-
return workflowInstanceStatus switch
327+
return status switch
320328
{
321329
V1WorkflowInstanceStatus.Pending => "bg-secondary",
322330
V1WorkflowInstanceStatus.Scheduling => "border-primary",

src/dashboard/Synapse.Dashboard/wwwroot/css/app.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)