liveBook · Manning

Operation id

As explained in ASP.NET Core in Action, 3e

An operation ID is a unique identifier for an API operation in an OpenAPI description that can be used by tooling when naming generated client methods.

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

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains fallback and explicit naming through WithName(), but does not detail the full OpenAPI specification.
Examples
Uses FruitPOSTAsync and FruitGETAsync as examples of generated client method names.
What it assumes
Assumes basic familiarity with API endpoints, OpenAPI descriptions, and generated clients.
What you can do after
Apply it via WithName() to produce clearer NSwag client method names.
How it connects
Connects OpenAPI, endpoint naming, NSwag, and generated clients.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.