private Schema CreateObjectSchema(JsonObjectContract jsonContract) { var properties = jsonContract.Properties .Where(p => !p.Ignored) .Where(p => !(_options.IgnoreObsoleteProperties && p.IsObsolete())) .ToDictionary( prop => prop.PropertyName, prop => CreateSchema(prop.PropertyType, true).AssignValidationProperties(prop) ); var required = jsonContract.Properties.Where(prop => prop.IsRequired()) .Select(propInfo => propInfo.PropertyName) .ToList(); var schema = new Schema { Required = required.Any() ? required : null, // required can be null but not empty Properties = properties, Type = "object" }; var filterContext = new ModelFilterContext( jsonContract.UnderlyingType, jsonContract, this); foreach (var filter in _options.ModelFilters) { filter.Apply(schema, filterContext); } return(schema); }
public void Apply(Schema model, ModelFilterContext context) { _logger.LogInformation("Applying an awesome IModelFilter that leverages Dependency Injection"); model.Default = new { Id = "myCartId" }; }
public void Apply(Schema model, ModelFilterContext context) { var typeInfo = context.SystemType.GetTypeInfo(); var attributes = typeInfo.GetCustomAttributes(false).OfType<SwaggerModelFilterAttribute>(); foreach (var attr in attributes) { var filter = (IModelFilter)ActivatorUtilities.CreateInstance(_serviceProvider, attr.Type, attr.Arguments); filter.Apply(model, context); } }
public void Apply(Schema model, ModelFilterContext context) { var commentId = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType); var typeNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, commentId)); if (typeNode != null) { var summaryNode = typeNode.SelectSingleNode(SummaryTag); if (summaryNode != null) model.Description = summaryNode.ExtractContent(); } foreach (var entry in model.Properties) { var jsonProperty = context.JsonObjectContract.Properties[entry.Key]; if (jsonProperty == null) continue; ApplyPropertyComments(entry.Value, jsonProperty.PropertyInfo()); } }
public void Apply(Schema model, ModelFilterContext context) { var typeXPath = string.Format(TypeExpression, context.SystemType.XmlLookupName()); var typeNode = _xmlNavigator.SelectSingleNode(typeXPath); if (typeNode != null) { var summaryNode = typeNode.SelectSingleNode(SummaryExpression); if (summaryNode != null) model.Description = summaryNode.ExtractContent(); } foreach (var entry in model.Properties) { var jsonProperty = context.JsonObjectContract.Properties[entry.Key]; if (jsonProperty == null) continue; ApplyPropertyComments(entry.Value, jsonProperty.PropertyInfo()); } }
private Schema CreateObjectSchema(JsonObjectContract jsonContract) { var properties = jsonContract.Properties .Where(p => !p.Ignored) .Where(p => !(_options.IgnoreObsoleteProperties && p.IsObsolete())) .ToDictionary( prop => prop.PropertyName, prop => CreateSchema(prop.PropertyType, true).AssignValidationProperties(prop) ); var required = jsonContract.Properties.Where(prop => prop.IsRequired()) .Select(propInfo => propInfo.PropertyName) .ToList(); var schema = new Schema { Required = required.Any() ? required : null, // required can be null but not empty Properties = properties, Type = "object" }; var filterContext = new ModelFilterContext( jsonContract.UnderlyingType, jsonContract, this); foreach (var filter in _options.ModelFilters) { filter.Apply(schema, filterContext); } return schema; }
public void Apply(Schema model, ModelFilterContext context) { model.Extensions.Add("X-property1", "value"); }