Пример #1
0
        public static void ApplyAutoRestFilters(this SwaggerDocsConfig config, SwaggerDocsConfigExtensionsConfiguration extensionsConfiguration, object codeGenerationSettings = null)
        {
            if (codeGenerationSettings != null)
            {
                config.DocumentFilter(() => new CodeGenerationSettingsDocumentFilter(codeGenerationSettings));
            }
            if (extensionsConfiguration.ApplyEnumTypeSchemaFilter)
            {
                config.SchemaFilter(() => new EnumTypeSchemaFilter(extensionsConfiguration.EnumTypeModelAsString));
            }
            if (extensionsConfiguration.ApplyTypeFormatSchemaFilter)
            {
                config.SchemaFilter <TypeFormatSchemaFilter>();
            }
            if (extensionsConfiguration.ApplyNullableTypeSchemaFilter)
            {
                config.SchemaFilter <NullableTypeSchemaFilter>();
                if (extensionsConfiguration.ApplyNonNullableAsRequiredSchemaFilter)
                {
                    config.SchemaFilter <NonNullableAsRequiredSchemaFilter>();
                }
            }

            config.ApplyFiltersToAllSchemas();
        }
Пример #2
0
        /// <summary>
        /// Adds fluent validation rules to swagger.
        /// </summary>
        /// <param name="config">Swagger options.</param>
        /// <param name="factory">IValidatorFactory. If null then factory gets from <see cref="HttpConfiguration.Services"/></param>
        public static void AddFluentValidationRules(this SwaggerDocsConfig config, IValidatorFactory factory = null)
        {
            var validatorFactory = factory ?? ((FluentValidationModelValidatorProvider)GlobalConfiguration.Configuration.Services.GetServices(typeof(ModelValidatorProvider)).FirstOrDefault(pr => pr is FluentValidationModelValidatorProvider))?.ValidatorFactory;

            if (validatorFactory != null)
            {
                config.SchemaFilter(() => new FluentValidationRules(validatorFactory));
            }
        }
Пример #3
0
        public static void ReleaseTheTRex(this SwaggerDocsConfig config)
        {
            if (config == null)
            {
                return;
            }

            config.SchemaFilter <TRexSchemaFilter>();
            config.OperationFilter <TRexOperationFilter>();
        }
Пример #4
0
        /// <summary>
        /// Confgures Swaschbuckle to provide additional metadata in methods which use FromQuery attribute so the API provided by DotVVM API generator is easier to use.
        /// </summary>
        public static void EnableDotvvmIntegration(this SwaggerDocsConfig options, Action <DotvvmApiOptions> configureOptions = null)
        {
            var apiOptions = new DotvvmApiOptions();

            configureOptions?.Invoke(apiOptions);

            var propertySerialization = new DefaultPropertySerialization();

            options.OperationFilter(() => new AddAsObjectAnnotationOperationFilter(propertySerialization));
            options.SchemaFilter(() => new AddTypeToModelSchemaFilter());
            options.DocumentFilter(() => new HandleKnownTypesDocumentFilter(apiOptions, propertySerialization));
        }
Пример #5
0
        /// <summary>
        /// Configures the Swashbuckle document generation, as per Zinc needs.
        /// </summary>
        /// <param name="config">
        /// Swagger configuration options.
        /// </param>
        public static void ZincConfigure(this SwaggerDocsConfig config)
        {
            config.UseFullTypeNameInSchemaIds();
            config.DescribeAllEnumsAsStrings();
            config.SchemaFilter <ZincSchemaFilter>();


            /*
             * Custom types
             */
            config.MapType <Duration>(() => new Swashbuckle.Swagger.Schema()
            {
                type    = "string",
                format  = "duration",
                example = "PT1H",
            });

            config.MapType <Duration?>(() => new Swashbuckle.Swagger.Schema()
            {
                type    = "string",
                format  = "duration",
                example = "PT1H",
            });
        }