Kevin Jump
04/19/2024, 12:32 PMOperationIdSelector
with something that checks for your api end point and then only applies that.
- replace umbracos in a build builder.Services.AddSingleton<IOperationIdSelector, MyOperationIdSelector>();
my convern here is that this isn't sustainable ?
if i register .AddSingleton<IOperationSelector, uSyncOperationSelector>
and then someone else comes along and reigsters .AddSingleton<IOperationSelector, SuperCustomIdSelector>
doesn't that mean that my customId selector will never then be used ?
---
I think (and i might be wrong) that what i should actually do, is only register my custom selector on the site i am using to generate my API from and not actually put it in the solution ? because as far as i can tell once the typescript files have been generated they are using the path not the id, so it doesn't matter ?Kevin Jump
04/19/2024, 12:48 PMWarren Buckley
04/19/2024, 1:01 PMJacob Overgaard
04/19/2024, 2:05 PMWarren Buckley
04/20/2024, 4:30 PMIOperationSelector
can you not do something like this instead @Kevin Jump ?
csharp
builder.Services.Configure<SwaggerGenOptions>(opt =>
{
// Configure the Swagger generation options
// Add in a new Swagger API document solely for our own package that can be browsed via Swagger UI
// Along with having a generated swagger JSON file that we can use to auto generate a TypeScript client
opt.SwaggerDoc("AccessibilityReporter", new OpenApiInfo
{
Title = "Accessibility Reporter Package API",
Version = "1.0"
});
// https://docs.umbraco.com/umbraco-cms/v/14.latest-beta/reference/custom-swagger-api
// PR: https://github.com/umbraco/Umbraco-CMS/pull/15699
opt.OperationFilter<MyBackOfficeSecurityRequirementsOperationFilter>();
// Rather than very verbose names from generated TS client, we simplify them a bit
// https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/README.md#operation-filters
// https://docs.umbraco.com/umbraco-cms/reference/api-versioning-and-openapi#adding-custom-operation-ids
// https://g-mariano.medium.com/generate-readable-apis-clients-by-setting-unique-and-meaningful-operationid-in-swagger-63d404f32ff8
opt.CustomOperationIds(apiDesc => $"{apiDesc.ActionDescriptor.RouteValues["action"]}");
});
Warren Buckley
04/20/2024, 4:31 PMKevin Jump
04/20/2024, 6:06 PMKevin Jump
04/20/2024, 6:06 PMWarren Buckley
04/20/2024, 7:27 PMWarren Buckley
04/20/2024, 7:28 PMWarren Buckley
04/20/2024, 7:55 PMSwashbuckle.AspNetCore.Annotations
nuget package
https://github.com/domaindrivendev/Swashbuckle.AspNetCore?tab=readme-ov-file#enrich-operation-metadata
csharp
[HttpPost]
[SwaggerOperation(
Summary = "Creates a new product",
Description = "Requires admin privileges",
OperationId = "CreateProduct",
Tags = new[] { "Purchase", "Products" }
)]
public IActionResult Create([FromBody]Product product)
Warren Buckley
04/20/2024, 8:27 PMWarren Buckley
04/20/2024, 8:49 PMWarren Buckley
04/20/2024, 8:56 PMKevin Jump
04/20/2024, 8:59 PMKevin Jump
04/20/2024, 9:00 PMWarren Buckley
04/21/2024, 8:30 AM