Example #1
0
        internal ISwaggerProvider CreateSwaggerProvider(IServiceProvider serviceProvider)
        {
            var swaggerGeneratorSettings = CreateSwaggerGeneratorSettings(serviceProvider);
            var schemaRegistrySettings   = CreateSchemaRegistrySettings(serviceProvider);

            // Instantiate & add the XML comments filters here so they're executed before any custom
            // filters AND so they can share the same XPathDocument (perf. optimization)
            foreach (var xmlDocFactory in _xmlDocFactories)
            {
                var xmlDoc = xmlDocFactory();
                schemaRegistrySettings.SchemaFilters.Insert(0, new XmlCommentsSchemaFilter(xmlDoc));
                swaggerGeneratorSettings.OperationFilters.Insert(0, new XmlCommentsOperationFilter(xmlDoc));

                if (_includeControllerXmlComments)
                {
                    swaggerGeneratorSettings.DocumentFilters.Insert(0, new XmlCommentsDocumentFilter(xmlDoc));
                }
            }

            var schemaRegistryFactory = new SchemaRegistryFactory(
                serviceProvider.GetRequiredService <IOptions <MvcJsonOptions> >().Value.SerializerSettings,
                schemaRegistrySettings
                );

            return(new SwaggerGenerator(
                       serviceProvider.GetRequiredService <IApiDescriptionGroupCollectionProvider>(),
                       schemaRegistryFactory,
                       swaggerGeneratorSettings
                       ));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SchemaRegistryFactory"/> class.
        /// </summary>
        /// <param name="mvcJsonOptionsAccessor"><see cref="IOptions{T}">Options</see> for <see cref="MvcJsonOptions"/>.</param>
        /// <param name="schemaRegistryOptionsAccessor"><see cref="IOptions{T}">Options</see> for <see cref="SchemaRegistryOptions"/>.</param>
        /// <param name="schemaProviders"><see cref="IInstancesOf{T}"/> of <see cref="ICanProvideSwaggerSchemas"/>.</param>
        public SchemaRegistryFactory(
            IOptions <MvcJsonOptions> mvcJsonOptionsAccessor,
            IOptions <SchemaRegistryOptions> schemaRegistryOptionsAccessor,
            IInstancesOf <ICanProvideSwaggerSchemas> schemaProviders)
        {
            _jsonSerializerSettings = mvcJsonOptionsAccessor.Value.SerializerSettings;
            _schemaRegistryOptions  = schemaRegistryOptionsAccessor.Value;
            _schemaProviders        = schemaProviders;

            _originalFactory = new OriginalSchemaRegistryFactory(_jsonSerializerSettings, _schemaRegistryOptions);
        }