cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Question: How to get rid of `Operation '/api/Documents.get' didn't specify an 'operationId'. Assuming 'apiDocumentsGet'.` #221

Closed Lonli-Lokli closed 2 years ago

Lonli-Lokli commented 2 years ago

I am getting a lot of such messages with code generation, how can I avoid them with Swashbuckle


Operation '/api/Documents.get' didn't specify an 'operationId'. Assuming 'apiDocumentsGet'.
Operation '/api/Documents.put' didn't specify an 'operationId'. Assuming 'apiDocumentsPut'.
TheRealGI commented 2 years ago

Hey @Lonli-Lokli It's hard to tell without a spec but according to this warning there is no operationId set. If you want to set a custom operationId preventing the package from generating one for you simply add the Name property to the HTTP action filter. For example [HttpGet(Name="GetDocuments")]

Toxantron commented 2 years ago

We use this in our StartUp.cs. It generates methods with the same name as the server side methods

services.AddSwaggerGen(c =>
{
  c.CustomOperationIds(api => ((ControllerActionDescriptor)api.ActionDescriptor).MethodInfo.Name);
});
Lonli-Lokli commented 2 years ago

Thanks, I am using now this within class SwaggerDefaultValues : IOperationFilter

operation.OperationId ??= string.Join(string.Empty, (new string[] { apiDescription.HttpMethod ?? string.Empty })
            .Concat((apiDescription.RelativePath ?? string.Empty).Split(@"/"))
            .Select(word => string.Join(string.Empty, word.Split('{', '}')))
            .Select(FirstCharToUpper));