You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The C# service code generator produces a controller base class that declares it implements an interface, but the base class itself does not directly implement the methods defined in that interface. Instead, it relies on a nested class to implement the interface methods. This creates a mismatch between the declared interface implementation and the actual implementation, leading to build errors.
Steps to Reproduce:
Use the OpenAPI code generator to generate a C# ASP.NET Core project with a controller that implements an interface.
Observe that the generated controller base class declares that it implements the interface but does not directly implement the interface methods.
Observe that the generated base class defines an abstract nested class and an abstract property of that type.
Attempt to build the project.
Observe the compiler error CS0535: '...' does not implement interface member '...'.
Expected Behavior:
The generated base controller class should either:
Directly Implement the Interface: The base class should directly implement the methods defined in the interface.
Not Declare Interface Implementation: The base class should not declare that it implements the interface. Instead, the nested class should implement the interface, and the concrete controller should implement the abstract property.
Actual Behavior:
The generated base controller class declares that it implements the interface but does not directly implement the interface methods. Instead, it relies on a nested class to implement the interface methods.
Reproduction
I'm working on a 'Todo' app that's pretty large, and I can share the tsp file I used to generate, here's an example of a generated interface and controller base files for context:
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated />
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Getitdone.Service.Models;
namespace Getitdone.Service.Operations
{
public interface ICommentOpsOperations
{
Task<Comment> GetCommentAsync(string commentId);
Task<Comment> UpdateCommentAsync(string commentId, UpdateCommentRequest body);
Task DeleteCommentAsync(string commentId);
}
}
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated />
using System;
using System.Net;
using System.Threading.Tasks;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;
using Getitdone.Service.Models;
using Getitdone.Service;
namespace Getitdone.Service.Controllers
{
[ApiController]
public abstract partial class CommentsOperationsControllerBase : ControllerBase
{
internal abstract ICommentsOperations CommentsOperationsImpl { get; }
[HttpGet]
[Route("/comments")]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(Comment[]))]
public virtual async Task<IActionResult> GetComments([FromQuery(Name = "task_id")] string taskId, [FromQuery(Name = "project_id")] string projectId)
{
var result = await CommentsOperationsImpl.GetCommentsAsync(taskId, projectId);
return Ok(result);
}
[HttpPost]
[Route("/comments")]
[ProducesResponseType((int)HttpStatusCode.Created, Type = typeof(Comment))]
public virtual async Task<IActionResult> CreateComment(CreateCommentRequest body)
{
var result = await CommentsOperationsImpl.CreateCommentAsync(body);
return Ok(result);
}
}
}
Describe the bug
Description:
The C# service code generator produces a controller base class that declares it implements an interface, but the base class itself does not directly implement the methods defined in that interface. Instead, it relies on a nested class to implement the interface methods. This creates a mismatch between the declared interface implementation and the actual implementation, leading to build errors.
Steps to Reproduce:
CS0535: '...' does not implement interface member '...'
.Expected Behavior:
The generated base controller class should either:
Actual Behavior:
The generated base controller class declares that it implements the interface but does not directly implement the interface methods. Instead, it relies on a nested class to implement the interface methods.
Reproduction
I'm working on a 'Todo' app that's pretty large, and I can share the tsp file I used to generate, here's an example of a generated interface and controller base files for context:
Checklist
The text was updated successfully, but these errors were encountered: