First post of a series on reshaping Aspire around the API-testing loop: services declare an OpenAPI annotation, and a Scalar resource is meant to discover them. This part is only the data model; the behaviour comes next.
Key points
- ScalarResource is a one-line sealed class deriving from ContainerResource, with no constructor side effects.
- OpenApiAnnotation is a record carrying an EndpointReference, a path and a title, implementing IResourceAnnotation.
- WithOpenApi() defaults to /openapi/v1.json on the http endpoint and falls back to the resource name for the title.
- The where T : IResourceWithEndpoints constraint keeps the extension method on resources that expose endpoints.
- Four axes are answered before coding: resource shape, lifecycle mode, integration role and structure.
- Use With{Tool} when a tool belongs to one parent, Add{Tool} when it serves many resources.
Why it matters
If you register containers by hand in an AppHost, the payoff here is not Scalar itself but the shape of the code: a service says what it offers, a tool discovers it, and the second list you keep in sync with your endpoints disappears. Teams with a handful of services may not feel the classification step pay off at once; the benefit shows up when one utility has to serve several resources. Two caveats before copying anything: this part ships only the data model, so nothing runs until the companion behaviour arrives, and the annotation approach only earns its keep if your services already publish OpenAPI documents.
Real-world use
- An AppHost with several APIs, each publishing its own OpenAPI document, that needs one reference UI for the whole graph
- Services that should stay unaware of which documentation tool the team picks
- Coding agents that burn tokens hunting for ports and endpoints in a terminal before every API test run
This summary was generated by the agent from the original post on Bart Wullems (The Art of Simplicity). The full text and all rights belong to its author and publisher. Go to original