-
Notifications
You must be signed in to change notification settings - Fork 324
http-client-java, support array encoded as CSV on property #9218
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
weidongxu-microsoft
wants to merge
17
commits into
microsoft:main
Choose a base branch
from
weidongxu-microsoft:http-client-java_support-csv-on-property
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.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
05abb2c
add arrayEncode to Property
weidongxu-microsoft b71290e
add ArrayEncoding
weidongxu-microsoft 26bb131
support element type String
weidongxu-microsoft 66f1c3a
regen
weidongxu-microsoft 5b32626
test by agent
weidongxu-microsoft 03b8567
bug fix
weidongxu-microsoft 441d8b3
regen
weidongxu-microsoft 9515a85
test in cliencore
weidongxu-microsoft 531a42f
log error if element type is not string
weidongxu-microsoft d4ca7ef
remove ClientLocationClientTests to pass nightly build
weidongxu-microsoft cd11ae7
bump dependencies
weidongxu-microsoft 3d0d060
comment
weidongxu-microsoft 086ee5b
unit test for corner cases
weidongxu-microsoft fd843b1
bug fix and regen
weidongxu-microsoft 805e28d
format
weidongxu-microsoft 20bb4c0
one more test
weidongxu-microsoft 883929b
format
weidongxu-microsoft 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
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
39 changes: 39 additions & 0 deletions
39
...or/http-client-generator-clientcore-test/src/test/java/encode/array/EncodeArrayTests.java
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,39 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package encode.array; | ||
|
|
||
| import java.util.List; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public final class EncodeArrayTests { | ||
|
|
||
| private static final List<String> COLORS = List.of("blue", "red", "green"); | ||
|
|
||
| private final ArrayClient client = new ArrayClientBuilder().buildArrayClient(); | ||
|
|
||
| @Test | ||
| public void commaDelimitedProperty() { | ||
| CommaDelimitedArrayProperty response = client.commaDelimited(new CommaDelimitedArrayProperty(COLORS)); | ||
| Assertions.assertEquals(COLORS, response.getValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void spaceDelimitedProperty() { | ||
| SpaceDelimitedArrayProperty response = client.spaceDelimited(new SpaceDelimitedArrayProperty(COLORS)); | ||
| Assertions.assertEquals(COLORS, response.getValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void pipeDelimitedProperty() { | ||
| PipeDelimitedArrayProperty response = client.pipeDelimited(new PipeDelimitedArrayProperty(COLORS)); | ||
| Assertions.assertEquals(COLORS, response.getValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void newlineDelimitedProperty() { | ||
| NewlineDelimitedArrayProperty response = client.newlineDelimited(new NewlineDelimitedArrayProperty(COLORS)); | ||
| Assertions.assertEquals(COLORS, response.getValue()); | ||
| } | ||
| } |
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
60 changes: 60 additions & 0 deletions
60
...va/com/microsoft/typespec/http/client/generator/core/model/clientmodel/ArrayEncoding.java
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,60 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.typespec.http.client.generator.core.model.clientmodel; | ||
|
|
||
| /** | ||
| * Known array encoding strategies supported by the generator. | ||
| */ | ||
| public enum ArrayEncoding { | ||
| PIPE_DELIMITED("pipeDelimited", "|", "\\\\|"), | ||
weidongxu-microsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| SPACE_DELIMITED("spaceDelimited", " "), | ||
| COMMA_DELIMITED("commaDelimited", ","), | ||
| NEWLINE_DELIMITED("newlineDelimited", "\\n"); | ||
weidongxu-microsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private final String value; | ||
| private final String delimiter; | ||
| private final String escapedDelimiter; | ||
|
|
||
| ArrayEncoding(String value, String delimiter) { | ||
| this.value = value; | ||
| this.delimiter = delimiter; | ||
| this.escapedDelimiter = delimiter; | ||
| } | ||
|
|
||
| ArrayEncoding(String value, String delimiter, String escapedDelimiter) { | ||
| this.value = value; | ||
| this.delimiter = delimiter; | ||
| this.escapedDelimiter = escapedDelimiter; | ||
| } | ||
|
|
||
| public String value() { | ||
| return this.value; | ||
| } | ||
|
|
||
| public String getDelimiter() { | ||
| return this.delimiter; | ||
| } | ||
|
|
||
| public String getEscapedDelimiter() { | ||
| return escapedDelimiter; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return this.value(); | ||
| } | ||
|
|
||
| public static ArrayEncoding fromValue(String value) { | ||
| if (value == null) { | ||
| return null; | ||
| } | ||
|
|
||
| for (ArrayEncoding v : values()) { | ||
| if (v.value().equalsIgnoreCase(value)) { | ||
| return v; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both
nulland""would map to same encoded string.On the other direction, currently we map e.g.
","to["", ""]for string element.For other type that extend string, we may choose differently (or even break this behavior on string type too), e.g.
","on utcDateTime/uuid can only be[null, null]Just hope service knows what it does on these...