@@ -23,6 +23,7 @@ import com.github.hauner.openapi.spring.model.Interface
2323import com.github.hauner.openapi.spring.model.datatypes.MappedDataType
2424import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
2525import com.github.hauner.openapi.spring.model.datatypes.StringDataType
26+ import com.github.hauner.openapi.spring.model.datatypes.StringEnumDataType
2627import com.github.hauner.openapi.spring.support.Sl4jMockRule
2728import org.junit.Rule
2829import org.junit.rules.TemporaryFolder
@@ -46,7 +47,7 @@ class ApiWriterSpec extends Specification {
4647 )
4748
4849 when :
49- new ApiWriter (opts, Stub (InterfaceWriter )). write (new Api ())
50+ new ApiWriter (opts, Stub (InterfaceWriter ), null , null ). write (new Api ())
5051
5152 then :
5253 def api = new File ([opts. targetDir, ' com' , ' github' , ' hauner' , ' openapi' , ' api' ]. join(File . separator))
@@ -66,7 +67,7 @@ class ApiWriterSpec extends Specification {
6667 when :
6768 target. newFolder (' java' , ' src' , ' com' , ' github' , ' hauner' , ' openapi' , ' api' )
6869 target. newFolder (' java' , ' src' , ' com' , ' github' , ' hauner' , ' openapi' , ' model' )
69- new ApiWriter (opts, Stub (InterfaceWriter )). write (new Api ())
70+ new ApiWriter (opts, Stub (InterfaceWriter ), null , null ). write (new Api ())
7071
7172 then :
7273 0 * log. error (* _)
@@ -94,7 +95,7 @@ class ApiWriterSpec extends Specification {
9495 ])
9596
9697 when :
97- new ApiWriter (opts, interfaceWriter). write (api)
98+ new ApiWriter (opts, interfaceWriter, null , null ). write (api)
9899
99100 then :
100101 def fooSource = new File (getApiPath (opts. targetDir, ' FooApi.java' ))
@@ -129,7 +130,7 @@ Bar interface!
129130 def api = new Api (dt)
130131
131132 when :
132- new ApiWriter (opts, Stub (InterfaceWriter ), dataTypeWriter). write (api)
133+ new ApiWriter (opts, Stub (InterfaceWriter ), dataTypeWriter, Stub ( StringEnumWriter ) ). write (api)
133134
134135 then :
135136 def fooSource = new File (getModelPath (opts. targetDir, ' Foo.java' ))
@@ -142,6 +143,41 @@ Bar class!
142143"""
143144 }
144145
146+ void " generates model enum sources in model target folder" () {
147+ def enumWriter = Stub (StringEnumWriter ) {
148+ write (_ as Writer , _ as StringEnumDataType ) >> {
149+ Writer writer = it. get(0 )
150+ writer. write (' Foo enum!\n ' )
151+ } >> {
152+ Writer writer = it. get(0 )
153+ writer. write (' Bar enum!\n ' )
154+ }
155+ }
156+
157+ def opts = new ApiOptions (
158+ packageName : ' com.github.hauner.openapi' ,
159+ targetDir : [target. root. toString (), ' java' , ' src' ]. join (File . separator)
160+ )
161+
162+ def dt = new DataTypes ()
163+ dt. add (' foo' , new StringEnumDataType (pkg : " ${ opts.packageName} .model" , type : ' foo' ))
164+ dt. add (new StringEnumDataType (pkg : " ${ opts.packageName} .model" , type : ' Bar' ))
165+ def api = new Api (dt)
166+
167+ when :
168+ new ApiWriter (opts, Stub (InterfaceWriter ), Stub (DataTypeWriter ), enumWriter). write (api)
169+
170+ then :
171+ def fooSource = new File (getModelPath (opts. targetDir, ' Foo.java' ))
172+ fooSource. text == """ \
173+ Foo enum!
174+ """
175+ def barSource = new File (getModelPath (opts. targetDir, ' Bar.java' ))
176+ barSource. text == """ \
177+ Bar enum!
178+ """
179+ }
180+
145181 void " generates model for object data types only" () {
146182 def dataTypeWriter = Mock (DataTypeWriter ) {
147183 write (_ as Writer , _ as ObjectDataType ) >> {
@@ -166,7 +202,7 @@ Bar class!
166202 def api = new Api (dt)
167203
168204 when :
169- new ApiWriter (opts, Stub (InterfaceWriter ), dataTypeWriter). write (api)
205+ new ApiWriter (opts, Stub (InterfaceWriter ), dataTypeWriter, Stub ( StringEnumWriter ) ). write (api)
170206
171207 then :
172208 0 * dataTypeWriter. write (_, dt. find (' simple' ))
0 commit comments