Skip to content

fixed missing @RequestBody import #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class InterfaceWriter {
imports.addAll (p.dataTypeImports)
}

ep.requestBodies.each { b ->
imports.add (b.annotationWithPackage)
// imports.addAll (b.imports)
}

if (!ep.response.empty) {
imports.addAll (ep.response.imports)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.github.hauner.openapi.spring.writer
import com.github.hauner.openapi.spring.model.Endpoint
import com.github.hauner.openapi.spring.model.HttpMethod
import com.github.hauner.openapi.spring.model.Interface
import com.github.hauner.openapi.spring.model.RequestBody
import com.github.hauner.openapi.spring.model.Response
import com.github.hauner.openapi.spring.model.datatypes.NoneDataType
import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
Expand Down Expand Up @@ -159,6 +160,28 @@ import org.springframework.web.bind.annotation.RequestParam;
""")
}

void "writes @RequestBody import" () {
def apiItf = new Interface (name: 'name', endpoints: [
new Endpoint(path: 'path', method: HttpMethod.GET, responses: [new EmptyResponse()],
requestBodies: [
new RequestBody(
contentType: 'plain/text',
requestBodyType: new StringDataType(),
required: true
)
])
])

when:
writer.write (target, apiItf)

then:
def result = extractImports (target.toString ())
result.contains("""\
import org.springframework.web.bind.annotation.RequestBody;
""")
}

void "writes import of request parameter data type" () {
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
new Response (contentType: 'application/json', responseType: new NoneDataType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import generated.model.Book;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

public interface Api {

Expand Down