コード例 #1
0
        private HttpContent ContentFor(HttpRequestMessage request, SwaggerDocument swaggerDoc, SwaggerGeneratorOptions options)
        {
            var negotiator = request.GetConfiguration().Services.GetContentNegotiator();
            var result = negotiator.Negotiate(typeof(SwaggerDocument), request, GetSupportedSwaggerFormatters(options));

            return new ObjectContent(typeof(SwaggerDocument), swaggerDoc, result.Formatter, result.MediaType);
        }
コード例 #2
0
ファイル: SwaggerOptions.cs プロジェクト: batesiiic/Ahoy
        public SwaggerOptions()
        {
            SwaggerGeneratorOptions = new SwaggerGeneratorOptions();
            SwaggerGeneratorOptions.OperationFilters.Add(new ApplySwaggerOperationAttributes());
            SwaggerGeneratorOptions.OperationFilters.Add(new ApplySwaggerResponseAttributes());

            SchemaGeneratorOptions = new SchemaGeneratorOptions();
        }
コード例 #3
0
 public SwaggerGenerator(
     IApiDescriptionGroupCollectionProvider apiDescriptionsProvider,
     Func <ISchemaRegistry> schemaRegistryFactory,
     SwaggerGeneratorOptions options = null)
 {
     _apiDescriptionsProvider = apiDescriptionsProvider;
     _schemaRegistryFactory   = schemaRegistryFactory;
     _options = options ?? new SwaggerGeneratorOptions();
 }
コード例 #4
0
ファイル: SwaggerGenerator.cs プロジェクト: batesiiic/Ahoy
 public SwaggerGenerator(
     IApiDescriptionGroupCollectionProvider apiDescriptionsProvider,
     Func<ISchemaRegistry> schemaRegistryFactory,
     SwaggerGeneratorOptions options = null)
 {
     _apiDescriptionsProvider = apiDescriptionsProvider;
     _schemaRegistryFactory = schemaRegistryFactory;
     _options = options ?? new SwaggerGeneratorOptions();
 }
コード例 #5
0
 public SwaggerGenerator(
     string basePath,
     string apiVersion,
     IEnumerable <ApiDescription> apiDescriptions,
     SwaggerGeneratorOptions options)
 {
     _basePath        = basePath;
     _apiVersion      = apiVersion;
     _apiDescriptions = apiDescriptions;
     _options         = options;
 }
コード例 #6
0
 public SwaggerGenerator(
     IApiExplorer apiExplorer,
     IContractResolver jsonContractResolver,
     IDictionary<string, Info> apiVersions,
     SwaggerGeneratorOptions options = null)
 {
     _apiExplorer = apiExplorer;
     _jsonContractResolver = jsonContractResolver;
     _apiVersions = apiVersions;
     _options = options ?? new SwaggerGeneratorOptions();
 }
コード例 #7
0
 public SwaggerGenerator(
     IApiExplorer apiExplorer,
     JsonSerializerSettings jsonSerializerSettings,
     IDictionary<string, Info> apiVersions,
     SwaggerGeneratorOptions options = null)
 {
     _apiExplorer = apiExplorer;
     _jsonSerializerSettings = jsonSerializerSettings;
     _apiVersions = apiVersions;
     _options = options ?? new SwaggerGeneratorOptions();
 }
コード例 #8
0
 public SwaggerGenerator(
     IApiExplorer apiExplorer,
     JsonSerializerSettings jsonSerializerSettings,
     IDictionary <string, Info> apiVersions,
     SwaggerGeneratorOptions options = null)
 {
     _apiExplorer            = apiExplorer;
     _jsonSerializerSettings = jsonSerializerSettings;
     _apiVersions            = apiVersions;
     _options = options ?? new SwaggerGeneratorOptions();
 }
コード例 #9
0
 public SwaggerGenerator(
     IApiExplorer apiExplorer,
     IContractResolver jsonContractResolver,
     IDictionary <string, Info> apiVersions,
     SwaggerGeneratorOptions options = null)
 {
     _apiExplorer          = apiExplorer;
     _jsonContractResolver = jsonContractResolver;
     _apiVersions          = apiVersions;
     _options = options ?? new SwaggerGeneratorOptions();
 }
