Skip to content

Commit 8b24632

Browse files
authored
Merge pull request #145 from agologan/master
2 parents 54394ee + a7ef162 commit 8b24632

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isQueryParam}}@retrofit2.http.Query("{{baseName}}") {{#collectionFormat}}{{^isCollectionFormatMulti}}@{{{collectionFormat.toUpperCase}}} {{/isCollectionFormatMulti}}{{/collectionFormat}}{{paramName}}: {{{dataType}}}{{/isQueryParam}}
1+
{{#isQueryParam}}@retrofit2.http.Query("{{baseName}}") {{#collectionFormat}}{{^isCollectionFormatMulti}}@{{{collectionFormat.toUpperCase}}} {{/isCollectionFormatMulti}}{{/collectionFormat}}{{paramName}}: {{{dataType}}}{{^required}} = null{{/required}}{{/isQueryParam}}

samples/junit-tests/src/main/java/com/yelp/codegen/generatecodesamples/apis/ResourceApi.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ interface ResourceApi {
116116
)
117117
@GET("/symbols/in/parameter/name")
118118
fun getSymbolsInParameterName(
119-
@retrofit2.http.Query("parameter") parameter: String?,
120-
@retrofit2.http.Query("brackets[]") brackets: String?,
121-
@retrofit2.http.Query("brackets[withText]") bracketsWithText: String?,
122-
@retrofit2.http.Query("dot.") dot: String?,
123-
@retrofit2.http.Query("dot.withText") dotWithText: String?
119+
@retrofit2.http.Query("parameter") parameter: String? = null,
120+
@retrofit2.http.Query("brackets[]") brackets: String? = null,
121+
@retrofit2.http.Query("brackets[withText]") bracketsWithText: String? = null,
122+
@retrofit2.http.Query("dot.") dot: String? = null,
123+
@retrofit2.http.Query("dot.withText") dotWithText: String? = null
124124
): Completable
125125
/**
126126
* The endpoint is owned by junittests service owner

samples/junit-tests/src/test/java/com/yelp/codegen/generatecodesamples/ValidParameterTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.yelp.codegen.generatecodesamples
33
import com.yelp.codegen.generatecodesamples.apis.ResourceApi
44
import com.yelp.codegen.generatecodesamples.tools.MockServerApiRule
55
import okhttp3.mockwebserver.MockResponse
6+
import org.junit.Assert.assertFalse
67
import org.junit.Assert.assertNull
78
import org.junit.Assert.assertTrue
89
import org.junit.Rule
@@ -36,4 +37,22 @@ class ValidParameterTest {
3637
assertTrue("dot.=testDot" in requestPath)
3738
assertTrue("dot.withText=testDotWithText" in requestPath)
3839
}
40+
41+
@Test
42+
fun optionalParameters() {
43+
mockServerRule.server.enqueue(MockResponse())
44+
45+
val defaultApi = mockServerRule.getApi<ResourceApi>()
46+
val pet = defaultApi.getSymbolsInParameterName().blockingGet()
47+
48+
val requestPath = mockServerRule.server.takeRequest().path
49+
assertNull(pet)
50+
51+
// No parameters should be present in the path
52+
assertFalse("parameter=" in requestPath)
53+
assertFalse("brackets%5B%5D=" in requestPath)
54+
assertFalse("brackets%5BwithText%5D=" in requestPath)
55+
assertFalse("dot.=" in requestPath)
56+
assertFalse("dot.withText=" in requestPath)
57+
}
3958
}

0 commit comments

Comments
 (0)