Example #1
0
        public static Dictionary <string, SecurityScheme> GetSecurityDefinitions(this SwaggerDocsConfig swaggerDocsConfig)
        {
            var securitySchemeBuilders = swaggerDocsConfig.GetFieldValue <IDictionary <string, SecuritySchemeBuilder> >("_securitySchemeBuilders");

            return(securitySchemeBuilders != null && securitySchemeBuilders.Any()
                ? securitySchemeBuilders.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.InvokeFunction <SecurityScheme>("Build"))
                : new Dictionary <string, SecurityScheme>());
        }
Example #2
0
        internal SwashbuckleOptions GetSwashbuckleOptions()
        {
            AddGlobalDocumentFilters();
            AddODataDocumentFilters();

            var swaggerProviderOptions = new SwaggerProviderOptions(
                _swaggerDocsConfig.GetFieldValue <Func <ApiDescription, string, bool> >("_versionSupportResolver"),
                _swaggerDocsConfig.GetFieldValue <IEnumerable <string> >("_schemes"),
                _swaggerDocsConfig.GetSecurityDefinitions(),
                _swaggerDocsConfig.GetFieldValue <bool>("_ignoreObsoleteActions"),
                _swaggerDocsConfig.GetFieldValue <Func <ApiDescription, string> >("_groupingKeySelector"),
                _swaggerDocsConfig.GetFieldValue <IComparer <string> >("_groupingKeyComparer"),
                GetODataCustomSchemaMappings(),
                _swaggerDocsConfig.GetFieldValue <IEnumerable <Func <ISchemaFilter> > >("_schemaFilters", true).Select(factory => factory()),
                _swaggerDocsConfig.GetFieldValue <IList <Func <IModelFilter> > >("_modelFilters", true).Select(factory => factory()).ToList(),
                _swaggerDocsConfig.GetFieldValue <bool>("_ignoreObsoleteProperties"),
                _swaggerDocsConfig.GetFieldValue <Func <Type, string> >("_schemaIdSelector"),
                _swaggerDocsConfig.GetFieldValue <bool>("_describeAllEnumsAsStrings"),
                _swaggerDocsConfig.GetFieldValue <bool>("_describeStringEnumsInCamelCase"),
                GetODataOperationFilters(),
                GetODataDocumentFilters(),
                _swaggerDocsConfig.GetFieldValue <Func <IEnumerable <ApiDescription>, ApiDescription> >("_conflictingActionsResolver"),
                _swaggerDocsConfig.GetFieldValue <bool>("_applyFiltersToAllSchemas"),
                _swaggerDocsConfig.GetFieldValue <IEnumerable <Func <XPathDocument> > >("_xmlDocFactories").Select(factory => factory).ToList()
                );

            return(new SwashbuckleOptions(swaggerProviderOptions));
        }
        public static SwaggerProviderOptions GetSwaggerProviderOptions(SwaggerDocsConfig swaggerDocsConfig)
        {
            Contract.Requires(swaggerDocsConfig != null);

            AddGlobalDocumentFilters(swaggerDocsConfig);

            return new SwaggerProviderOptions(
                swaggerDocsConfig.GetFieldValue<Func<ApiDescription, string, bool>>("_versionSupportResolver"),
                swaggerDocsConfig.GetFieldValue<IEnumerable<string>>("_schemes"),
                swaggerDocsConfig.GetSecurityDefinitions(),
                swaggerDocsConfig.GetFieldValue<bool>("_ignoreObsoleteActions"),
                swaggerDocsConfig.GetFieldValue<Func<ApiDescription, string>>("_groupingKeySelector"),
                swaggerDocsConfig.GetFieldValue<IComparer<string>>("_groupingKeyComparer"),
                GetODataCustomSchemaMappings(swaggerDocsConfig),
                swaggerDocsConfig.GetFieldValue<IList<Func<ISchemaFilter>>>("_schemaFilters", true).Select(factory => factory()),
                swaggerDocsConfig.GetFieldValue<IList<Func<IModelFilter>>>("_modelFilters", true).Select(factory => factory()),
                swaggerDocsConfig.GetFieldValue<bool>("_ignoreObsoleteProperties"),
                swaggerDocsConfig.GetFieldValue<Func<Type, string>>("_schemaIdSelector"),
                swaggerDocsConfig.GetFieldValue<bool>("_describeAllEnumsAsStrings"),
                swaggerDocsConfig.GetFieldValue<bool>("_describeStringEnumsInCamelCase"),
                GetODataOperationFilters(swaggerDocsConfig),
                GetODataDocumentFilters(swaggerDocsConfig),
                swaggerDocsConfig.GetFieldValue<Func<IEnumerable<ApiDescription>, ApiDescription>>("_conflictingActionsResolver")
            );
        }
 /// <summary>
 /// Gets custom schema mappings that will only be applied to OData operations.
 /// </summary>
 /// <param name="swaggerDocsConfig">The swagger docs configuration.</param>
 /// <returns></returns>
 private static IDictionary<Type, Func<Schema>> GetODataCustomSchemaMappings(SwaggerDocsConfig swaggerDocsConfig)
 {
     var customSchemaMappings = swaggerDocsConfig.GetFieldValue<IDictionary<Type, Func<Schema>>>("_customSchemaMappings", true);
     customSchemaMappings[typeof(decimal)] = () => new Schema { type = "number", format = "decimal" };
     return customSchemaMappings;
 }
        /// <summary>
        /// Gets the API versions. I'd rather not use reflection because the implementation may change, but can't find a better way.
        /// </summary>
        /// <param name="swaggerDocsConfig">The swagger docs configuration.</param>
        /// <returns></returns>
        public static IDictionary<string, Info> GetApiVersions(SwaggerDocsConfig swaggerDocsConfig)
        {
            Contract.Requires(swaggerDocsConfig != null);

            return swaggerDocsConfig.GetFieldValue<VersionInfoBuilder>("_versionInfoBuilder", true).Build();
        }
 /// <summary>
 /// Gets document filters that will only be applied to the SwaggerDocument built from the OData ApiExplorer.
 /// </summary>
 /// <param name="swaggerDocsConfig">The swagger docs configuration.</param>
 private static IEnumerable<IDocumentFilter> GetODataDocumentFilters(SwaggerDocsConfig swaggerDocsConfig)
 {
     return swaggerDocsConfig.GetFieldValue<IList<Func<IDocumentFilter>>>("_documentFilters", true)
         .Select(factory => factory())
         .Concat(new LimitSchemaGraphToTopLevelEntity());
 }
 /// <summary>
 /// Gets operation filters that will only be applied to OData operations.
 /// </summary>
 /// <param name="swaggerDocsConfig">The swagger docs configuration.</param>
 private static IEnumerable<IOperationFilter> GetODataOperationFilters(SwaggerDocsConfig swaggerDocsConfig)
 {
     return swaggerDocsConfig.GetFieldValue<IList<Func<IOperationFilter>>>("_operationFilters", true)
         .Select(factory => factory())
         .Concat(new EnableQueryFilter());
 }
        public static SwaggerProviderOptions GetSwaggerProviderOptions(SwaggerDocsConfig swaggerDocsConfig)
        {
            Contract.Requires(swaggerDocsConfig != null);

            AddInternalDocumentFilters(swaggerDocsConfig);
            AddInternalOperationFilters(swaggerDocsConfig);

            return(new SwaggerProviderOptions(
                       swaggerDocsConfig.GetFieldValue <Func <ApiDescription, string, bool> >("_versionSupportResolver"),
                       swaggerDocsConfig.GetFieldValue <IEnumerable <string> >("_schemes"),
                       swaggerDocsConfig.GetSecurityDefinitions(),
                       swaggerDocsConfig.GetFieldValue <bool>("_ignoreObsoleteActions"),
                       swaggerDocsConfig.GetFieldValue <Func <ApiDescription, string> >("_groupingKeySelector"),
                       swaggerDocsConfig.GetFieldValue <IComparer <string> >("_groupingKeyComparer"),
                       swaggerDocsConfig.GetFieldValue <IDictionary <Type, Func <Schema> > >("_customSchemaMappings"),
                       swaggerDocsConfig.GetFieldValue <IList <Func <ISchemaFilter> > >("_schemaFilters", true).Select(factory => factory()),
                       swaggerDocsConfig.GetFieldValue <IList <Func <IModelFilter> > >("_modelFilters", true).Select(factory => factory()),
                       swaggerDocsConfig.GetFieldValue <bool>("_ignoreObsoleteProperties"),
                       swaggerDocsConfig.GetFieldValue <Func <Type, string> >("_schemaIdSelector"),
                       swaggerDocsConfig.GetFieldValue <bool>("_describeAllEnumsAsStrings"),
                       swaggerDocsConfig.GetFieldValue <bool>("_describeStringEnumsInCamelCase"),
                       swaggerDocsConfig.GetFieldValue <IList <Func <IOperationFilter> > >("_operationFilters", true).Select(factory => factory()),
                       swaggerDocsConfig.GetFieldValue <IList <Func <IDocumentFilter> > >("_documentFilters", true).Select(factory => factory()),
                       swaggerDocsConfig.GetFieldValue <Func <IEnumerable <ApiDescription>, ApiDescription> >("_conflictingActionsResolver")
                       ));
        }
        /// <summary>
        /// Gets the API versions. I'd rather not use reflection because the implementation may change, but can't find a better way.
        /// </summary>
        /// <param name="swaggerDocsConfig">The swagger docs configuration.</param>
        /// <returns></returns>
        public static IDictionary <string, Info> GetApiVersions(SwaggerDocsConfig swaggerDocsConfig)
        {
            Contract.Requires(swaggerDocsConfig != null);

            return(swaggerDocsConfig.GetFieldValue <VersionInfoBuilder>("_versionInfoBuilder", true).Build());
        }