Skip to content

Commit

Permalink
Add IgnoreRequest to OpenApiFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed May 21, 2024
1 parent 2baacee commit 60e57f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ServiceStack/src/ServiceStack.Api.OpenApi/OpenApiFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class OpenApiFeature : IPlugin, IPreInitPlugin, Model.IHasStringId

public Dictionary<string, List<string>> OperationSecurity { get; set; }

public Func<Type, bool> IgnoreRequest { get; set; } = _ => false;

public bool UseBearerSecurity
{
set
Expand Down Expand Up @@ -124,6 +126,7 @@ public void Register(IAppHost appHost)
OpenApiService.InlineSchemaTypesInNamespaces = InlineSchemaTypesInNamespaces.ToArray();
OpenApiService.SecurityDefinitions = SecurityDefinitions;
OpenApiService.OperationSecurity = OperationSecurity;
OpenApiService.IgnoreRequest = IgnoreRequest;

appHost.RegisterService(typeof(OpenApiService), "/openapi");

Expand Down
6 changes: 4 additions & 2 deletions ServiceStack/src/ServiceStack.Api.OpenApi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class OpenApiService : Service
internal static Action<OpenApiProperty> SchemaPropertyFilter { get; set; }
internal static string[] AnyRouteVerbs { get; set; }
internal static string[] InlineSchemaTypesInNamespaces { get; set; }
internal static Func<Type, bool> IgnoreRequest { get; set; }

public static Dictionary<string, OpenApiSecuritySchema> SecurityDefinitions { get; set; }
public static Dictionary<string, List<string>> OperationSecurity { get; set; }
Expand Down Expand Up @@ -489,6 +490,7 @@ protected bool IsInlineSchema(Type schemaType)

private void ParseDefinitions(IDictionary<string, OpenApiSchema> schemas, Type schemaType, string route, string verb)
{
if (IgnoreRequest(schemaType)) return;
if (IsSwaggerScalarType(schemaType) || schemaType.ExcludesFeature(Feature.Metadata)) return;

var schemaId = GetSchemaDefinitionRef(schemaType);
Expand Down Expand Up @@ -556,7 +558,7 @@ private void ParseDefinitions(IDictionary<string, OpenApiSchema> schemas, Type s
var apiDoc = apiMembers
.Where(attr => string.IsNullOrEmpty(verb) || string.IsNullOrEmpty(attr.Verb) || (verb ?? "").Equals(attr.Verb))
.Where(attr => string.IsNullOrEmpty(route) || string.IsNullOrEmpty(attr.Route) || (route ?? "").StartsWith(attr.Route))
.FirstOrDefault(attr => attr.ParameterType == "body" || attr.ParameterType == "model");
.FirstOrDefault(attr => attr.ParameterType is "body" or "model");

if (apiMembers.Any(x => x.ExcludeInSchema))
continue;
Expand All @@ -576,7 +578,7 @@ private void ParseDefinitions(IDictionary<string, OpenApiSchema> schemas, Type s

if (propAttr.IsRequired)
{
schema.Required ??= new List<string>();
schema.Required ??= [];
schema.Required.Add(schemaPropertyName);
}
}
Expand Down

0 comments on commit 60e57f7

Please sign in to comment.