public OpenApiCompilerConfiguration(OpenApiConfiguration configuration)
        {
            foreach (var documentFilterFactory in configuration.DocumentFilterFactories)
            {
                DocumentFilters.Add(documentFilterFactory());
            }

            foreach (var operationFilterFactory in configuration.OperationFilterFactories)
            {
                OperationFilters.Add(operationFilterFactory());
            }

            foreach (var parameterFilterFactory in configuration.ParameterFilterFactories)
            {
                ParameterFilters.Add(parameterFilterFactory());
            }

            foreach (var schemaFilterFactory in configuration.SchemaFilterFactories)
            {
                SchemaFilters.Add(schemaFilterFactory());
            }

            foreach (var xmlDocFactory in configuration.XmlDocFactories)
            {
                SchemaFilters.Add(new OpenApiXmlCommentsSchemaFilter(xmlDocFactory()));
            }

            SchemaIdSelector = configuration.SchemaIdSelector;
            if (SchemaIdSelector == null)
            {
                SchemaIdSelector = type =>
                {
                    var typeName = type.GetAttributeValue((DataContractAttribute attribute) => attribute.Name) ?? type.FriendlyId();
                    return(typeName.SanitizeClassName());
                };
            }
        }
Exemplo n.º 2
0
 public void OperationFilter <TFilter>(TFilter filter)
     where TFilter : IOperationFilter, new()
 {
     OperationFilters.Add(filter);
 }
 public void OperationFilter <TFilter>()
     where TFilter : IOperationFilter, new()
 {
     OperationFilters.Add(new TFilter());
 }
Exemplo n.º 4
0
 public SwaggerSpecConfig OperationFilter(IOperationFilter operationFilter)
 {
     OperationFilters.Add(operationFilter);
     return(this);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Add operation filter action
 /// </summary>
 /// <param name="filterAction"></param>
 public void AddOperationFilter(Action <OperationFilterContext> filterAction) =>
 OperationFilters.Add(new OperationFilterFunc(filterAction));
Exemplo n.º 6
0
        public OpenApiCompilerConfiguration(OpenApiConfiguration configuration)
        {
            foreach (var documentFilterFactory in configuration.DocumentFilterFactories)
            {
                DocumentFilters.Add(documentFilterFactory());
            }

            foreach (var reDocDocumentFilterFactory in configuration.ReDocDocumentFilterFactories)
            {
                ReDocDocumentFilters.Add(reDocDocumentFilterFactory());
            }

            foreach (var injectedExtensions in configuration.InjectedExtensions)
            {
                DocumentFilters.Add(new OpenApiExtensionInjectingDocumentFilter(injectedExtensions.resourceAssembly, injectedExtensions.resourceName, injectedExtensions.documentRoute));
            }

            foreach (var reDocInjectedExtensions in configuration.ReDocInjectedExtensions)
            {
                ReDocDocumentFilters.Add(new OpenApiExtensionInjectingDocumentFilter(reDocInjectedExtensions.resourceAssembly, reDocInjectedExtensions.resourceName, reDocInjectedExtensions.documentRoute));
            }

            foreach (var injectedTags in configuration.InjectedTags)
            {
                DocumentFilters.Add(new OpenApiTagInjectingDocumentFilter(injectedTags.resourceAssembly, injectedTags.resourceName, injectedTags.documentRoute));
            }

            foreach (var reDocInjectedTags in configuration.ReDocInjectedTags)
            {
                ReDocDocumentFilters.Add(new OpenApiTagInjectingDocumentFilter(reDocInjectedTags.resourceAssembly, reDocInjectedTags.resourceName, reDocInjectedTags.documentRoute));
            }

            foreach (var operationFilterFactory in configuration.OperationFilterFactories)
            {
                OperationFilters.Add(operationFilterFactory());
            }

            foreach (var parameterFilterFactory in configuration.ParameterFilterFactories)
            {
                ParameterFilters.Add(parameterFilterFactory());
            }

            foreach (var schemaFilterFactory in configuration.SchemaFilterFactories)
            {
                SchemaFilters.Add(schemaFilterFactory());
            }

            foreach (var xmlDocFactory in configuration.XmlDocFactories)
            {
                SchemaFilters.Add(new OpenApiXmlCommentsSchemaFilter(xmlDocFactory()));
            }

            SchemaIdSelector = configuration.SchemaIdSelector;
            if (SchemaIdSelector == null)
            {
                SchemaIdSelector = type =>
                {
                    var typeName = type.GetAttributeValue((DataContractAttribute attribute) => attribute.Name) ?? type.FriendlyId();
                    return(typeName.SanitizeClassName());
                };
            }
        }