Settings that control serialization aspects.
Esempio n. 1
0
        /// <summary>
        /// Configures swagger to use NodaTime types.
        /// </summary>
        /// <param name="config">Options to configure swagger.</param>
        /// <param name="nodaTimeSchemaSettings">Settings to configure serialization.</param>
        public static void ConfigureForNodaTime(this SwaggerGenOptions config, NodaTimeSchemaSettings nodaTimeSchemaSettings)
        {
            config.ParameterFilter <NamingPolicyParameterFilter>(nodaTimeSchemaSettings);

            Schemas schemas = new SchemasFactory(nodaTimeSchemaSettings).CreateSchemas();

            config.MapType <Instant>        (schemas.Instant);
            config.MapType <LocalDate>      (schemas.LocalDate);
            config.MapType <LocalTime>      (schemas.LocalTime);
            config.MapType <LocalDateTime>  (schemas.LocalDateTime);
            config.MapType <OffsetDateTime> (schemas.OffsetDateTime);
            config.MapType <ZonedDateTime>  (schemas.ZonedDateTime);
            config.MapType <Interval>       (schemas.Interval);
            config.MapType <DateInterval>   (schemas.DateInterval);
            config.MapType <Offset>         (schemas.Offset);
            config.MapType <Period>         (schemas.Period);
            config.MapType <Duration>       (schemas.Duration);
            config.MapType <OffsetDate>     (schemas.OffsetDate);
            config.MapType <OffsetTime>     (schemas.OffsetTime);
            config.MapType <DateTimeZone>   (schemas.DateTimeZone);

            // Nullable structs
            config.MapType <Instant?>       (schemas.Instant);
            config.MapType <LocalDate?>     (schemas.LocalDate);
            config.MapType <LocalTime?>     (schemas.LocalTime);
            config.MapType <LocalDateTime?> (schemas.LocalDateTime);
            config.MapType <OffsetDateTime?>(schemas.OffsetDateTime);
            config.MapType <ZonedDateTime?> (schemas.ZonedDateTime);
            config.MapType <Interval?>      (schemas.Interval);
            config.MapType <Offset?>        (schemas.Offset);
            config.MapType <Duration?>      (schemas.Duration);
            config.MapType <OffsetDate?>    (schemas.OffsetDate);
            config.MapType <OffsetTime?>    (schemas.OffsetTime);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SchemasFactory"/> class.
 /// </summary>
 /// <param name="settings"><see cref="JsonSerializerSettings"/> for serializing examples and for <see cref="IContractResolver"/>.</param>
 public SchemasFactory(NodaTimeSchemaSettings settings)
 {
     _settings = settings;
 }
 public NamingPolicyParameterFilter(NodaTimeSchemaSettings nodaTimeSchemaSettings)
 {
     _nodaTimeSchemaSettings = nodaTimeSchemaSettings;
 }