OpenAPI is the contract that describes what an HTTP API can do. It defines endpoints, parameters, request bodies, responses, authentication requirements, schemas, and other information that tools can use to understand an API.
For ASP.NET Core developers, OpenAPI is commonly used to generate interactive documentation, client SDKs, testing tools, and API contracts between development teams.
OpenAPI 3.2 extends the specification with improvements around API description, reusable components, security, webhooks, and more detailed representation of HTTP behavior. The important part for an ASP.NET Core application is understanding how the OpenAPI document maps to the API rather than treating it as only a Swagger UI feature.
This article explains how to work with OpenAPI 3.2 in ASP.NET Core, how to generate and inspect the document, and what to consider when an existing API moves from an older OpenAPI version.
What OpenAPI Does in an ASP.NET Core Application
Consider a simple ASP.NET Core endpoint:
app.MapGet("/api/products/{id:int}", (int id) =>
{
return Results.Ok(new Product(
id,
"Mechanical Keyboard",
129.99m));
});
public record Product(
int Id,
string Name,
decimal Price);A developer can understand this endpoint by reading the source code.
An external client, however, needs a machine-readable contract.
OpenAPI provides that contract:
ASP.NET Core API
|
v
OpenAPI document
|
+---- API documentation
|
+---- Client generation
|
+---- Testing tools
|
+---- Contract validation
|
+---- API discoveryThe OpenAPI document describes the API independently from the implementation language.
What Is OpenAPI 3.2?
OpenAPI versions define the structure and capabilities of the API description document.
An OpenAPI document begins with a version declaration:
openapi: 3.2.0
info:
title: Product API
version: 1.0.0
paths: {}The openapi field identifies the specification version.
The info section describes the API itself, while paths contains the available HTTP operations.
A simplified document looks like this:
openapi: 3.2.0
info:
title: Product API
version: 1.0.0
servers:
- url: https://api.example.com
paths:
/api/products:
get:
summary: Get products
responses:
"200":
description: Successful responseThis is the contract that tooling consumes.
OpenAPI Is Not Swagger
Swagger and OpenAPI are often used interchangeably, but they are not the same thing.
OpenAPI is the specification.
Swagger is a collection of tools that historically became closely associated with OpenAPI, including documentation and tooling.
In an ASP.NET Core project, you may encounter:
- OpenAPI document generation
- Swagger UI
- Scalar
- API client generators
- OpenAPI validators
- Contract testing tools
The specification is the important part.
The UI is only one way of consuming the document.
Generating OpenAPI From ASP.NET Core
Modern ASP.NET Core applications can generate OpenAPI documents through the framework's OpenAPI support.
A minimal API can start with:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();
app.MapOpenApi();
app.MapGet("/api/products/{id:int}", (int id) =>
{
return Results.Ok(new Product(
id,
"Mechanical Keyboard",
129.99m));
});
app.Run();
public record Product(
int Id,
string Name,
decimal Price);The important services are:
builder.Services.AddOpenApi();and:
app.MapOpenApi();The first registers OpenAPI document generation.
The second exposes the generated document through an HTTP endpoint.
The generated document can then be consumed by documentation and API tooling.
OpenAPI Document Version and ASP.NET Core Version Are Different
A common mistake is assuming that an ASP.NET Core application automatically produces the newest OpenAPI specification simply because the application uses a modern .NET SDK.
These are separate concerns.
The application framework controls how the API is implemented and how the OpenAPI document is generated.
The OpenAPI specification defines the format and semantics of that document.
Therefore, before changing the version declaration, verify that the generator actually supports the desired OpenAPI version.
Do not simply change:
openapi: 3.1.0to:
openapi: 3.2.0after generation and assume the document has become a valid OpenAPI 3.2 contract.
The generator needs to understand the target specification.
Adding API Metadata
A useful OpenAPI document should describe more than endpoint paths.
For example:
builder.Services.AddOpenApi(options =>
{
options.AddDocumentTransformer((document, context, cancellationToken) =>
{
document.Info.Title = "Product API";
document.Info.Description =
"HTTP API for managing product information.";
return Task.CompletedTask;
});
});This gives API consumers useful information without changing the application endpoints.
Good API metadata becomes especially important when the OpenAPI document is consumed by another team.
Describing Request and Response Models
Consider an endpoint that accepts a product request:
public record CreateProductRequest(
string Name,
decimal Price);The endpoint can use that model:
app.MapPost("/api/products",
(CreateProductRequest request) =>
{
var product = new Product(
1001,
request.Name,
request.Price);
return Results.Created(
$"/api/products/{product.Id}",
product);
});The OpenAPI generator can use the model information to describe the request body and response schema.
A client generator can then understand that the request contains:
{
"name": "Mechanical Keyboard",
"price": 129.99
}This is one of the main advantages of contract-driven API development.
Describing Validation Rules
Suppose the API requires a product name and a positive price.
You can model validation explicitly:
public record CreateProductRequest(
[property: Required] string Name,
[property: Range(0.01, 100000)] decimal Price);The generated API description can expose those constraints to consumers when the OpenAPI tooling supports the corresponding metadata.
This matters because validation should not exist only inside application code.
A consumer should be able to understand important request requirements from the API contract.
OpenAPI and Authentication
Authentication is another important part of an API contract.
For a bearer-token API, the OpenAPI document needs to describe the security scheme.
Conceptually:
components:
securitySchemes:
Bearer:
type: http
scheme: bearer
bearerFormat: JWTAn operation can then indicate that authentication is required:
security:
- Bearer: []This allows API documentation and client-generation tools to understand that requests need an authorization token.
The important distinction is that OpenAPI describes the security requirement. It does not implement authentication.
Your ASP.NET Core application still needs authentication middleware and authorization policies.
OpenAPI and Versioned APIs
Many production APIs have multiple versions.
For example:
/api/v1/products
/api/v2/productsThe OpenAPI document should make the versioning strategy clear.
If two API versions expose different request or response contracts, they should not be represented as though they were the same operation.
A useful structure is:
API
|
+-- v1 OpenAPI document
|
+-- v2 OpenAPI documentThis makes it easier for client teams to generate clients against a specific contract.
OpenAPI 3.2 and Webhooks
Webhooks are an important part of modern API design because applications increasingly need to notify other systems when something happens.
For example:
Order API
|
| Order completed
v
Webhook
|
v
Customer systemThe OpenAPI specification can describe webhook-related interactions.
That means the API contract does not have to describe only inbound HTTP requests. It can also document HTTP callbacks and event-driven integration patterns.
For systems that expose webhooks, keeping these contracts in the same API description can make integration easier to understand.
OpenAPI 3.2 and Modern HTTP APIs
OpenAPI has traditionally been strongest at describing request-response APIs.
Modern applications increasingly expose:
- Webhooks
- Callbacks
- Multiple content types
- Streaming-related endpoints
- Complex security requirements
- Event-driven integrations
OpenAPI 3.2 continues the specification's evolution toward describing these richer API behaviors.
For ASP.NET Core developers, the practical lesson is that an OpenAPI document should represent the actual HTTP contract instead of being treated as a generated list of URLs.
Validating the Generated Document
Do not assume that generated OpenAPI is correct simply because the application starts successfully.
The application can work while the generated contract contains incomplete or incorrect metadata.
A useful workflow is:
Build API
|
v
Generate OpenAPI
|
v
Validate document
|
v
Review breaking changes
|
v
Publish contractValidation should be part of the development or CI process when the OpenAPI document is used as a contract by other teams.
Common Problems
The Document Still Uses an Older OpenAPI Version
The generator may target a different specification version than the application expects.
Check the generated document rather than relying on assumptions.
Endpoints Are Missing
An endpoint may not appear because it is not discovered by the configured API description infrastructure.
Check route mapping, endpoint metadata, and the OpenAPI generator configuration.
Authentication Is Missing
Registering ASP.NET Core authentication does not automatically mean every detail appears in the OpenAPI document.
Security metadata needs to be represented correctly.
Validation Rules Are Not Visible
Not every validation mechanism automatically becomes an OpenAPI schema constraint.
If consumers depend on those constraints, verify the generated schema.
The OpenAPI Document Is Modified Manually
Avoid treating the generated document as a file that developers manually edit after every build.
Prefer generator configuration, metadata, transformers, or source-level API annotations where appropriate.
Best Practices
Keep the OpenAPI Contract Close to the API
The contract should be generated or maintained as part of the application development workflow.
Review Breaking Changes
Changing a response property, removing an endpoint, changing a required field, or altering an authentication requirement can break consumers.
Treat OpenAPI changes as API changes.
Generate Documentation From the Contract
Documentation tools should consume the same OpenAPI document used for validation and client generation.
This avoids having one API contract in source code and another in documentation.
Keep Internal Details Out of Public Schemas
Not every internal domain property belongs in a public API response.
Use dedicated request and response DTOs when necessary.
For example:
public record ProductResponse(
int Id,
string Name,
decimal Price);This is often safer than exposing an internal entity directly.
Advantages
- Provides a machine-readable API contract.
- Helps generate documentation and clients.
- Makes request and response structures explicit.
- Improves communication between API producers and consumers.
- Supports authentication and security metadata.
- Helps detect contract changes.
- Can describe webhooks and more complex API interactions.
Disadvantages
- Generated documentation can become inaccurate if metadata is incomplete.
- Large APIs can produce very large OpenAPI documents.
- Specification changes can require tooling updates.
- Not every implementation detail maps cleanly to OpenAPI.
- Poorly designed schemas can make generated clients difficult to use.
OpenAPI 3.2 vs Older OpenAPI Contracts
| Area | Older contract | OpenAPI 3.2 |
|---|---|---|
| Basic HTTP APIs | Supported | Supported |
| Request/response schemas | Supported | Supported |
| Security schemes | Supported | Supported |
| Webhooks | More limited depending on version | Improved support |
| Modern API description | Good | More expressive |
| Tooling compatibility | Very broad | Depends on tool version |
The important consideration is compatibility.
Before moving an existing API to a newer OpenAPI version, check the complete toolchain:
ASP.NET Core generator
|
v
OpenAPI document
|
v
Validator
|
v
Documentation tool
|
v
Client generatorIf one tool does not understand the newer specification, the migration can create unnecessary friction.
Summary
OpenAPI 3.2 gives ASP.NET Core developers a modern way to describe HTTP APIs and their surrounding integration contracts.
The biggest benefit is not the specification version itself. It is having a reliable machine-readable contract that can be used by developers, documentation systems, validation tools, and client generators.
When introducing OpenAPI 3.2, avoid changing only the version string. Verify that the ASP.NET Core OpenAPI generator and the tools consuming the document support the features you intend to use.
Keep request and response models explicit, document authentication requirements, validate generated contracts, and treat OpenAPI changes as part of API versioning and compatibility management.
A well-maintained OpenAPI document becomes part of the API itself. It gives developers a shared understanding of what the service accepts, what it returns, and how other systems are expected to integrate with it.


Join the conversation! Your thoughts help the community grow.