-
Notifications
You must be signed in to change notification settings - Fork 334
Add support for array encoding with @encode(ArrayEncoding.*) decorator #9430
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
+472
−33
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
b4f5cd7
minor: added long path support to prerequisite
radhgupta ccef568
Merge branch 'main' of https://github.com/microsoft/typespec
radhgupta 3486047
Merge branch 'main' of https://github.com/microsoft/typespec
radhgupta 25e823a
Merge branch 'main' of https://github.com/microsoft/typespec
radhgupta 7958158
Merge branch 'main' of https://github.com/microsoft/typespec
radhgupta 5227fce
Merge branch 'main' of https://github.com/microsoft/typespec
radhgupta 175f199
Merge remote-tracking branch 'upstream/main'
radhgupta b39a7f4
Merge branch 'main' of https://github.com/microsoft/typespec
radhgupta 699978e
Merge branch 'main' of https://github.com/microsoft/typespec
radhgupta d0909f3
Merge remote-tracking branch 'upstream/main'
radhgupta 17ae707
Merge remote-tracking branch 'upstream/main'
radhgupta 339819f
Merge remote-tracking branch 'upstream/main'
radhgupta 9cb6c4c
Merge remote-tracking branch 'upstream/main'
radhgupta 6606677
csv encoding
radhgupta fbbfaf5
geenrate script
radhgupta 4be7888
serealization format used
radhgupta b2757da
Refactoring
radhgupta 434bb4a
refactoring
radhgupta 1e737ab
Merge branch 'main' into csv-encoding
radhgupta 4013b4a
added unit tests
radhgupta 1ca3af7
Merge branch 'csv-encoding' of https://github.com/radhgupta/typespec …
radhgupta 759da07
refactored code
radhgupta 38659d3
added unit test
radhgupta 7d6c272
used input convert to convert form str to enum
radhgupta e64270a
removed tryparse
radhgupta 756378c
removed tryparse
radhgupta 31225bd
removed tryparse
radhgupta 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
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
242 changes: 217 additions & 25 deletions
242
.../Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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
41 changes: 41 additions & 0 deletions
41
...nerator/Microsoft.TypeSpec.Generator.Input/src/Extensions/ArrayKnownEncodingExtensions.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,41 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.TypeSpec.Generator.Input.Extensions | ||
| { | ||
| public static class ArrayKnownEncodingExtensions | ||
| { | ||
| /// <summary> | ||
| /// Converts ArrayKnownEncoding to SerializationFormat. | ||
| /// </summary> | ||
| public static SerializationFormat ToSerializationFormat(this ArrayKnownEncoding encoding) | ||
| { | ||
| return encoding switch | ||
| { | ||
| ArrayKnownEncoding.CommaDelimited => SerializationFormat.Array_CommaDelimited, | ||
| ArrayKnownEncoding.SpaceDelimited => SerializationFormat.Array_SpaceDelimited, | ||
| ArrayKnownEncoding.PipeDelimited => SerializationFormat.Array_PipeDelimited, | ||
| ArrayKnownEncoding.NewlineDelimited => SerializationFormat.Array_NewlineDelimited, | ||
| _ => throw new ArgumentOutOfRangeException(nameof(encoding), encoding, "Unknown array encoding") | ||
| }; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get the delimiter string for array serialization format. | ||
| /// </summary> | ||
| public static bool TryGetDelimiter(SerializationFormat format, out string? delimiter) | ||
| { | ||
| delimiter = format switch | ||
| { | ||
| SerializationFormat.Array_CommaDelimited => ",", | ||
| SerializationFormat.Array_SpaceDelimited => " ", | ||
| SerializationFormat.Array_PipeDelimited => "|", | ||
| SerializationFormat.Array_NewlineDelimited => "\n", | ||
| _ => null | ||
| }; | ||
| return delimiter != null; | ||
| } | ||
| } | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
...-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/ArrayKnownEncoding.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,31 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.TypeSpec.Generator.Input | ||
| { | ||
| /// <summary> | ||
| /// Represents the known encoding formats for arrays. | ||
| /// </summary> | ||
| public enum ArrayKnownEncoding | ||
| { | ||
| /// <summary> | ||
| /// Comma-delimited array encoding | ||
| /// </summary> | ||
| CommaDelimited, | ||
|
|
||
| /// <summary> | ||
| /// Space-delimited array encoding | ||
| /// </summary> | ||
| SpaceDelimited, | ||
|
|
||
| /// <summary> | ||
| /// Pipe-delimited array encoding | ||
| /// </summary> | ||
| PipeDelimited, | ||
|
|
||
| /// <summary> | ||
| /// Newline-delimited array encoding | ||
| /// </summary> | ||
| NewlineDelimited | ||
| } | ||
| } |
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
62 changes: 62 additions & 0 deletions
62
...-client-csharp/generator/TestProjects/Spector.Tests/Http/Encode/Array/EncodeArrayTests.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,62 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.ClientModel; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Encode._Array; | ||
| using Encode._Array._Property; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace TestProjects.Spector.Tests.Http.Encode.Array | ||
| { | ||
| public class EncodeArrayTests : SpectorTestBase | ||
| { | ||
| [SpectorTest] | ||
| public Task CommaDelimited() => Test(async (host) => | ||
| { | ||
| var testData = new List<string> { "blue", "red", "green" }; | ||
| var body = new CommaDelimitedArrayProperty(testData); | ||
|
|
||
| ClientResult<CommaDelimitedArrayProperty> result = await new ArrayClient(host, null).GetPropertyClient().CommaDelimitedAsync(body); | ||
| Assert.AreEqual(200, result.GetRawResponse().Status); | ||
| Assert.AreEqual(testData, result.Value.Value); | ||
| }); | ||
|
|
||
| [SpectorTest] | ||
| public Task SpaceDelimited() => Test(async (host) => | ||
| { | ||
| var testData = new List<string> { "blue", "red", "green" }; | ||
| var body = new SpaceDelimitedArrayProperty(testData); | ||
|
|
||
| ClientResult<SpaceDelimitedArrayProperty> result = await new ArrayClient(host, null).GetPropertyClient().SpaceDelimitedAsync(body); | ||
| Assert.AreEqual(200, result.GetRawResponse().Status); | ||
| Assert.AreEqual(testData, result.Value.Value); | ||
| }); | ||
|
|
||
| [SpectorTest] | ||
| public Task PipeDelimited() => Test(async (host) => | ||
| { | ||
| var testData = new List<string> { "blue", "red", "green" }; | ||
| var body = new PipeDelimitedArrayProperty(testData); | ||
|
|
||
| ClientResult<PipeDelimitedArrayProperty> result = await new ArrayClient(host, null).GetPropertyClient().PipeDelimitedAsync(body); | ||
| Assert.AreEqual(200, result.GetRawResponse().Status); | ||
| Assert.AreEqual(testData, result.Value.Value); | ||
| }); | ||
|
|
||
| [SpectorTest] | ||
| public Task NewlineDelimited() => Test(async (host) => | ||
| { | ||
| var testData = new List<string> { "blue", "red", "green" }; | ||
| var body = new NewlineDelimitedArrayProperty(testData); | ||
|
|
||
| ClientResult<NewlineDelimitedArrayProperty> result = await new ArrayClient(host, null).GetPropertyClient().NewlineDelimitedAsync(body); | ||
| Assert.AreEqual(200, result.GetRawResponse().Status); | ||
| Assert.AreEqual(testData, result.Value.Value); | ||
| }); | ||
|
|
||
|
|
||
| } | ||
| } |
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.
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.