-
Notifications
You must be signed in to change notification settings - Fork 299
Add schema and serialization support for autoentities wildcard enhancement #2973
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
81330ac
Initial plan
Copilot 7cfbd5d
Add autoentities schema and C# models for wildcard properties
Copilot 15e4674
Add test for autoentities serialization/deserialization
Copilot 92fe8a2
Add test config file with autoentities
Copilot e02c53d
Changes to schema file
RubenCerna2079 6cbba87
Fixes to schema file
RubenCerna2079 8c25493
Add serialization and deserialization of autoentities
RubenCerna2079 fd4df81
Merge branch 'main' into copilot/add-wildcard-properties-schema
RubenCerna2079 db3d137
Fix merge conflicts
RubenCerna2079 a443ae0
Fix tests
RubenCerna2079 853e356
Rename RuntimeAutoEntitiesConverter.cs to RuntimeAutoentitiesConverte…
RubenCerna2079 30ac9d6
Rename AutoEntity.cs to Autoentity.cs
RubenCerna2079 48c48f4
Rename RuntimeAutoEntities.cs to RuntimeAutoentities.cs
RubenCerna2079 1dcfbed
Rename AutoEntityPatterns.cs to AutoentityPatterns.cs
RubenCerna2079 7be3a41
Rename AutoEntityTemplate.cs to AutoentityTemplate.cs
RubenCerna2079 71dfe30
Merge branch 'main' into copilot/add-wildcard-properties-schema
RubenCerna2079 5ce4107
Changes based on comments
RubenCerna2079 0d97798
Changes based on comments
RubenCerna2079 8cfde2e
Changes based on comments
RubenCerna2079 ed786ce
Merge branch 'main' into copilot/add-wildcard-properties-schema
RubenCerna2079 3a860f1
Fix tests
RubenCerna2079 014808e
Fix failing tests
RubenCerna2079 d399911
Merge branch 'main' into copilot/add-wildcard-properties-schema
RubenCerna2079 fcfabef
Fix entity permission
RubenCerna2079 e731411
Fix schema
RubenCerna2079 0b4ea58
Merge branch 'main' into copilot/add-wildcard-properties-schema
RubenCerna2079 8fc87af
Fix formatting issues
RubenCerna2079 1f840bd
Changes based on comments
RubenCerna2079 1247a48
Merge branch 'main' into copilot/add-wildcard-properties-schema
RubenCerna2079 6f8178a
Add missing mcp entity property
RubenCerna2079 4cef2ea
Merge branch 'main' into copilot/add-wildcard-properties-schema
RubenCerna2079 80ff055
Add additionalProperties to schema
RubenCerna2079 f3cd932
Merge branch 'main' into copilot/add-wildcard-properties-schema
RubenCerna2079 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Azure.DataApiBuilder.Config.ObjectModel; | ||
|
|
||
| namespace Azure.DataApiBuilder.Config.Converters; | ||
|
|
||
| internal class AutoentityConverter : JsonConverter<Autoentity> | ||
| { | ||
| // Settings for variable replacement during deserialization. | ||
| private readonly DeserializationVariableReplacementSettings? _replacementSettings; | ||
|
|
||
| /// <param name="replacementSettings">Settings for variable replacement during deserialization. | ||
| /// If null, no variable replacement will be performed.</param> | ||
| public AutoentityConverter(DeserializationVariableReplacementSettings? replacementSettings = null) | ||
| { | ||
| _replacementSettings = replacementSettings; | ||
RubenCerna2079 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override Autoentity? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| if (reader.TokenType is JsonTokenType.StartObject) | ||
| { | ||
| // Initialize all sub-properties to null. | ||
| AutoentityPatterns? patterns = null; | ||
| AutoentityTemplate? template = null; | ||
| EntityPermission[]? permissions = null; | ||
|
|
||
| while (reader.Read()) | ||
RubenCerna2079 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if (reader.TokenType == JsonTokenType.EndObject) | ||
| { | ||
| return new Autoentity(patterns, template, permissions); | ||
| } | ||
|
|
||
| string? propertyName = reader.GetString(); | ||
|
|
||
| reader.Read(); | ||
| switch (propertyName) | ||
| { | ||
| case "patterns": | ||
| AutoentityPatternsConverter patternsConverter = new(_replacementSettings); | ||
| patterns = patternsConverter.Read(ref reader, typeof(AutoentityPatterns), options); | ||
| break; | ||
|
|
||
| case "template": | ||
| AutoentityTemplateConverter templateConverter = new(_replacementSettings); | ||
| template = templateConverter.Read(ref reader, typeof(AutoentityTemplate), options); | ||
| break; | ||
|
|
||
RubenCerna2079 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| case "permissions": | ||
| permissions = JsonSerializer.Deserialize<EntityPermission[]>(ref reader, options) | ||
| ?? throw new JsonException("The 'permissions' property must contain at least one permission."); | ||
| break; | ||
|
|
||
| default: | ||
| throw new JsonException($"Unexpected property {propertyName}"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw new JsonException("Failed to read the Autoentities"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// When writing the autoentities back to a JSON file, only write the properties | ||
| /// if they are user provided. This avoids polluting the written JSON file with properties | ||
| /// the user most likely omitted when writing the original DAB runtime config file. | ||
| /// This Write operation is only used when a RuntimeConfig object is serialized to JSON. | ||
| /// </summary> | ||
| /// <inheritdoc/> | ||
| public override void Write(Utf8JsonWriter writer, Autoentity value, JsonSerializerOptions options) | ||
| { | ||
| writer.WriteStartObject(); | ||
|
|
||
| AutoentityPatterns? patterns = value?.Patterns; | ||
| if (patterns?.UserProvidedIncludeOptions is true | ||
| || patterns?.UserProvidedExcludeOptions is true | ||
| || patterns?.UserProvidedNameOptions is true) | ||
| { | ||
| AutoentityPatternsConverter autoentityPatternsConverter = options.GetConverter(typeof(AutoentityPatterns)) as AutoentityPatternsConverter ?? | ||
| throw new JsonException("Failed to get autoentities.patterns options converter"); | ||
| writer.WritePropertyName("patterns"); | ||
| autoentityPatternsConverter.Write(writer, patterns, options); | ||
| } | ||
|
|
||
| AutoentityTemplate? template = value?.Template; | ||
| if (template?.UserProvidedRestOptions is true | ||
| || template?.UserProvidedGraphQLOptions is true | ||
| || template?.UserProvidedHealthOptions is true | ||
| || template?.UserProvidedCacheOptions is true) | ||
| { | ||
| AutoentityTemplateConverter autoentityTemplateConverter = options.GetConverter(typeof(AutoentityTemplate)) as AutoentityTemplateConverter ?? | ||
| throw new JsonException("Failed to get autoentities.template options converter"); | ||
| writer.WritePropertyName("template"); | ||
| autoentityTemplateConverter.Write(writer, template, options); | ||
| } | ||
|
|
||
RubenCerna2079 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (value?.Permissions is not null) | ||
| { | ||
| writer.WritePropertyName("permissions"); | ||
| JsonSerializer.Serialize(writer, value.Permissions, options); | ||
| } | ||
|
|
||
| writer.WriteEndObject(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.