AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Code generation for REST API

Open reberinformatik opened this issue 8 years ago • 3 comments

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.

reberinformatik avatar Jun 08 '18 07:06 reberinformatik

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)

RicoSuter avatar Jun 08 '18 08:06 RicoSuter

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.

reberinformatik avatar Jun 08 '18 08:06 reberinformatik

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)

RicoSuter avatar Jun 08 '18 08:06 RicoSuter