Skip to content

Commit

Permalink
[Schema Registry] Default SchemaFormat to the Content-Type header val…
Browse files Browse the repository at this point in the history
…ue (Azure#45007)

* fixes

* fixes

* clean up client
  • Loading branch information
m-redding authored and tejasm-microsoft committed Jul 22, 2024
1 parent 29f5f0b commit dc44873
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 99 deletions.
58 changes: 0 additions & 58 deletions sdk/schemaregistry/Azure.Data.SchemaRegistry/src/ContentType.cs

This file was deleted.

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

39 changes: 22 additions & 17 deletions sdk/schemaregistry/Azure.Data.SchemaRegistry/src/SchemaFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.ComponentModel;
using Azure.Core;

namespace Azure.Data.SchemaRegistry
{
Expand All @@ -16,9 +17,16 @@ namespace Azure.Data.SchemaRegistry
private const string CustomValue = "Custom";
private const string ProtobufValue = "Protobuf";

private const string AvroContentType = "Avro";
private const string JsonContentType = "Json";
private const string ProtobufContentType = "vnd.ms.protobuf";
// Temporary until autorest bug is fixed
private const string AvroContentType = "application/json; serialization=Avro";
private const string JsonContentType = "application/json; serialization=Json";
private const string CustomContentType = "text/plain; charset=utf-8";
private const string ProtobufContentType = "text/vnd.ms.protobuf";

private const string AvroContentTypeValue = "Avro";
private const string JsonContentTypeValue = "Json";
private const string CustomContentTypeValue = "utf-8";
private const string ProtobufContentTypeValue = "vnd.ms.protobuf";

/// <summary> Initializes a new instance of <see cref="SchemaFormat"/>. </summary>
/// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception>
Expand Down Expand Up @@ -63,37 +71,34 @@ internal ContentType ToContentType()
switch (_value)
{
case AvroValue:
return ContentType.Avro;
return new ContentType(AvroContentType);
case JsonValue:
return ContentType.Json;
return new ContentType(JsonContentType);
//case ProtobufValue:
// return ContentType.Protobuf;
// return new ContentType(ProtobufContentType);
default:
return ContentType.Custom;
return new ContentType(CustomContentType);
}
}

internal static SchemaFormat FromContentType(string contentTypeValue)
{
var contentTypeParameterValue = contentTypeValue.Split('=');
var contentSubType = contentTypeValue.Split('/');
if (contentTypeParameterValue.Length > 1)
{
switch (contentTypeParameterValue[1])
{
case AvroContentType:
return SchemaFormat.Avro;
case JsonContentType:
return SchemaFormat.Json;
case AvroContentTypeValue:
return Avro;
case JsonContentTypeValue:
return Json;
case CustomContentTypeValue:
return Custom;
default:
break;
}
}
return contentSubType[1] switch
{
//ProtobufContentType => SchemaFormat.Protobuf,
_ => SchemaFormat.Custom,
};
return new SchemaFormat(contentTypeValue);
}
}
}
Loading

0 comments on commit dc44873

Please sign in to comment.