Skip to content

Add support for copy constructors to Microsoft.OpenApi.Models objects #832

Closed
@captainsafia

Description

@captainsafia

As outlined in dotnet/aspnetcore#40676 and implemented in dotnet/aspnetcore#41238, we're introducing support for a new Microsoft.AspNetCore.OpenApi package that acts as a link between Microsoft.OpenApi and route handler endpoints.

This package exposes a WithOpenApi extension method that users can invoke on their endpoints to mutate the OpenApiOperation that we generate by default from the handler's MethodInfo with their own annotation. For example,

app.MapGet("/foo", () => {})
.WithOpenApi(generatedOperation => {
  generatedOperation.OperationId = "MadeByMe";
  return generatedOperation;
});

One of the things we thought would be compelling was support for a copy constructor for OpenApiOperation so that users can invoke the following and have their modification automatically merged into the generated operation.

app.MapGet("/foo", () => {})
.WithOpenApi(generatedOperation => new(generatedOperation) {
  OperationId = "MadeByMe"
});

Metadata

Metadata

Assignees

Labels

priority:p1High priority but not blocking. Causes major but not critical loss of functionality SLA <=7daystype:enhancementEnhancement request targeting an existing experience

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions