ForceInclude Metadata does not make it into the OpenApi plugin

Just upgraded to 6.0.2, and after regenerating some dtos, my service client dtos lost the GetAccessToken endpoint.

I read here about the ForceInclude option. That worked for getting it back into Metadata, but it’s now missing from OpenApi routes, and so I fail to pass validation, as seen here (https://apitools.dev/swagger-parser/online/)

image

How do we include it into the openapi end-point as well?

GetAccessToken is an explicitly excluded DTO that’s already exists in ServiceStack’s client libraries, e.g. C# ServiceStack.Client.dll, @servicestack/client js/typescript, etc.

What validation is this where it’s expected to exist?

This is taking my /openapi route and submitting it to a swagger validator, as Azure Api Management won’t proceed if the /openapi result does not pass validation.

The test for the fix would be to have the /openapi route pass validation still providing the GetAccessToken endpoint.

There’s no support in ServiceStack to add it, a temp workaround would be to use the Operation Filters to modify the Open Api response to add it.

I’ll look into it using ForceInclude to add it to /openapi as well.

Oh Nice! Can I get an example of what that Operation Filter should look like for this GetAccessToken route please?

Is there a helper function than can build the Definition by type?

There isn’t, you’d basically just try to replicate the JSON output by adding the C# classes which map 1:1 to the serialized json. During debug you can inspect the populated DTO to see how other APIs are populated.

The latest v6.0.3 on MyGet should now not ignore types defined in Metadata.ForceInclude.

Thank-you. I will test it out right now.

1 Like

So that seemed to work running against a validator :slight_smile:

I haven’t check Azure Api Management yet, because I now get a new issue which I assume has more to do with going from 6.0.2 => 6.0.3.

System.NotSupportedException: UserAuthRepositoryAsyncWrapper does not implement IManageApiKeys
     at ServiceStack.ApiKeyAuthProviderExtensions.AssertManageApiKeysAsync(ServiceStackHost appHost, IRequest req) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/ApiKeyAuthProvider.cs:line 548
     at ServiceStack.Auth.ApiKeyAuthProvider.Register(IAppHost appHost, AuthFeature feature) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/ApiKeyAuthProvider.cs:line 369

and

System.NotSupportedException: UserAuthRepositoryAsyncWrapper does not implement IManageApiKeys
     at ServiceStack.ApiKeyAuthProviderExtensions.AssertManageApiKeysAsync(ServiceStackHost appHost, IRequest req) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/ApiKeyAuthProvider.cs:line 548
     at ServiceStack.Auth.ApiKeyAuthProvider.GetApiKeyAsync(IRequest req, String apiKey) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/ApiKeyAuthProvider.cs:line 290
     at ServiceStack.Auth.ApiKeyAuthProvider.PreAuthenticateAsync(IRequest req, IResponse res) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/ApiKeyAuthProvider.cs:line 271
     at ServiceStack.AuthenticateAttribute.PreAuthenticateAsync(IRequest req, IEnumerable`1 authProviders) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/AuthenticateAttribute.cs:line 207
     at ServiceStack.AuthenticateAttribute.ExecuteAsync(IRequest req, IResponse res, Object requestDto) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/AuthenticateAttribute.cs:line 76
     at ServiceStack.ServiceStackHost.ApplyRequestFiltersSingleAsync(IRequest req, IResponse res, Object requestDto) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.Runtime.cs:line 180
     at ServiceStack.ServiceStackHost.ApplyRequestFiltersAsync(IRequest req, IResponse res, Object requestDto) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.Runtime.cs:line 144
     at ServiceStack.Host.Handlers.GenericHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Host/Handlers/GenericHandler.cs:line 56

Any ideas?

What Auth Repository are you using?

I’m using MongoDb w/ Jwt / ApiKey

Is this your own custom MongoDb AuthProvider? i.e. it’s not using the MongoDbAuthRepository built into ServiceStack?

Yes, I believe so, my partner set this up under a CentralizedAuthProvider, so it feeds all the downstream projects.

The issue is because it doesn’t implement IUserAuthRepositoryAsync or IManageApiKeysAsync (like ServiceStack’s built-in Auth Repos), I’ve added a change to try handle this, will let you know when it’s on MyGet.

Hopefully a workaround that handles this is now on MyGet v6.0.3.

Since you have v6.0.3 MyGet installed, you’ll need to clear your NuGet packages to download the latest v6.0.3 version:

https://docs.servicestack.net/myget#redownloading-myget-packages

Ok, that makes sense. Your fix will be the same as if I were to flush out and implement the two async versions? or in the end I’m still losing a little because it’s still resolving to my sync versions which are not fully async?

I’ll try to clear and test now. Thank-you :slight_smile:

As it doesn’t have an Async impl it uses a less efficient sync wrapper, but your Auth Provider would have always been synchronous either way.

To improve performance you can add an IUserAuthRepositoryAsync and IManageApiKeysAsync implementation to your Custom Auth Provider, since it looks like it was originally based on our it should be fairly easy to copy the necessary functionality from MongoDbAuthRepositoryAsync.cs

This one needs a double dash “–clear”, not the single dash “-clear”

Either should work, I’ve always used -clear. Do you have a version where it stopped working?

Using 6.0.101 I got:

C:\Dev>dotnet nuget locals all -clear
Specify --help for a list of available options and commands.
error: Unrecognized option ‘-clear’

Usage: dotnet nuget locals [arguments] [options]

Arguments:
Cache Location(s) Specifies the cache location(s) to list or clear.
<all | http-cache | global-packages | temp>

Options:
-h|–help Show help information
–force-english-output Forces the application to run using an invariant, English-based culture.
-c|–clear Clear the selected local resources or cache location(s).
-l|–list List the selected local resources or cache location(s).