Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit 93806f5

Browse files
committed
write additional annotation import
1 parent 37bbd0c commit 93806f5

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/main/groovy/com/github/hauner/openapi/core/writer/java/InterfaceWriter.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.github.hauner.openapi.core.framework.FrameworkAnnotations
2020
import com.github.hauner.openapi.core.converter.ApiOptions
2121
import com.github.hauner.openapi.core.model.Endpoint
2222
import com.github.hauner.openapi.core.model.Interface
23+
import com.github.hauner.openapi.core.model.parameters.AdditionalParameter
2324
import io.openapiprocessor.core.writer.java.DefaultImportFilter
2425
import io.openapiprocessor.core.writer.java.ImportFilter
2526

@@ -78,6 +79,10 @@ class InterfaceWriter {
7879
imports.add (annotations.getAnnotation (p).fullyQualifiedName)
7980
}
8081

82+
if (p instanceof AdditionalParameter && p.hasAdditionalAnnotation ()) {
83+
imports.addAll (p.annotationDataType.imports)
84+
}
85+
8186
imports.addAll (p.dataTypeImports)
8287
}
8388

src/test/groovy/com/github/hauner/openapi/core/writer/java/InterfaceWriterSpec.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.github.hauner.openapi.core.model.HttpMethod
2525
import com.github.hauner.openapi.core.model.Interface
2626
import com.github.hauner.openapi.core.model.RequestBody
2727
import com.github.hauner.openapi.core.model.Response
28+
import com.github.hauner.openapi.core.model.datatypes.AnnotationDataType
2829
import com.github.hauner.openapi.core.model.datatypes.MappedDataType
2930
import com.github.hauner.openapi.core.model.datatypes.NoneDataType
3031
import com.github.hauner.openapi.core.model.datatypes.ObjectDataType
@@ -219,6 +220,31 @@ import model.Foo;
219220
""")
220221
}
221222

223+
void "writes additional parameter annotation import" () {
224+
// annotations.getAnnotation (_) >> new FrameworkAnnotation(name: 'Parameter', pkg: 'annotation')
225+
226+
def itf = intrface ('Foo') {
227+
endpoint ('/foo') {
228+
parameters {
229+
add {
230+
name ('bar')
231+
type (new StringDataType())
232+
annotation (new AnnotationDataType (pkg: 'bar', type: 'Bar', parameters: '()'))
233+
}
234+
}
235+
}
236+
}
237+
238+
when:
239+
writer.write (target, itf)
240+
241+
then:
242+
def result = extractImports (target.toString ())
243+
result.contains("""\
244+
import bar.Bar;
245+
""")
246+
}
247+
222248
void "writes request body annotation import" () {
223249
annotations.getAnnotation (_) >> new FrameworkAnnotation(name: 'Body', pkg: 'annotation')
224250

src/test/groovy/io/openapiprocessor/core/model/Builder.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class ParametersBuilder {
204204
parameters.add (parameter)
205205
}
206206

207-
void add (@DelegatesTo(strategy = Closure.DELEGATE_ONLY, value = QueryParameterBuilder) Closure init) {
207+
void add (@DelegatesTo(strategy = Closure.DELEGATE_ONLY, value = AddParameterBuilder) Closure init) {
208208
def builder = new AddParameterBuilder()
209209
def code = init.rehydrate (builder, this, this)
210210
code.resolveStrategy = Closure.DELEGATE_ONLY

0 commit comments

Comments
 (0)