API-Designer: Duplicate operationIds in the swagger definition

When we define API methods like

builder.AddMethod(Method.Define("obj").HandleGet(qr => "list of objs"));
builder.AddMethod(Method.Define("obj/{id}").WithParameter("id", isInQuery: false).HandleGet(qr => "single obj"));

we encounter the error message (while compiling):

Duplicate operationIds in the swagger definition
	at VI.ApiDesigner.CodeGen.SwaggerGen.<DoAsync>d__4.MoveNext()
	at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
	at CompositionApiToSwagger.SwaggerDocumentContainer.<CreateAsync>d__7.MoveNext()
	at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
	at CompositionApiToSwagger.SwaggerDocumentContainer.<AddRoutesAsync>d__9.MoveNext()

I tried to remove the first definition and treat the empty id inside the handler - but then the "empty" call "/obj/" does not exists anymore (404) - even with an arbitrary default value. So I think this is broken.

Is there another way to define the methods as described (even swagger defines that as best practice https://swagger.io/resources/articles/best-practices-in-api-design/ ) - so I think the error comes from a step before.

Parents Reply Children
  • Thanks for sorting things out. So I have to wait until we can update.

    The latter part with NSwag is not that clear to me. The operation ID has to be unique for every endpoint. By not using the parameters at all and ignoring fixed parts between first and last parameter ("b" in "a/{x}/b/{y}"), you get (unsolvable) ambiguities with surprising ease and this actively prevents writing a clear/conventional api.