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

Commit 484c018

Browse files
committed
#78, write data type interface
1 parent a6815ed commit 484c018

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2022 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.writer.java
7+
8+
import io.openapiprocessor.core.converter.ApiOptions
9+
import io.openapiprocessor.core.model.datatypes.InterfaceDataType
10+
import java.io.Writer
11+
12+
class InterfaceDataTypeWriter(
13+
private val apiOptions: ApiOptions,
14+
private val headerWriter: SimpleWriter,
15+
private val javadocWriter: JavaDocWriter = JavaDocWriter()
16+
) {
17+
18+
fun write(target: Writer, dataType: InterfaceDataType) {
19+
headerWriter.write(target)
20+
target.write("package ${dataType.getPackageName()};\n\n")
21+
22+
if (apiOptions.javadoc) {
23+
target.write(javadocWriter.convert(dataType))
24+
}
25+
26+
target.write("public interface ${dataType.getTypeName()} {\n")
27+
target.write ("}\n")
28+
}
29+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2022 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.writer.java
7+
8+
import io.kotest.core.spec.IsolationMode
9+
import io.kotest.core.spec.style.StringSpec
10+
import io.kotest.matchers.string.shouldContain
11+
import io.mockk.verify
12+
import io.openapiprocessor.core.converter.ApiOptions
13+
import io.openapiprocessor.core.model.datatypes.DataTypeName
14+
import io.openapiprocessor.core.model.datatypes.InterfaceDataType
15+
import java.io.StringWriter
16+
17+
18+
class InterfaceDataTypeWriterSpec: StringSpec({
19+
isolationMode = IsolationMode.InstancePerTest
20+
21+
val headerWriter: SimpleWriter = io.mockk.mockk(relaxed = true)
22+
val options = ApiOptions()
23+
options.oneOfInterface = true
24+
25+
val writer = InterfaceDataTypeWriter(options, headerWriter)
26+
val target = StringWriter()
27+
28+
"writes 'generated' comment" {
29+
val dataType = InterfaceDataType (DataTypeName("Foo"), "pkg")
30+
31+
writer.write(target, dataType)
32+
33+
verify (exactly = 1) {
34+
headerWriter.write(any())
35+
}
36+
}
37+
38+
"writes 'package'" {
39+
val pkg = "io.openapiprocessor.test"
40+
val dataType = InterfaceDataType (DataTypeName("Foo"), pkg)
41+
42+
writer.write (target, dataType)
43+
44+
target.toString() shouldContain
45+
"""
46+
|package $pkg;
47+
|
48+
""".trimMargin()
49+
}
50+
51+
"writes 'interface'" {
52+
val pkg = "io.openapiprocessor.test"
53+
val dataType = InterfaceDataType (DataTypeName("Foo"), pkg)
54+
55+
writer.write (target, dataType)
56+
57+
target.toString() shouldContain
58+
"""
59+
|public interface ${dataType.getTypeName()} {
60+
|}
61+
|
62+
""".trimMargin()
63+
}
64+
})

0 commit comments

Comments
 (0)