コード例 #10
0
 public SwaggerGenerator(
     string basePath,
     string apiVersion,
     IEnumerable<ApiDescription> apiDescriptions,
     SwaggerGeneratorOptions options)
 {
     _basePath = basePath;
     _apiVersion = apiVersion;
     _apiDescriptions = apiDescriptions;
     _options = options;
 }
コード例 #11
0
 public SwaggerGenerator(
     IApiExplorer apiExplorer,
     JsonSerializerSettings jsonSerializerSettings,
     IDictionary <string, Info> apiVersions,
     SwaggerGeneratorOptions options = null)
 {
     this._apiExplorer            = apiExplorer;
     this._jsonSerializerSettings = jsonSerializerSettings;
     this._apiVersions            = apiVersions;
     this._options = options ?? new SwaggerGeneratorOptions((Func <ApiDescription, string, bool>)null, (IEnumerable <string>)null, (IDictionary <string, SecurityScheme>)null, false, (Func <ApiDescription, string>)null, (IComparer <string>)null, (IDictionary <Type, Func <Schema> >)null, (IEnumerable <ISchemaFilter>)null, (IEnumerable <IModelFilter>)null, false, (Func <Type, string>)null, false, false, false, (IEnumerable <IOperationFilter>)null, (IEnumerable <IDocumentFilter>)null, (Func <IEnumerable <ApiDescription>, ApiDescription>)null);
 }
コード例 #12
0
        private IEnumerable<MediaTypeFormatter> GetSupportedSwaggerFormatters(SwaggerGeneratorOptions options)
        {
            var jsonFormatter = new JsonMediaTypeFormatter
            {
                SerializerSettings = new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    Converters = new List<JsonConverter>() { new VendorExtensionsConverter() }
                }
            };

              if (options.DescribeAllEnumsAsStrings)
              {
                    jsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter()
                    {
                          CamelCaseText = options.DescribeStringEnumsInCamelCase
                    });
              }

            // NOTE: The custom converter would not be neccessary in Newtonsoft.Json >= 5.0.5 as JsonExtensionData
            // provides similar functionality. But, need to stick with older version for WebApi 5.0.0 compatibility
            return new[] { jsonFormatter };
        }
コード例 #13
0
        private SwaggerGenerator Subject(
            Action <FakeApiDescriptionGroupCollectionProvider> setupApis = null,
            Action <SwaggerGeneratorOptions> configure = null)
        {
            var apiDescriptionsProvider = new FakeApiDescriptionGroupCollectionProvider();

            if (setupApis != null)
            {
                setupApis(apiDescriptionsProvider);
            }

            var options = new SwaggerGeneratorOptions();

            if (configure != null)
            {
                configure(options);
            }

            return(new SwaggerGenerator(
                       apiDescriptionsProvider,
                       () => new SchemaGenerator(new DefaultContractResolver()),
                       options
                       ));
        }
コード例 #14
0
        private SwaggerGenerator Subject(
            Action<FakeApiDescriptionGroupCollectionProvider> setupApis = null,
            Action<SwaggerGeneratorOptions> configure = null)
        {
            var apiDescriptionsProvider = new FakeApiDescriptionGroupCollectionProvider();
            if (setupApis != null) setupApis(apiDescriptionsProvider);

            var options = new SwaggerGeneratorOptions();
            if (configure != null) configure(options);

            return new SwaggerGenerator(
                apiDescriptionsProvider,
                () => new SchemaGenerator(new JsonSerializerSettings()),
                options
            );
        }
コード例 #15
0
 public static void DocumentFilter <TFilter>(this SwaggerGeneratorOptions options)
     where TFilter : IDocumentFilter, new()
 {
     options.DocumentFilters.Add(new TFilter());
 }
コード例 #16
0
 public static void OperationFilter <TFilter>(this SwaggerGeneratorOptions options)
     where TFilter : IOperationFilter, new()
 {
     options.OperationFilters.Add(new TFilter());
 }