-
Notifications
You must be signed in to change notification settings - Fork 366
Propagate tcgc SerializationOptions for body parameters and responses #10730
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
Draft
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/consume-serialization-options
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70e5ce0
Initial plan
Copilot 77637b6
Consume SerializationOptions for body parameters and responses
Copilot 0978bc4
address review: optional serializationOptions, replace test with json…
Copilot a762fa7
address review: revert nullable, add binary serialization options, MT…
Copilot 37a8feb
use SerializationOptions.Xml in TryGetXmlCollectionNamesForResponse
Copilot 8bf7f5d
add Filename to InputBinarySerializationOptions; move tests; expand e…
Copilot 95973fa
regenerate test libraries to pick up serializationOptions on body par…
Copilot 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
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
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
44 changes: 44 additions & 0 deletions
44
...ator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/InputBinarySerializationOptions.cs
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,44 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.TypeSpec.Generator.Input | ||
| { | ||
| /// <summary> | ||
| /// Describes how a body is serialized as a binary payload (e.g. a file or raw stream). | ||
| /// </summary> | ||
| public class InputBinarySerializationOptions | ||
| { | ||
| public InputBinarySerializationOptions(bool isFile = false, bool? isText = null, IReadOnlyList<string>? contentTypes = null, InputModelProperty? filename = null) | ||
| { | ||
| IsFile = isFile; | ||
| IsText = isText; | ||
| ContentTypes = contentTypes; | ||
| Filename = filename; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Whether this is a file/stream input. | ||
| /// </summary> | ||
| public bool IsFile { get; internal set; } | ||
|
|
||
| /// <summary> | ||
| /// Whether the file contents should be represented as a string or a raw byte stream. | ||
| /// Only set when <see cref="IsFile"/> is <c>true</c>. | ||
| /// </summary> | ||
| public bool? IsText { get; internal set; } | ||
|
|
||
| /// <summary> | ||
| /// The list of inner media types of the file. | ||
| /// Only set when <see cref="IsFile"/> is <c>true</c>. | ||
| /// </summary> | ||
| public IReadOnlyList<string>? ContentTypes { get; internal set; } | ||
|
|
||
| /// <summary> | ||
| /// The model property that represents the filename in the file model. | ||
| /// Only set when <see cref="IsFile"/> is <c>true</c>. | ||
| /// </summary> | ||
| public InputModelProperty? Filename { get; internal set; } | ||
| } | ||
| } |
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
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
51 changes: 51 additions & 0 deletions
51
....Generator.Input/src/InputTypes/Serialization/InputBinarySerializationOptionsConverter.cs
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,51 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.TypeSpec.Generator.Input | ||
| { | ||
| internal sealed class InputBinarySerializationOptionsConverter : JsonConverter<InputBinarySerializationOptions> | ||
| { | ||
| public InputBinarySerializationOptionsConverter() | ||
| { | ||
| } | ||
|
|
||
| public override InputBinarySerializationOptions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| => ReadInputBinarySerializationOptions(ref reader, options); | ||
|
|
||
| public override void Write(Utf8JsonWriter writer, InputBinarySerializationOptions value, JsonSerializerOptions options) | ||
| => throw new NotSupportedException("Writing not supported"); | ||
|
|
||
| private static InputBinarySerializationOptions ReadInputBinarySerializationOptions(ref Utf8JsonReader reader, JsonSerializerOptions options) | ||
| { | ||
| if (reader.TokenType == JsonTokenType.StartObject) | ||
| { | ||
| reader.Read(); | ||
| } | ||
|
|
||
| bool isFile = false; | ||
| bool? isText = null; | ||
| IReadOnlyList<string>? contentTypes = null; | ||
| InputModelProperty? filename = null; | ||
|
|
||
| while (reader.TokenType != JsonTokenType.EndObject) | ||
| { | ||
| var isKnownProperty = reader.TryReadBoolean("isFile", ref isFile) | ||
| || reader.TryReadNullableBoolean("isText", ref isText) | ||
| || reader.TryReadComplexType("contentTypes", options, ref contentTypes) | ||
| || reader.TryReadComplexType("filename", options, ref filename); | ||
|
|
||
| if (!isKnownProperty) | ||
| { | ||
| reader.SkipProperty(); | ||
| } | ||
| } | ||
|
|
||
| return new InputBinarySerializationOptions(isFile, isText, contentTypes, filename); | ||
| } | ||
| } | ||
| } |
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
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.