/// <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> /// Configures swagger to use NodaTime types. /// </summary> /// <param name="config">Options to configure swagger.</param> /// <param name="serializerSettings">Settings to configure serialization.</param> public static void ConfigureForNodaTime(this SwaggerGenOptions config, JsonSerializerSettings serializerSettings) { bool isNodaConvertersRegistered = serializerSettings.Converters.Any(converter => converter is NodaConverterBase <Instant>); if (!isNodaConvertersRegistered) { serializerSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); } Schemas schemas = new SchemasFactory(serializerSettings).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 <DateTimeZone> (schemas.DateTimeZone); 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); }