/// <summary> /// Initializes a new instance of the <see cref="NodaTimeSchemaSettings"/> class. /// </summary> /// <param name="resolvePropertyName">Function that resolves property name by proper naming strategy.</param> /// <param name="formatToJson">Function that formats object as json text.</param> /// <param name="shouldGenerateExamples">Should the example node be generated.</param> /// <param name="schemaExamples"><see cref="SchemaExamples"/> for schema example values.</param> /// <param name="dateTimeZoneProvider"><see cref="IDateTimeZoneProvider"/> configured in Startup.</param> public NodaTimeSchemaSettings( Func<string, string> resolvePropertyName, Func<object, string> formatToJson, bool shouldGenerateExamples, SchemaExamples? schemaExamples = null, IDateTimeZoneProvider? dateTimeZoneProvider = null) { ResolvePropertyName = resolvePropertyName; FormatToJson = formatToJson; DateTimeZoneProvider = dateTimeZoneProvider ?? DateTimeZoneProviders.Tzdb; ShouldGenerateExamples = shouldGenerateExamples; SchemaExamples = schemaExamples ?? new SchemaExamples( DateTimeZoneProvider, dateTimeUtc: null, dateTimeZone: null); }
/// <summary> /// Creates schemas container. /// </summary> /// <returns>Initialized <see cref="Schemas"/> instance.</returns> public Schemas CreateSchemas() { SchemaExamples examples = _settings.SchemaExamples; // https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14 return(new Schemas { Instant = () => StringSchema(examples.Instant, "date-time"), LocalDate = () => StringSchema(examples.ZonedDateTime.Date, "date"), LocalTime = () => StringSchema(examples.ZonedDateTime.TimeOfDay), LocalDateTime = () => StringSchema(examples.ZonedDateTime.LocalDateTime), OffsetDateTime = () => StringSchema(examples.OffsetDateTime, "date-time"), ZonedDateTime = () => StringSchema(examples.ZonedDateTime), Interval = () => new OpenApiSchema { Type = "object", Properties = new Dictionary <string, OpenApiSchema> { { ResolvePropertyName(nameof(Interval.Start)), StringSchema(examples.Interval.Start, "date-time") }, { ResolvePropertyName(nameof(Interval.End)), StringSchema(examples.Interval.End, "date-time") }, }, }, DateInterval = () => new OpenApiSchema { Type = "object", Properties = new Dictionary <string, OpenApiSchema> { { ResolvePropertyName(nameof(DateInterval.Start)), StringSchema(examples.DateInterval.Start, "date") }, { ResolvePropertyName(nameof(DateInterval.End)), StringSchema(examples.DateInterval.End, "date") }, }, }, Offset = () => StringSchema(examples.ZonedDateTime.Offset), Period = () => StringSchema(examples.Period), Duration = () => StringSchema(examples.Interval.Duration), OffsetDate = () => StringSchema(examples.OffsetDate), OffsetTime = () => StringSchema(examples.OffsetTime), DateTimeZone = () => StringSchema(examples.DateTimeZone), }); }