Skip to content

Commit 77f7c1e

Browse files
committed
query parameter needs import
1 parent dd0e69c commit 77f7c1e

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/main/groovy/com/github/hauner/openapi/spring/model/parameters/QueryParameter.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class QueryParameter {
4343
"@${annotationName}"
4444
}
4545

46+
String getDataTypeImport() {
47+
dataType.import
48+
}
49+
4650
/**
4751
* Is the parameter required?
4852
*

src/main/groovy/com/github/hauner/openapi/spring/writer/InterfaceWriter.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class InterfaceWriter {
6060
if (p.withAnnotation()) {
6161
imports.add (p.annotationWithPackage)
6262
}
63+
64+
imports.add (p.dataTypeImport)
6365
}
6466

6567
if (!ep.response.empty) {

src/test/groovy/com/github/hauner/openapi/spring/writer/InterfaceWriterSpec.groovy

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ import org.springframework.http.ResponseEntity;
117117
""")
118118
}
119119

120-
void "writes RequestParam import" () {
120+
void "writes @RequestParam import" () {
121121
def apiItf = new Interface (name: 'name', endpoints: [
122122
new Endpoint(path: 'path', method: HttpMethod.GET, responses: [new EmptyResponse()],
123123
parameters: [
@@ -135,7 +135,7 @@ import org.springframework.web.bind.annotation.RequestParam;
135135
""")
136136
}
137137

138-
void "does not write @RequestParam annotation import of request parameter that does not want the annotation" () {
138+
void "does not write @RequestParam annotation import of parameter that does not want the annotation" () {
139139
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
140140
new Response (contentType: 'application/json', responseType: new NoneDataType())
141141
], parameters: [
@@ -159,6 +159,30 @@ import org.springframework.web.bind.annotation.RequestParam;
159159
""")
160160
}
161161

162+
void "writes import of request parameter data type" () {
163+
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
164+
new Response (contentType: 'application/json', responseType: new NoneDataType())
165+
], parameters: [
166+
new QueryParameter(name: 'foo', required: false, dataType: new ObjectDataType (
167+
pkg: 'model', type: 'Foo', properties: [
168+
foo1: new StringDataType (),
169+
foo2: new StringDataType ()
170+
]
171+
))
172+
])
173+
174+
def apiItf = new Interface (name: 'name', endpoints: [endpoint])
175+
176+
when:
177+
writer.write (target, apiItf)
178+
179+
then:
180+
def result = extractImports (target.toString ())
181+
result.contains("""\
182+
import model.Foo;
183+
""")
184+
}
185+
162186
void "writes model import"() {
163187
def pkg = 'model.package'
164188
def type = 'Model'

0 commit comments

Comments
 (0)