Skip to content

Commit ac8b1dd

Browse files
authored
Merge pull request #54 from hauner/#52
fixed missing @RequestBody import
2 parents c46f16d + 723f435 commit ac8b1dd

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ class InterfaceWriter {
6464
imports.addAll (p.dataTypeImports)
6565
}
6666

67+
ep.requestBodies.each { b ->
68+
imports.add (b.annotationWithPackage)
69+
// imports.addAll (b.imports)
70+
}
71+
6772
if (!ep.response.empty) {
6873
imports.addAll (ep.response.imports)
6974
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.github.hauner.openapi.spring.writer
1919
import com.github.hauner.openapi.spring.model.Endpoint
2020
import com.github.hauner.openapi.spring.model.HttpMethod
2121
import com.github.hauner.openapi.spring.model.Interface
22+
import com.github.hauner.openapi.spring.model.RequestBody
2223
import com.github.hauner.openapi.spring.model.Response
2324
import com.github.hauner.openapi.spring.model.datatypes.NoneDataType
2425
import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
@@ -159,6 +160,28 @@ import org.springframework.web.bind.annotation.RequestParam;
159160
""")
160161
}
161162

163+
void "writes @RequestBody import" () {
164+
def apiItf = new Interface (name: 'name', endpoints: [
165+
new Endpoint(path: 'path', method: HttpMethod.GET, responses: [new EmptyResponse()],
166+
requestBodies: [
167+
new RequestBody(
168+
contentType: 'plain/text',
169+
requestBodyType: new StringDataType(),
170+
required: true
171+
)
172+
])
173+
])
174+
175+
when:
176+
writer.write (target, apiItf)
177+
178+
then:
179+
def result = extractImports (target.toString ())
180+
result.contains("""\
181+
import org.springframework.web.bind.annotation.RequestBody;
182+
""")
183+
}
184+
162185
void "writes import of request parameter data type" () {
163186
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
164187
new Response (contentType: 'application/json', responseType: new NoneDataType())

src/testInt/resources/params-request-body/generated/api/Api.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import generated.model.Book;
99
import org.springframework.http.ResponseEntity;
1010
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestBody;
1112

1213
public interface Api {
1314

0 commit comments

Comments
 (0)