mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Add JsonInto32Converter
Add additional swagger type mapping
This commit is contained in:
parent
77bea56708
commit
6651cb8d24
@ -215,6 +215,19 @@ namespace Jellyfin.Server.Extensions
|
|||||||
Format = "string"
|
Format = "string"
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
options.MapType<Dictionary<ImageType, Dictionary<string, string>>>(() =>
|
||||||
|
new OpenApiSchema
|
||||||
|
{
|
||||||
|
Type = "object",
|
||||||
|
Properties = typeof(ImageType).GetEnumNames().ToDictionary(
|
||||||
|
name => name,
|
||||||
|
name => new OpenApiSchema
|
||||||
|
{
|
||||||
|
Type = "string",
|
||||||
|
Format = "string"
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,40 +14,27 @@ namespace MediaBrowser.Common.Json.Converters
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
static void ThrowFormatException() => throw new FormatException("Invalid format for an integer.");
|
if (reader.TokenType == JsonTokenType.String)
|
||||||
ReadOnlySpan<byte> span = stackalloc byte[0];
|
{
|
||||||
|
ReadOnlySpan<byte> span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
|
||||||
|
if (Utf8Parser.TryParse(span, out int number, out int bytesConsumed) && span.Length == bytesConsumed)
|
||||||
|
{
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
if (reader.HasValueSequence)
|
if (int.TryParse(reader.GetString(), out number))
|
||||||
{
|
{
|
||||||
long sequenceLength = reader.ValueSequence.Length;
|
return number;
|
||||||
Span<byte> stackSpan = stackalloc byte[(int)sequenceLength];
|
}
|
||||||
reader.ValueSequence.CopyTo(stackSpan);
|
|
||||||
span = stackSpan;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
span = reader.ValueSpan;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Utf8Parser.TryParse(span, out int number, out _))
|
return reader.GetInt32();
|
||||||
{
|
|
||||||
ThrowFormatException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
|
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
static void ThrowInvalidOperationException() => throw new InvalidOperationException();
|
writer.WriteNumberValue(value);
|
||||||
Span<byte> span = stackalloc byte[16];
|
|
||||||
if (Utf8Formatter.TryFormat(value, span, out int bytesWritten))
|
|
||||||
{
|
|
||||||
writer.WriteStringValue(span.Slice(0, bytesWritten));
|
|
||||||
}
|
|
||||||
|
|
||||||
ThrowInvalidOperationException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ namespace MediaBrowser.Common.Json
|
|||||||
};
|
};
|
||||||
|
|
||||||
options.Converters.Add(new JsonGuidConverter());
|
options.Converters.Add(new JsonGuidConverter());
|
||||||
|
options.Converters.Add(new JsonInt32Converter());
|
||||||
options.Converters.Add(new JsonStringEnumConverter());
|
options.Converters.Add(new JsonStringEnumConverter());
|
||||||
options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
|
options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user