1
1
/*
2
- * Copyright 2019 the original authors
2
+ * Copyright 2019-2020 the original authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import com.github.hauner.openapi.spring.model.HttpMethod
21
21
import com.github.hauner.openapi.spring.model.Interface
22
22
import com.github.hauner.openapi.spring.model.RequestBody
23
23
import com.github.hauner.openapi.spring.model.Response
24
+ import com.github.hauner.openapi.spring.model.datatypes.MappedDataType
24
25
import com.github.hauner.openapi.spring.model.datatypes.NoneDataType
25
26
import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
26
27
import com.github.hauner.openapi.spring.model.datatypes.StringDataType
@@ -160,9 +161,33 @@ import org.springframework.web.bind.annotation.RequestParam;
160
161
""" )
161
162
}
162
163
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
+
163
188
void " writes @RequestBody import" () {
164
189
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 ()],
166
191
requestBodies : [
167
192
new RequestBody (
168
193
contentType : ' plain/text' ,
@@ -182,16 +207,16 @@ import org.springframework.web.bind.annotation.RequestBody;
182
207
""" )
183
208
}
184
209
185
- void " writes import of request parameter data type" () {
210
+ void " writes import of request body data type" () {
186
211
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
+ )
195
220
])
196
221
197
222
def apiItf = new Interface (name : ' name' , endpoints : [endpoint])
@@ -202,7 +227,7 @@ import org.springframework.web.bind.annotation.RequestBody;
202
227
then :
203
228
def result = extractImports (target. toString ())
204
229
result. contains(""" \
205
- import model.Foo ;
230
+ import com.github.hauner.openapi.Bar ;
206
231
""" )
207
232
}
208
233
0 commit comments