Skip to content

fixed missing @ResponseBody data type import #55

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
@@ -1,5 +1,5 @@
/*
* Copyright 2019 the original authors
* Copyright 2019-2020 the original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,7 +66,7 @@ class InterfaceWriter {

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

if (!ep.response.empty) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 the original authors
* Copyright 2019-2020 the original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@ 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.MappedDataType
import com.github.hauner.openapi.spring.model.datatypes.NoneDataType
import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
import com.github.hauner.openapi.spring.model.datatypes.StringDataType
Expand Down Expand Up @@ -160,9 +161,33 @@ import org.springframework.web.bind.annotation.RequestParam;
""")
}

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())
], parameters: [
new QueryParameter(name: 'foo', required: false, dataType: new ObjectDataType (
pkg: 'model', type: 'Foo', properties: [
foo1: new StringDataType (),
foo2: new StringDataType ()
]
))
])

def apiItf = new Interface (name: 'name', endpoints: [endpoint])

when:
writer.write (target, apiItf)

then:
def result = extractImports (target.toString ())
result.contains("""\
import model.Foo;
""")
}

void "writes @RequestBody import" () {
def apiItf = new Interface (name: 'name', endpoints: [
new Endpoint(path: 'path', method: HttpMethod.GET, responses: [new EmptyResponse()],
new Endpoint(path: '/foo', method: HttpMethod.GET, responses: [new EmptyResponse()],
requestBodies: [
new RequestBody(
contentType: 'plain/text',
Expand All @@ -182,16 +207,16 @@ import org.springframework.web.bind.annotation.RequestBody;
""")
}

void "writes import of request parameter data type" () {
void "writes import of request body data type" () {
def endpoint = new Endpoint (path: '/foo', method: HttpMethod.GET, responses: [
new Response (contentType: 'application/json', responseType: new NoneDataType())
], parameters: [
new QueryParameter(name: 'foo', required: false, dataType: new ObjectDataType (
pkg: 'model', type: 'Foo', properties: [
foo1: new StringDataType (),
foo2: new StringDataType ()
]
))
new EmptyResponse ()
], requestBodies: [
new RequestBody (
contentType: 'plain/text',
requestBodyType: new MappedDataType (
pkg: 'com.github.hauner.openapi', type: 'Bar'),
required: true
)
])

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

Expand Down