Skip to content

CSHARP-5453: Add builder for CSFLE schemas #1631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
db1dea7
CSHARP-5453: Improve field encryption usability with attributes/API
papafe Mar 7, 2025
cee7a93
Small corrections
papafe Mar 7, 2025
7d1c109
Fixed stub
papafe Mar 11, 2025
87b1c2f
Small fix
papafe Mar 11, 2025
ee898d3
Various improvements
papafe Mar 12, 2025
a3a06a7
Conversion to records
papafe Mar 12, 2025
e599cc0
Various improvements
papafe Mar 12, 2025
400b8b0
Fixed API
papafe Mar 12, 2025
0a32d51
Small comment
papafe Mar 12, 2025
c3bfde4
Fix to naming
papafe Mar 13, 2025
dd1aeaf
Several improvements
papafe Mar 19, 2025
f21b87a
Removed unused
papafe Mar 19, 2025
f88465c
First improvement
papafe Mar 20, 2025
33fcbeb
Removed old things
papafe Apr 9, 2025
6a265c2
Improvements
papafe Apr 14, 2025
c37c6bb
Some simplifications
papafe Apr 14, 2025
6f1b2a3
Simplified
papafe Apr 14, 2025
4942f97
Improved API
papafe Apr 14, 2025
93f46f9
Small fix
papafe Apr 14, 2025
670c663
Fixing schema builder
papafe Apr 30, 2025
517db94
Various improvements plus fixed tests
papafe May 1, 2025
8f10903
Small fix
papafe May 1, 2025
ef5faa9
Added first basic test
papafe May 2, 2025
601169e
Corrections plus more tests
papafe May 2, 2025
4ddfdf8
Corrected order
papafe May 2, 2025
f31c705
Improved tests
papafe May 2, 2025
0069760
Added exceptions and improved testing
papafe May 5, 2025
bd88e8b
Moved builder to encryption project and removed CsfleEncryptionEnum (…
papafe May 5, 2025
20379df
Put bsontypes to be nullable and removed unsupported bsonTypes
papafe May 5, 2025
a8390d3
Corrected test naming
papafe May 5, 2025
d30739d
Fixed API for overloads
papafe May 5, 2025
fa3143c
Added exception for empty schema
papafe May 5, 2025
134622e
Added docs
papafe May 5, 2025
6098c29
Small fix
papafe May 5, 2025
7a4f46a
Fix
papafe May 5, 2025
a25ad56
Removed unnecessary
papafe May 5, 2025
84ddfbd
Name fix
papafe May 5, 2025
eca0ace
Removed unnecessaty
papafe May 5, 2025
b6ef4d2
Added common method BsonType --> string and removed unnecessary files.
papafe Jun 18, 2025
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
57 changes: 57 additions & 0 deletions src/MongoDB.Bson/Serialization/BsonTypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;

namespace MongoDB.Bson.Serialization
{
/// <summary>
/// A static class containing extension methods for <see cref="BsonType"/>.
/// </summary>
public static class BsonTypeExtensions
{
/// <summary>
/// Maps a <see cref="BsonType"/> to its corresponding string representation.
/// </summary>
/// <param name="type">The input type to map.</param>
public static string ToStringRepresentation(this BsonType type)
Copy link
Contributor Author

@papafe papafe Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rstam this is the new method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should add this to the public API just so EF Core can use it. EF Core can easily duplicate this very small method.

Unless there is a clear scenario where a USER would find this useful, I wouldn't add it to the public API.

Definitely a good idea to centralize this conversion in an internal method for our own consumption.

If we do make this public I suggest it be done as a separate JIRA ticket so that users can see it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a useful method with a clear and defined purpose and limited API surface. If I need it in the EF provider chances are other people need it too and probably also had to reproduce it. They'd need it right now if they're doing their own queryable encryption or CSFLE work and are trying to leverage BsonType in order to generate the schema.

{
return type switch
{
BsonType.Array => "array",
BsonType.Binary => "binData",
BsonType.Boolean => "bool",
BsonType.DateTime => "date",
BsonType.Decimal128 => "decimal",
BsonType.Document => "object",
BsonType.Double => "double",
BsonType.Int32 => "int",
BsonType.Int64 => "long",
BsonType.JavaScript => "javascript",
BsonType.JavaScriptWithScope => "javascriptWithScope",
BsonType.MaxKey => "maxKey",
BsonType.MinKey => "minKey",
BsonType.Null => "null",
BsonType.ObjectId => "objectId",
BsonType.RegularExpression => "regex",
BsonType.String => "string",
BsonType.Symbol => "symbol",
BsonType.Timestamp => "timestamp",
BsonType.Undefined => "undefined",
_ => throw new ArgumentException($"Unexpected BSON type: {type}.", nameof(type))
};
}
}
}
Loading