Skip to content

Commit 9c3d539

Browse files
authored
Merge pull request #55 from hauner/#53
fixed missing @responsebody data type import
2 parents acd25b7 + e2df590 commit 9c3d539

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original authors
2+
* Copyright 2019-2020 the original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@ class InterfaceWriter {
6666

6767
ep.requestBodies.each { b ->
6868
imports.add (b.annotationWithPackage)
69-
// imports.addAll (b.imports)
69+
imports.addAll (b.imports)
7070
}
7171

7272
if (!ep.response.empty) {

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original authors
2+
* Copyright 2019-2020 the original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import com.github.hauner.openapi.spring.model.HttpMethod
2121
import com.github.hauner.openapi.spring.model.Interface
2222
import com.github.hauner.openapi.spring.model.RequestBody
2323
import com.github.hauner.openapi.spring.model.Response
24+
import com.github.hauner.openapi.spring.model.datatypes.MappedDataType
2425
import com.github.hauner.openapi.spring.model.datatypes.NoneDataType
2526
import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
2627
import com.github.hauner.openapi.spring.model.datatypes.StringDataType
@@ -160,9 +161,33 @@ import org.springframework.web.bind.annotation.RequestParam;
160161
""")
161162
}
162163

164+
void "writes import of request parameter data type" () {
165+
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
166+
new Response (contentType: 'application/json', responseType: new NoneDataType())
167+
], parameters: [
168+
new QueryParameter(name: 'foo', required: false, dataType: new ObjectDataType (
169+
pkg: 'model', type: 'Foo', properties: [
170+
foo1: new StringDataType (),
171+
foo2: new StringDataType ()
172+
]
173+
))
174+
])
175+
176+
def apiItf = new Interface (name: 'name', endpoints: [endpoint])
177+
178+
when:
179+
writer.write (target, apiItf)
180+
181+
then:
182+
def result = extractImports (target.toString ())
183+
result.contains("""\
184+
import model.Foo;
185+
""")
186+
}
187+
163188
void "writes @RequestBody import" () {
164189
def apiItf = new Interface (name: 'name', endpoints: [
165-
new Endpoint(path: 'path', method: HttpMethod.GET, responses: [new EmptyResponse()],
190+
new Endpoint(path: '/foo', method: HttpMethod.GET, responses: [new EmptyResponse()],
166191
requestBodies: [
167192
new RequestBody(
168193
contentType: 'plain/text',
@@ -182,16 +207,16 @@ import org.springframework.web.bind.annotation.RequestBody;
182207
""")
183208
}
184209

185-
void "writes import of request parameter data type" () {
210+
void "writes import of request body data type" () {
186211
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
187-
new Response (contentType: 'application/json', responseType: new NoneDataType())
188-
], parameters: [
189-
new QueryParameter(name: 'foo', required: false, dataType: new ObjectDataType (
190-
pkg: 'model', type: 'Foo', properties: [
191-
foo1: new StringDataType (),
192-
foo2: new StringDataType ()
193-
]
194-
))
212+
new EmptyResponse ()
213+
], requestBodies: [
214+
new RequestBody (
215+
contentType: 'plain/text',
216+
requestBodyType: new MappedDataType (
217+
pkg: 'com.github.hauner.openapi', type: 'Bar'),
218+
required: true
219+
)
195220
])
196221

197222
def apiItf = new Interface (name: 'name', endpoints: [endpoint])
@@ -202,7 +227,7 @@ import org.springframework.web.bind.annotation.RequestBody;
202227
then:
203228
def result = extractImports (target.toString ())
204229
result.contains("""\
205-
import model.Foo;
230+
import com.github.hauner.openapi.Bar;
206231
""")
207232
}
208233

0 commit comments

Comments
 (0)