Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@

<PropertyGroup>
<TestProxyVersion>1.0.0-dev.20250930.1</TestProxyVersion>
<UnbrandedGeneratorVersion>1.0.0-alpha.20251208.2</UnbrandedGeneratorVersion>
<UnbrandedGeneratorVersion>1.0.0-alpha.20251210.1</UnbrandedGeneratorVersion>
<AzureGeneratorVersion>1.0.0-alpha.20251205.1</AzureGeneratorVersion>
</PropertyGroup>
</Project>
10 changes: 5 additions & 5 deletions eng/http-client-csharp-emitter-package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eng/http-client-csharp-emitter-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"main": "dist/src/index.js",
"dependencies": {
"client-plugin": "file:../../../../eng/packages/plugins/client",
"@typespec/http-client-csharp": "1.0.0-alpha.20251208.2"
"@typespec/http-client-csharp": "1.0.0-alpha.20251210.1"
},
"devDependencies": {
"@azure-tools/typespec-client-generator-core": "0.62.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected override string BuildServiceName()

/// <inheritdoc/>
public override ValueExpression DeserializeJsonValue(
Type valueType,
CSharpType valueType,
ScopedApi<JsonElement> element,
ScopedApi<BinaryData> data,
ScopedApi<ModelReaderWriterOptions> mrwOptionsParameter,
Expand All @@ -135,7 +135,7 @@ public override ValueExpression DeserializeJsonValue(
}

private ValueExpression? DeserializeJsonValueCore(
Type valueType,
CSharpType valueType,
ScopedApi<JsonElement> element,
ScopedApi<BinaryData> data,
ScopedApi<ModelReaderWriterOptions> mrwOptionsParameter,
Expand All @@ -147,7 +147,7 @@ public override ValueExpression DeserializeJsonValue(
}

/// <inheritdoc/>
public override MethodBodyStatement SerializeJsonValue(Type valueType, ValueExpression value, ScopedApi<Utf8JsonWriter> utf8JsonWriter, ScopedApi<ModelReaderWriterOptions> mrwOptionsParameter, SerializationFormat serializationFormat)
public override MethodBodyStatement SerializeJsonValue(CSharpType valueType, ValueExpression value, ScopedApi<Utf8JsonWriter> utf8JsonWriter, ScopedApi<ModelReaderWriterOptions> mrwOptionsParameter, SerializationFormat serializationFormat)
{
var statement = SerializeValueTypeCore(serializationFormat, value, valueType, utf8JsonWriter, mrwOptionsParameter);
return statement ?? base.SerializeJsonValue(valueType, value, utf8JsonWriter, mrwOptionsParameter, serializationFormat);
Expand All @@ -156,7 +156,7 @@ public override MethodBodyStatement SerializeJsonValue(Type valueType, ValueExpr
private MethodBodyStatement? SerializeValueTypeCore(SerializationFormat serializationFormat, ValueExpression value, CSharpType valueType, ScopedApi<Utf8JsonWriter> utf8JsonWriter, ScopedApi<ModelReaderWriterOptions> mrwOptionsParameter)
{
return KnownAzureTypes.TryGetJsonSerializationExpression(valueType, out var serializationExpression) ?
serializationExpression(value, utf8JsonWriter, mrwOptionsParameter, serializationFormat) :
serializationExpression(valueType, value, utf8JsonWriter, mrwOptionsParameter, serializationFormat) :
null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
using System.Net;
using System.Text;
using System.Text.Json;
using static Microsoft.TypeSpec.Generator.Primitives.CSharpType;
using static Microsoft.TypeSpec.Generator.Snippets.Snippet;

namespace Azure.Generator.Primitives
{
internal static class KnownAzureTypes
{
public delegate MethodBodyStatement SerializationExpression(ValueExpression value, ScopedApi<Utf8JsonWriter> writer, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format);
public delegate MethodBodyStatement SerializationExpression(CSharpType valueType, ValueExpression value, ScopedApi<Utf8JsonWriter> writer, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format);
public delegate ValueExpression DeserializationExpression(CSharpType valueType, ScopedApi<JsonElement> element, ScopedApi<BinaryData> data, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format);

private const string UuidId = "Azure.Core.uuid";
Expand All @@ -33,19 +34,25 @@ internal static class KnownAzureTypes
private const string AzureError = "Azure.Core.Foundations.Error";
private const string EmbeddingVector = "Azure.Core.EmbeddingVector";

private static MethodBodyStatement SerializeTypeWithImplicitOperatorToString(ValueExpression value, ScopedApi<Utf8JsonWriter> writer, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format)
=> writer.WriteStringValue(value);
private static MethodBodyStatement SerializeTypeWithImplicitOperatorToString(CSharpType valueType, ValueExpression value, ScopedApi<Utf8JsonWriter> writer, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format)
{
value = value.NullableStructValue(valueType);
return writer.WriteStringValue(value);
}

private static ValueExpression DeserializeNewInstanceStringLikeType(CSharpType valueType, ScopedApi<JsonElement> element, ScopedApi<BinaryData> data, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format)
=> New.Instance(valueType, element.GetString());

private static MethodBodyStatement SerializeTypeWithToString(ValueExpression value, ScopedApi<Utf8JsonWriter> writer, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format)
=> writer.WriteStringValue(value.InvokeToString());
private static MethodBodyStatement SerializeTypeWithToString(CSharpType valueType, ValueExpression value, ScopedApi<Utf8JsonWriter> writer, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format)
{
value = value.NullableStructValue(valueType);
return writer.WriteStringValue(value.InvokeToString());
}

private static ValueExpression DeserializeParsableStringLikeType(CSharpType valueType, ScopedApi<JsonElement> element, ScopedApi<BinaryData> data, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format)
=> Static(valueType).Invoke("Parse", element.GetString());

private static MethodBodyStatement SerializeResponseError(ValueExpression value, ScopedApi<Utf8JsonWriter> writer, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format)
private static MethodBodyStatement SerializeResponseError(CSharpType valueType, ValueExpression value, ScopedApi<Utf8JsonWriter> writer, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format)
{
var asJsonModel = value.CastTo(typeof(IJsonModel<ResponseError>));
return asJsonModel.Invoke(nameof(IJsonModel<ResponseError>.Write), writer, options).Terminate();
Expand Down Expand Up @@ -80,7 +87,7 @@ private static ValueExpression DeserializeResponseError(
[EmbeddingVector] = typeof(ReadOnlyMemory<>)
};

private static readonly IReadOnlyDictionary<CSharpType, SerializationExpression> _typeToSerializationExpression = new Dictionary<CSharpType, SerializationExpression>
private static readonly IReadOnlyDictionary<CSharpType, SerializationExpression> _typeToSerializationExpression = new Dictionary<CSharpType, SerializationExpression>(new CSharpTypeIgnoreNullableComparer())
{
[typeof(Guid)] = SerializeTypeWithImplicitOperatorToString,
[typeof(IPAddress)] = SerializeTypeWithToString,
Expand All @@ -90,7 +97,7 @@ private static ValueExpression DeserializeResponseError(
[typeof(ResponseError)] = SerializeResponseError,
};

private static readonly IReadOnlyDictionary<CSharpType, DeserializationExpression> _typeToDeserializationExpression = new Dictionary<CSharpType, DeserializationExpression>
private static readonly IReadOnlyDictionary<CSharpType, DeserializationExpression> _typeToDeserializationExpression = new Dictionary<CSharpType, DeserializationExpression>(new CSharpTypeIgnoreNullableComparer())
{
[typeof(Guid)] = DeserializeNewInstanceStringLikeType,
[typeof(IPAddress)] = DeserializeParsableStringLikeType,
Expand Down
10 changes: 5 additions & 5 deletions eng/packages/http-client-csharp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eng/packages/http-client-csharp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dist/generator/**"
],
"dependencies": {
"@typespec/http-client-csharp": "1.0.0-alpha.20251208.2"
"@typespec/http-client-csharp": "1.0.0-alpha.20251210.1"
},
"devDependencies": {
"@azure-tools/azure-http-specs": "0.1.0-alpha.32",
Expand Down
Loading