Exemplo n.º 1
0
        internal ISwaggerProvider GetSwaggerProvider(HttpRequestMessage swaggerRequest)
        {
            HttpConfiguration configuration = HttpRequestMessageExtensions.GetConfiguration(swaggerRequest);
            Dictionary <string, SecurityScheme> dictionary = this._securitySchemeBuilders.Any <KeyValuePair <string, SecuritySchemeBuilder> >() ? this._securitySchemeBuilders.ToDictionary <KeyValuePair <string, SecuritySchemeBuilder>, string, SecurityScheme>((Func <KeyValuePair <string, SecuritySchemeBuilder>, string>)(kvp => kvp.Key), (Func <KeyValuePair <string, SecuritySchemeBuilder>, SecurityScheme>)(kvp => kvp.Value.Build())) : (Dictionary <string, SecurityScheme>)null;
            List <IModelFilter>     list1 = this._modelFilters.Select <Func <IModelFilter>, IModelFilter>((Func <Func <IModelFilter>, IModelFilter>)(factory => factory())).ToList <IModelFilter>();
            List <IOperationFilter> list2 = this._operationFilters.Select <Func <IOperationFilter>, IOperationFilter>((Func <Func <IOperationFilter>, IOperationFilter>)(factory => factory())).ToList <IOperationFilter>();

            foreach (Func <XPathDocument> xmlDocFactory in (IEnumerable <Func <XPathDocument> >) this._xmlDocFactories)
            {
                XPathDocument xmlDoc = xmlDocFactory();
                list1.Insert(0, (IModelFilter) new ApplyXmlTypeComments(xmlDoc));
                list2.Insert(0, (IOperationFilter) new ApplyXmlActionComments(xmlDoc));
            }
            SwaggerGeneratorOptions options          = new SwaggerGeneratorOptions(this._versionSupportResolver, this._schemes, (IDictionary <string, SecurityScheme>)dictionary, this._ignoreObsoleteActions, this._groupingKeySelector, this._groupingKeyComparer, this._customSchemaMappings, (IEnumerable <ISchemaFilter>) this._schemaFilters.Select <Func <ISchemaFilter>, ISchemaFilter>((Func <Func <ISchemaFilter>, ISchemaFilter>)(factory => factory())).ToList <ISchemaFilter>(), (IEnumerable <IModelFilter>)list1, this._ignoreObsoleteProperties, this._schemaIdSelector, this._describeAllEnumsAsStrings, this._describeStringEnumsInCamelCase, this._applyFiltersToAllSchemas, (IEnumerable <IOperationFilter>)list2, (IEnumerable <IDocumentFilter>) this._documentFilters.Select <Func <IDocumentFilter>, IDocumentFilter>((Func <Func <IDocumentFilter>, IDocumentFilter>)(factory => factory())).ToList <IDocumentFilter>(), this._conflictingActionsResolver);
            SwaggerGenerator        swaggerGenerator = new SwaggerGenerator(ServicesExtensions.GetApiExplorer(configuration.get_Services()), configuration.SerializerSettingsOrDefault(), this._versionInfoBuilder.Build(), options);

            if (this._customProviderFactory == null)
            {
                return((ISwaggerProvider)swaggerGenerator);
            }
            return(this._customProviderFactory((ISwaggerProvider)swaggerGenerator));
        }
Exemplo n.º 2
0
        private HttpContent ContentFor(
            HttpRequestMessage request,
            SwaggerDocument swaggerDoc)
        {
            ContentNegotiationResult negotiationResult = ServicesExtensions.GetContentNegotiator(HttpRequestMessageExtensions.GetConfiguration(request).get_Services()).Negotiate(typeof(SwaggerDocument), request, this.GetSupportedSwaggerFormatters());

            return((HttpContent) new ObjectContent(typeof(SwaggerDocument), (object)swaggerDoc, negotiationResult.get_Formatter(), negotiationResult.get_MediaType()));
        }
Exemplo n.º 3
0
 public static string DefaultRootUrlResolver(HttpRequestMessage request)
 {
     return(new UriBuilder(SwaggerDocsConfig.GetHeaderValue(request, "X-Forwarded-Proto") ?? request.RequestUri.Scheme, SwaggerDocsConfig.GetHeaderValue(request, "X-Forwarded-Host") ?? request.RequestUri.Host, int.Parse(SwaggerDocsConfig.GetHeaderValue(request, "X-Forwarded-Port") ?? request.RequestUri.Port.ToString((IFormatProvider)CultureInfo.InvariantCulture)), (SwaggerDocsConfig.GetHeaderValue(request, "X-Forwarded-Prefix") ?? string.Empty) + HttpRequestMessageExtensions.GetConfiguration(request).get_VirtualPathRoot()).Uri.AbsoluteUri.TrimEnd('/'));
 }