Code generation for REST API
Please show a real world example with REST URLs. The TodoController supports only CRUD operations. But what, when you add a "Details" or a "Search" action? i.e. api/todo/1/details api/todo/search?isComplete=true
In my experience, this will break a clean code generation (MultipleClientsFromOperationId used): We end up having a "TodoClient", a "DetailsClient" and a "SearchClient" which is not what we want.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 2483813a-3c16-7ddd-3160-43e6843b55d4
- Version Independent ID: 25f7fb5b-92b0-a45b-57ab-fdceab571884
- Content: Get started with NSwag and ASP.NET Core
- Content Source: aspnetcore/tutorials/getting-started-with-NSwag.md
- Product: asp.net-core
- GitHub Login: @zuckerthoben
- Microsoft Alias: scaddie
Why would this not generate a "nice" client? I expect that this will generate the following operations with the following operation ids:
- Todo_GetAll, etc. (CRUD)
- Todo_GetDetails
- Todo_Search
Which will then translate in one TodoClient with three methods (GetAll, GetDetails, Search)
You are perfectly right - I was using the Swashbuckle example to generate my API. Your NSwag.SwaggerGeneration.AspNetCore Swagger generator generates the operationIds as you stated. So as we are using Swashbuckle as Swagger generator (I guess NSwag.SwaggerGeneration.AspNetCore is still experimental?) this leads to the question: How are you generating your operationIds? I would like to adapt this behaviour to Swashbuckle, as otherwise I get the problem mentioned in the issue.
I think NSwag.SwaggerGeneration.AspNetCore is fairly stable and safe to use via middleware (there are still some problems when using it via CLI but that's another story). With Swashbuckle, you can implement a custom operation filter and transform/generate the operation ids as expected. Probably there is already sample code for this somewhere as most code gens expect the operation in the form controller_operation (e.g. AutoRest, NSwag, swagger-codegen)