You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Numerous extension methods exist to enable customization of the generated OpenAPI description. Endpoints defined via minimal APIs can be annotated with metadata for use in OpenAPI libraries with a series of extension methods.
81
+
82
+
You can set the EndpointName or `EndpointGroupName` of an endpoint using the `WithName` and `WithGroupName` extension methods as follows.
> Note: If you have multiple `WithName` statements on the same endpoint, the last endpoint will be favored.
90
+
91
+
On the topic of endpoint names, by default, endpoints that use a method group or named lambda will have their endpoint name set to the method name. For example, in the code snippet below, the endpoint will have a default endpoint name of `SomeMessage`.
92
+
93
+
```csharp
94
+
stringSomeMessage() =>"Hello World.";
95
+
app.MapGet("/hello", SomeMessage);
96
+
```
97
+
98
+
This default endpoint name can be overloaded by using the `WithName` extension method as referenced above.
Let's say that you did want an endpoint to be annotated. In addition to endpoint names, you can also use the various `ProducesX` endpoints to indicate the response types of a method. The available extension methods are:
In general, the `Produces` extension methods give you the flexibility to set a `ProblemDetails` response type for your endpoint or define what response it returns on happy-path scenarios. You can do this with the generic-typed implementation `Produces<TResponse>` or with the `Produces` attribute. So, for example, to define the response metadata for a POST method that returns a `Todo` or a `ProblemDetails` response you can annotate it using the following extension methods.
0 commit comments