Skip to content

Commit af55109

Browse files
update swagger kb (#1661)
* update swagger kb * Update conflicting-actions-error-in-swagger-generation-net-core.md --------- Co-authored-by: Todor Arabadzhiev <todor.arabadzhiev@progress.com>
1 parent a2ddc02 commit af55109

File tree

1 file changed

+22
-63
lines changed

1 file changed

+22
-63
lines changed
Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
title: Failed to load API definition is displayed on the Swagger Generation page
3-
description: Swagger requires actions to have unique methods/paths.
2+
title: Swagger UI Generation Page Displays Errors
3+
description: "Learn why the Swagger UI generation tools such as NSwag and Swashbuckle may require special settings for Telerik Reporting."
44
type: troubleshooting
5-
page_title: Conflicting method/path combination for actions in Swagger Generation
5+
page_title: Swagger UI Generation Conflicting method/path combination for Actions
66
slug: conflicting-actions-error-in-swagger-generation-net-core
77
position:
8-
tags: .NET 5.0, .NET Core, WebReportDesigner
8+
tags: .NET 6.0, .NET Core, WebReportDesigner
99
ticketid: 1543912
1010
res_type: kb
1111
---
@@ -27,7 +27,7 @@ res_type: kb
2727

2828
## Description
2929

30-
`Failed to load API definition.` message is displayed on the Swagger Generation page(usually `localhost:port/swagger`).
30+
A `Failed to load API definition.` message is displayed on the Swagger UI Generation page(usually at `https://localhost:port/swagger`).
3131

3232
There may also be a short error on the page about being unable to fetch `swagger.json`.
3333

@@ -71,81 +71,40 @@ System.InvalidOperationException: The method 'get' on path '/api/ReportDesignerC
7171

7272
## Cause
7373

74-
There is a confliction method/path in ReportDesignerController. Swagger requires actions to have unique methods/paths.
74+
There are conflicting methods/paths in the [ReportsController](/api/telerik.reporting.services.webapi.reportscontrollerbase) and [ReportDesignerController](/api/telerik.webreportdesigner.services.controllers.reportdesignercontrollerbase) controllers, as well as some `Obsolete` Actions. Swagger requires actions to have unique methods/paths, and by default - no `Obsolete` actions are accepted.
7575

7676
## Solution
7777

7878
### Swashbuckle
7979

80-
- For .NET Core 3.1 and .NET 5, configure the Swagger Generation in **Startup.cs**:
80+
Configure the following Swagger UI Generation configuration in the **Program.cs**/**Startup.cs** file of the project:
8181

8282
````CSharp
83-
public void ConfigureServices(IServiceCollection services)
84-
{
85-
...
86-
services.AddSwaggerGen(c => {
87-
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
88-
c.IgnoreObsoleteActions();
89-
c.IgnoreObsoleteProperties();
90-
c.CustomSchemaIds(type => type.FullName);
91-
});
92-
...
93-
}
94-
````
95-
96-
- For .NET 6+, configure the Swagger Generation in **Program.cs**
97-
98-
````CSharp
99-
builder.Services.AddSwaggerGen(c => {
100-
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
101-
c.IgnoreObsoleteActions();
102-
c.IgnoreObsoleteProperties();
103-
c.CustomSchemaIds(type => type.FullName);
83+
builder.Services.AddSwaggerGen(options => {
84+
options.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
85+
options.IgnoreObsoleteActions();
86+
options.IgnoreObsoleteProperties();
87+
options.CustomSchemaIds(type => type.FullName);
10488
});
10589
````
10690

10791
### NSwag
10892

109-
Implement the `NSwag.Generation.Processors.IOperationProcessor` interface as follows and then use it in the `AddSwaggerGen` configuration:
93+
The [ReportsController](/api/telerik.reporting.services.webapi.reportscontrollerbase) should work normally with **NSwag**. However, if the [ReportDesignerController](/api/telerik.webreportdesigner.services.controllers.reportdesignercontrollerbase) is used, it should be ignored by the Swagger generation tool by attaching to it the `[ApiExplorerSettings(IgnoreApi = true)]` attribute:
11094

11195
````CSharp
112-
public class IncludeControllersInSwagger : IOperationProcessor
96+
[ApiExplorerSettings(IgnoreApi = true)]
97+
[Route("api/reportdesigner")]
98+
public class ReportDesignerController : ReportDesignerControllerBase
11399
{
114-
public bool Process(OperationProcessorContext context)
115-
{
116-
return ShouldIncludeController(context.ControllerType);
117-
}
118-
119-
bool ShouldIncludeController(System.Type type)
120-
{
121-
return !(type.AssemblyQualifiedName == typeof(Telerik.WebReportDesigner.Services.Controllers.ReportDesignerControllerBase).AssemblyQualifiedName);
122-
}
100+
public ReportDesignerController(IReportDesignerServiceConfiguration reportDesignerServiceConfiguration, IReportServiceConfiguration reportServiceConfiguration)
101+
: base(reportDesignerServiceConfiguration, reportServiceConfiguration)
102+
{
103+
}
123104
}
124105
````
125106

126-
- For .NET Core 3.1 and .NET 5, configure the Swagger Generation in **Startup.cs**:
127-
128-
````CSharp
129-
public void ConfigureServices(IServiceCollection services)
130-
{
131-
...
132-
services.AddSwaggerGen(c => {
133-
c.IgnoreObsoleteProperties = true;
134-
c.OperationProcessors.Add(new IncludeControllersInSwagger());
135-
});
136-
...
137-
}
138-
````
139-
140-
- For .NET 6+, configure the Swagger Generation in **Program.cs**
141-
142-
````CSharp
143-
builder.Services.AddSwaggerGen(c => {
144-
c.IgnoreObsoleteProperties = true;
145-
c.OperationProcessors.Add(new IncludeControllersInSwagger());
146-
});
147-
````
148-
149107
## See Also
150108

151-
[NSwag filter namespace](https://stackoverflow.com/questions/52337355/nswag-filter-namespace)
109+
* [Get started with NSwag and ASP.NET Core]([https://stackoverflow.com/questions/52337355/nswag-filter-namespace](https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-nswag)
110+
* [Get started with Swashbuckle and ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle)

0 commit comments

Comments
 (0)