An operation ID uniquely identifies an API operation in an OpenAPI description. Client-generation tools such as NSwag use it to name generated client methods. section 11.4.3 section 11.7
When an operation lacks an operation ID, NSwag generates a name from the endpoint. The result may be technically valid but awkward, such as FruitPOSTAsync or FruitGETAsync. section 11.4.3 section 11.7
Improving generated method names
Assign an endpoint name with WithName(). That name becomes the operation ID in the OpenAPI description, allowing NSwag to generate clearer client methods instead of relying on its fallback naming. section 11.4.3 section 11.7
Listing 11.6 Calling the API from listing 11.2 using a generated client
using Fruit; #1
var client = new FruitClient( #2
"https://localhost:7186", #3
new HttpClient()); #4
Fruit.Fruit created = await client.FruitPOSTAsync("123", #5
new Fruit.Fruit { Name = "Banana", Stock = 100 }); #6
Console.WriteLine($"Created {created.Name}");
Fruit.Fruit fetched = await client.FruitGETAsync("123"); #7
Console.WriteLine($"Fetched {fetched.Name}");
The generated client demonstrates the practical effect of operation-based method naming through FruitPOSTAsync and FruitGETAsync calls. section 11.4.3
