We are using ASPNet Zero (Angular + .Net Core) v11.1
We have tried to hide endpoints from Swagger by using [ApiExplorerSettings(IgnoreApi = true)], [RemoteService(false)] attributes. They do remove the endpoints from swagger but the enpoints themselves no longer exist while calling via the appservices or methods from typscript. We also tried creating a custom attribute [ShowSwagger] but ended up with the same problem.
Another possible solution:
We would like the swagger/v1/swagger.json
endpoint to behave differently depending on whether we are in development or production. When in development, we want all endpoints to be visible so that NSwag can build the service proxies correctly. When in production, we only want the customer-facing endpoints visible. It's possible that this can be achieved with a custom DocumentFilter?
Thank you.
1 Answer(s)
-
0
Hi @conorcorr
Yes, you can create a custom DocumentFilter and achieve this. A sample document filter would be something like this;
public class SwaggerDocumentFilter : IDocumentFilter { public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { swaggerDoc.Paths .Where(x => x.Key.Contains("/part-of-endpoint") || ) .ToList() .ForEach(x => swaggerDoc.Paths.Remove(x.Key)); } }