Skip to content

Commit ef54c0b

Browse files
authored
feat: customize SDK generation (#174)
1 parent a2d897b commit ef54c0b

File tree

63 files changed

+2329
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2329
-1
lines changed

.github/workflows/generate-and-publish-sdk.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@ on:
99
E.g., 1.0.0, 1.0.1, 1.0.0-SNAPSHOT, etc.
1010
required: true
1111
type: string
12-
12+
sdk_repo_ref:
13+
description: |
14+
Branch or tag to checkout on the `expediagroup-sdk-core` repository.
15+
Leave empty to use the default branch.
16+
type: string
17+
default: ''
18+
ref:
19+
description: |
20+
Branch or tag to checkout on the provided repository.
21+
Leave empty to use the default branch.
22+
type: string
23+
default: ''
1324
jobs:
1425
generate-and-publish:
1526
uses: ExpediaGroup/expediagroup-java-sdk/.github/workflows/selfserve-full-workflow.yaml@main
@@ -18,3 +29,5 @@ jobs:
1829
name: rapid
1930
version: ${{ inputs.version }}
2031
transformations: "-th -te /v3 --operationIdsToTags"
32+
repository: 'ExpediaGroup/rapid-java-sdk'
33+
sdk_repo_ref: ${{ inputs.sdk_repo_ref }}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2022 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.expediagroup.sdk.domain.rapid
17+
18+
import com.expediagroup.sdk.core.client.BaseRapidClient
19+
import com.expediagroup.sdk.core.client.ClientHelpers
20+
import com.expediagroup.sdk.core.constant.HeaderKey
21+
import com.expediagroup.sdk.core.model.Response
22+
23+
@Deprecated("Use operations and responses instead")
24+
class RapidHelpers(client: BaseRapidClient) : ClientHelpers(client) {
25+
/** Extracts the token parameter from a URL string if it exists; otherwise, returns null. */
26+
@Deprecated("Construct operation using Link", ReplaceWith("Operation(link: Link)"))
27+
fun extractToken(url: String): String? = Regex("token=([^&]*)").find(url)?.groupValues?.getOrNull(1)
28+
29+
/** Extracts the room booking ID from a URL string if it exists; otherwise, returns null. */
30+
@Deprecated("Construct operation using Link", ReplaceWith("Operation(link: Link)"))
31+
fun extractRoomBookingId(url: String): String? = Regex("rooms\\/([a-z0-9-]+)").find(url)?.groupValues?.getOrNull(1)
32+
33+
/** Extracts the transaction ID from a response object if it exists; otherwise, returns null. */
34+
@Deprecated("Get transactionId from response headers", ReplaceWith("response.headers[transaction-id]"))
35+
fun <T> extractTransactionId(response: Response<T>): String? = response.headers[HeaderKey.TRANSACTION_ID]?.first()
36+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright (C) 2022 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.expediagroup.sdk.domain.rapid
17+
18+
import com.expediagroup.sdk.core.client.BaseRapidClient
19+
import com.expediagroup.sdk.core.configuration.RapidClientConfiguration
20+
import com.expediagroup.sdk.core.model.Response
21+
import io.ktor.client.statement.HttpResponse
22+
import org.junit.jupiter.api.Assertions.assertEquals
23+
import org.junit.jupiter.api.Assertions.assertNull
24+
import org.junit.jupiter.api.Nested
25+
import org.junit.jupiter.api.Test
26+
27+
class RapidHelpersTest {
28+
companion object {
29+
private val rapidClient =
30+
object : BaseRapidClient("dummy", RapidClientConfiguration()) {
31+
override suspend fun throwServiceException(
32+
response: HttpResponse,
33+
operationId: String
34+
) {
35+
throw UnsupportedOperationException()
36+
}
37+
}
38+
39+
val rapidHelpers = RapidHelpers(rapidClient)
40+
}
41+
42+
@Nested
43+
inner class TestExtractToken {
44+
@Test
45+
fun `Verify extractToken returns token when present`() {
46+
assertEquals("12345", rapidHelpers.extractToken("https://www.example.com?token=12345"))
47+
}
48+
49+
@Test
50+
fun `Verify extractToken returns null when no token is present`() {
51+
assertNull(rapidHelpers.extractToken("https://www.example.com"))
52+
}
53+
54+
@Test
55+
fun `Verify extractToken returns an empty string when token is empty`() {
56+
assertEquals("", rapidHelpers.extractToken("https://www.example.com?token="))
57+
}
58+
59+
@Test
60+
fun `Verify extractToken returns token when it is not the first parameter`() {
61+
assertEquals("12345", rapidHelpers.extractToken("https://www.example.com?foo=bar&token=12345"))
62+
}
63+
64+
@Test
65+
fun `Verify extractToken returns null when token is not provided but other parameters are`() {
66+
assertNull(rapidHelpers.extractToken("https://www.example.com?foo=bar"))
67+
}
68+
69+
@Test
70+
fun `Verify extractToken returns null when token is not provided but multiple other parameters are`() {
71+
assertNull(rapidHelpers.extractToken("https://www.example.com?foo=bar&baz=qux"))
72+
}
73+
74+
@Test
75+
fun `Verify extractToken returns it when token is not the last parameter`() {
76+
assertEquals("12345", rapidHelpers.extractToken("https://www.example.com?token=12345&foo=bar"))
77+
}
78+
79+
@Test
80+
fun `extractToken should handle multiple parameters and return the correct token`() {
81+
assertEquals("xyz456", rapidHelpers.extractToken("https://example.com/page?param1=value1&token=xyz456&param2=value2"))
82+
}
83+
84+
@Test
85+
fun `extractToken should handle URL-encoded characters in the token`() {
86+
assertEquals("abc%20456", rapidHelpers.extractToken("https://example.com/page?token=abc%20456&param=value"))
87+
}
88+
89+
@Test
90+
fun `extractToken should handle different token parameter names`() {
91+
assertEquals("abcd1234", rapidHelpers.extractToken("https://example.com/page?access_token=abcd1234"))
92+
assertEquals("efgh5678", rapidHelpers.extractToken("https://example.com/page?api_token=efgh5678"))
93+
}
94+
95+
@Test
96+
fun `extractToken should handle multiple tokens`() {
97+
assertEquals("abcd1234", rapidHelpers.extractToken("https://example.com/page?token=abcd1234&token=efgh5678"))
98+
assertEquals("efgh5678", rapidHelpers.extractToken("https://example.com/page?api_token=efgh5678&access_token=abcd1234"))
99+
}
100+
101+
@Test
102+
fun `extractToken should get only the query param token`() {
103+
assertNull(rapidHelpers.extractToken("https://example.com/tokenPage?query=tokenValue"))
104+
}
105+
106+
@Test
107+
fun `extractToken should return an empty string when token is empty and other parameters are present`() {
108+
assertEquals("", rapidHelpers.extractToken("https://www.example.com?foo=bar&token="))
109+
}
110+
111+
@Test
112+
fun `extractToken should return an empty string when token is empty in the middle of other parameters`() {
113+
assertEquals("", rapidHelpers.extractToken("https://www.example.com?foo=bar&token=&baz=qux"))
114+
}
115+
}
116+
117+
@Nested
118+
inner class TestExtractRoomBookingId {
119+
@Test
120+
fun `Verify extractRoomBookingId returns roomId when present`() {
121+
assertEquals("abc-123-xyz", rapidHelpers.extractRoomBookingId("https://www.example.com/rooms/abc-123-xyz?token=abc"))
122+
}
123+
124+
@Test
125+
fun `Verify extractRoomBookingId returns null when roomId is not present`() {
126+
assertNull(rapidHelpers.extractRoomBookingId("https://www.example.com?token=abc"))
127+
}
128+
}
129+
130+
@Nested
131+
inner class TestExtractTransactionId {
132+
@Test
133+
fun `Verify extractTransactionId returns transactionId when present`() {
134+
Response<String>(
135+
200,
136+
"body",
137+
mapOf("transaction-id" to listOf("abc-123-xyz"))
138+
).let { assertEquals("abc-123-xyz", rapidHelpers.extractTransactionId(it)) }
139+
}
140+
141+
@Test
142+
fun `Verify extractTransactionId returns null when transactionId is not present`() {
143+
Response<String>(
144+
200,
145+
"body",
146+
mapOf("some-header" to listOf("some data"))
147+
).let { assertNull(rapidHelpers.extractTransactionId(it)) }
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)