CalculateOfferPricingRequest
Properties
-
offers(array)Required. List of offers to calculate pricing for. Length must be at least 1.-
Items (object)Cannot contain additional properties.
offerId(string, required)Required. The offer ID to calculate pricing for.pageCount(['integer', 'null'], format: int32)Page count (used only if tiers and page count tiers exist).-
productIds(['array', 'null'])Product IDs for filtering (optional).- Items (string)
-
quantity(integer, format: int32, required)Required. The quantity to calculate pricing for. Minimum:1.
-
-
priceClasses(['array', 'null'])Preferred price classes (priority order). Nullable.- Items (string)
Quicktype Command
quicktype \
--framework SystemTextJson \
--lang cs \
--number-type double \
--src-lang schema \
--no-check-required \
--density dense \
--features complete \
--namespace OtpSchema.Api.OfferBroker.CalculateOfferPricingRequest \
--src .working/build/internal/json-schema-for-cs/CalculateOfferPricingRequest.json -o .working/build/internal/csharp/OtpSchema/Api/OfferBroker/CalculateOfferPricingRequest.cs
CalculateOfferPricingRequest
// <auto-generated />
//
// To parse this JSON data, add NuGet 'System.Text.Json' then do:
//
// using OtpSchema.Api.OfferBroker.CalculateOfferPricingRequest;
//
// var calculateOfferPricingRequest = CalculateOfferPricingRequest.FromJson(jsonString);
#nullable enable
#pragma warning disable CS8618
#pragma warning disable CS8601
#pragma warning disable CS8603
namespace OtpSchema.Api.OfferBroker.CalculateOfferPricingRequest
{
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Globalization;
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
using N = System.Text.Json.Serialization.JsonIgnoreCondition;
public partial class CalculateOfferPricingRequest
{
[J("offers")] public Offer[]? Offers { get; set; } // Required. List of offers to calculate pricing for.
[J("priceClasses")] public string[]? PriceClasses { get; set; } // Preferred price classes (priority order). Nullable.
}
public partial class Offer
{
[J("offerId")][JsonConverter(typeof(MinMaxLengthCheckConverter))] public string OfferId { get; set; } // Required. The offer ID to calculate pricing for.
[J("pageCount")] public long? PageCount { get; set; } // Page count (used only if tiers and page count tiers exist).
[J("productIds")] public string[]? ProductIds { get; set; } // Product IDs for filtering (optional).
[J("quantity")] public long Quantity { get; set; } // Required. The quantity to calculate pricing for.
}
public partial class CalculateOfferPricingRequest
{
public static CalculateOfferPricingRequest FromJson(string json) => JsonSerializer.Deserialize<CalculateOfferPricingRequest>(json, OtpSchema.Api.OfferBroker.CalculateOfferPricingRequest.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this CalculateOfferPricingRequest self) => JsonSerializer.Serialize(self, OtpSchema.Api.OfferBroker.CalculateOfferPricingRequest.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
{
Converters =
{
new DateOnlyConverter(),
new TimeOnlyConverter(),
IsoDateTimeOffsetConverter.Singleton
},
};
}
internal class MinMaxLengthCheckConverter : JsonConverter<string>
{
public override bool CanConvert(Type t) => t == typeof(string);
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
if (value != null && value.Length >= 1)
{
return value;
}
throw new Exception("Cannot unmarshal type string");
}
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
{
if (value != null && value.Length >= 1)
{
JsonSerializer.Serialize(writer, value, options);
return;
}
throw new Exception("Cannot marshal type string");
}
public static readonly MinMaxLengthCheckConverter Singleton = new MinMaxLengthCheckConverter();
}
public class DateOnlyConverter : JsonConverter<DateOnly>
{
private readonly string serializationFormat;
public DateOnlyConverter() : this(null) { }
public DateOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
}
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return DateOnly.Parse(value!);
}
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString(serializationFormat));
}
public class TimeOnlyConverter : JsonConverter<TimeOnly>
{
private readonly string serializationFormat;
public TimeOnlyConverter() : this(null) { }
public TimeOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
}
public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return TimeOnly.Parse(value!);
}
public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString(serializationFormat));
}
internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
{
public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
private string? _dateTimeFormat;
private CultureInfo? _culture;
public DateTimeStyles DateTimeStyles
{
get => _dateTimeStyles;
set => _dateTimeStyles = value;
}
public string? DateTimeFormat
{
get => _dateTimeFormat ?? string.Empty;
set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
}
public CultureInfo Culture
{
get => _culture ?? CultureInfo.CurrentCulture;
set => _culture = value;
}
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
{
string text;
if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
|| (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
{
value = value.ToUniversalTime();
}
text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);
writer.WriteStringValue(text);
}
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string? dateText = reader.GetString();
if (string.IsNullOrEmpty(dateText) == false)
{
if (!string.IsNullOrEmpty(_dateTimeFormat))
{
return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
}
else
{
return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
}
}
else
{
return default(DateTimeOffset);
}
}
public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
}
}
#pragma warning restore CS8618
#pragma warning restore CS8601
#pragma warning restore CS8603
CalculateOfferPricingRequest
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "CalculateOfferPricingRequest.json",
"type": "object",
"additionalProperties": false,
"properties": {
"offers": {
"description": "Required. List of offers to calculate pricing for.",
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"offerId": {
"description": "Required. The offer ID to calculate pricing for.",
"type": "string",
"minLength": 1
},
"pageCount": {
"description": "Page count (used only if tiers and page count tiers exist).",
"type": ["integer", "null"],
"format": "int32"
},
"productIds": {
"description": "Product IDs for filtering (optional).",
"type": ["array", "null"],
"items": {"type": "string"}
},
"quantity": {
"description": "Required. The quantity to calculate pricing for.",
"type": "integer",
"format": "int32",
"minimum": 1
}
},
"required": ["offerId", "quantity"]
},
"minItems": 1
},
"priceClasses": {
"description": "Preferred price classes (priority order). Nullable.",
"type": ["array", "null"],
"items": {"type": "string"}
}
},
"required": ["offers"]
}