private void SetRequestModelExamples(Operation operation, OperationFilterContext context) { var actionAttributes = context.MethodInfo.GetCustomAttributes <SwaggerRequestExampleAttribute>(); foreach (var attr in actionAttributes) { var examplesProvider = (IExamplesProvider)(serviceProvider.GetService(attr.ExamplesProviderType) ?? Activator.CreateInstance(attr.ExamplesProviderType)); object example = examplesProvider?.GetExamples(); requestExample.SetRequestExampleForType(operation, context.SchemaRegistry, attr.RequestType, example, attr.ContractResolver, attr.JsonConverter); } }
private void SetRequestExamples(Operation operation, OperationFilterContext context) { var actionAttributes = context.MethodInfo.GetCustomAttributes <SwaggerRequestExampleAttribute>(); foreach (var parameterDescription in context.ApiDescription.ParameterDescriptions) { if (actionAttributes.Any(a => a.RequestType == parameterDescription.Type)) { continue; // if [SwaggerRequestExample] is defined, then let ExamplesOperationFilter define the example } var example = GetExampleForTypeFromServiceProvider(parameterDescription.Type); requestExample.SetRequestExampleForType(operation, context.SchemaRegistry, parameterDescription.Type, example); } }