Skip to content

Commit cd6403f

Browse files
fzakariapriteshkp
authored andcommitted
Add support for UUID in encodePathParam
Swagger has support for strings with format `uuid`. This adds support for overloading the encodePathParam to allow UUIDs as method argument. Also added some sensible defaults to the gitignore for IntelliJ Signed-off-by: Farid Zakaria <farid.m.zakaria@gmail.com>
1 parent 064933d commit cd6403f

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
*.iml
3+
*/target

bmc-common/src/main/java/com/oracle/bmc/util/internal/HttpUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static com.google.common.net.UrlEscapers.urlPathSegmentEscaper;
77

88
import java.util.Date;
9+
import java.util.UUID;
910

1011
import javax.annotation.Nonnull;
1112

@@ -60,6 +61,16 @@ public static String encodePathSegment(@Nonnull Character pathSegment) {
6061
return urlPathSegmentEscaper().escape(pathSegment.toString());
6162
}
6263

64+
/**
65+
* Encodes a path segment.
66+
*
67+
* @param pathSegment The path segment to encode.
68+
* @return The encoded path segment.
69+
*/
70+
public static String encodePathSegment(@Nonnull UUID pathSegment) {
71+
return urlPathSegmentEscaper().escape(pathSegment.toString());
72+
}
73+
6374
/**
6475
* Attempts to encode a query param if it is a String. This does not try
6576
* to encode non-String values as Jersey uses different serializers

bmc-common/src/test/java/com/oracle/bmc/util/internal/HttpUtilsTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import org.junit.Test;
1010

11+
import java.util.UUID;
12+
1113
public class HttpUtilsTest {
1214

1315
@Test
@@ -31,6 +33,12 @@ public void encodePathSegment_numbers() {
3133
assertEquals("20", HttpUtils.encodePathSegment((short) 20));
3234
}
3335

36+
@Test
37+
public void encodePathSegment_uuid() {
38+
UUID uuid = UUID.randomUUID();
39+
assertEquals(uuid.toString(), HttpUtils.encodePathSegment(uuid));
40+
}
41+
3442
@Test
3543
public void encodePathSegment_character() {
3644
assertEquals("d", HttpUtils.encodePathSegment('d'));

0 commit comments

Comments
 (0)