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

Commit 2d46293

Browse files
committed
extract/migrate to better home, #68
1 parent 19f79b4 commit 2d46293

File tree

2 files changed

+120
-75
lines changed

2 files changed

+120
-75
lines changed

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

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -301,79 +301,4 @@ class MethodWriterSpec extends Specification {
301301
"""
302302
}
303303
304-
void "writes method with success response type when it has only empty error responses" () {
305-
def endpoint = endpoint ("/foo", HttpMethod.GET) {e ->
306-
e.responses { rs ->
307-
rs.status ('200') { r ->
308-
r.response ('application/json', new StringDataType ())
309-
}
310-
rs.status ('400') { r ->
311-
r.empty ()
312-
}
313-
rs.status ('500') { r ->
314-
r.empty ()
315-
}
316-
}
317-
}
318-
319-
when:
320-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
321-
322-
then:
323-
target.toString () == """\
324-
@CoreMapping
325-
String getFoo();
326-
"""
327-
}
328-
329-
void "writes method with 'Object' response when it has multiple result content types (200, default)" () {
330-
def endpoint = endpoint ("/foo", HttpMethod.GET) {e ->
331-
e.responses { rs ->
332-
rs.status ('200') { r ->
333-
r.response ('application/json', new StringDataType ())
334-
}
335-
rs.status ('default') { r ->
336-
r.response ('text/plain', new StringDataType ())
337-
}
338-
}
339-
}
340-
341-
when:
342-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
343-
344-
then:
345-
target.toString () == """\
346-
@CoreMapping
347-
Object getFoo();
348-
"""
349-
}
350-
351-
void "writes method with '?' response when it has multiple result contents types & wrapper result type" () {
352-
def endpoint = endpoint ("/foo", HttpMethod.GET) {e ->
353-
e.responses { rs ->
354-
rs.status ('200') { r ->
355-
r.response ('application/json', new ResultDataType (
356-
'ResultWrapper',
357-
'http',
358-
new StringDataType ()))
359-
}
360-
rs.status ('default') { r ->
361-
r.response ('text/plain', new ResultDataType (
362-
'ResultWrapper',
363-
'http',
364-
new StringDataType ()))
365-
}
366-
}
367-
}
368-
369-
when:
370-
writer.write (target, endpoint, endpoint.endpointResponses.first ())
371-
372-
then:
373-
target.toString () == """\
374-
@CoreMapping
375-
ResultWrapper<?> getFoo();
376-
"""
377-
}
378-
379304
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright 2021 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.shouldBe
11+
import io.mockk.mockk
12+
import io.openapiprocessor.core.builder.api.endpoint
13+
import io.openapiprocessor.core.converter.ApiOptions
14+
import io.openapiprocessor.core.model.HttpMethod
15+
import io.openapiprocessor.core.model.datatypes.ResultDataType
16+
import io.openapiprocessor.core.model.datatypes.StringDataType
17+
import io.openapiprocessor.core.support.TestMappingAnnotationWriter
18+
import io.openapiprocessor.core.support.TestParameterAnnotationWriter
19+
import java.io.StringWriter
20+
21+
class MethodWriterResponseStyleSpec: StringSpec({
22+
isolationMode = IsolationMode.InstancePerTest
23+
24+
val apiOptions = ApiOptions()
25+
26+
val writer = MethodWriter (
27+
apiOptions,
28+
TestMappingAnnotationWriter(),
29+
TestParameterAnnotationWriter(),
30+
mockk<BeanValidationFactory>(),
31+
mockk<JavaDocWriter>())
32+
33+
val target = StringWriter()
34+
35+
"writes method with success response type when it has only empty error responses" {
36+
val endpoint = endpoint("/foo", HttpMethod.GET) {
37+
responses {
38+
status("200") {
39+
response("application/json", StringDataType())
40+
}
41+
status("400") {
42+
empty()
43+
}
44+
status("500") {
45+
empty()
46+
}
47+
}
48+
}
49+
50+
// when:
51+
writer.write (target, endpoint, endpoint.endpointResponses.first ())
52+
53+
// then:
54+
target.toString() shouldBe
55+
"""
56+
| @CoreMapping
57+
| String getFoo();
58+
|
59+
""".trimMargin()
60+
}
61+
62+
"writes method with 'Object' response when it has multiple result content types (200, default)" {
63+
val endpoint = endpoint("/foo", HttpMethod.GET) {
64+
responses {
65+
status("200") {
66+
response("application/json", StringDataType())
67+
}
68+
status("default") {
69+
response("text/plain", StringDataType())
70+
}
71+
}
72+
}
73+
74+
// when:
75+
writer.write(target, endpoint, endpoint.endpointResponses.first())
76+
77+
// then:
78+
target.toString() shouldBe
79+
"""
80+
| @CoreMapping
81+
| Object getFoo();
82+
|
83+
""".trimMargin()
84+
}
85+
86+
"writes method with '?' response when it has multiple result contents types & wrapper result type" {
87+
val endpoint = endpoint("/foo", HttpMethod.GET) {
88+
responses {
89+
status("200") {
90+
response("application/json", ResultDataType(
91+
"ResultWrapper",
92+
"http",
93+
StringDataType()
94+
)
95+
)
96+
}
97+
status("default") {
98+
response("text/plain", ResultDataType(
99+
"ResultWrapper",
100+
"http",
101+
StringDataType()
102+
)
103+
)
104+
}
105+
}
106+
}
107+
108+
// when:
109+
writer.write(target, endpoint, endpoint.endpointResponses.first())
110+
111+
// then:
112+
target.toString() shouldBe
113+
"""
114+
| @CoreMapping
115+
| ResultWrapper<?> getFoo();
116+
|
117+
""".trimMargin()
118+
}
119+
120+
})

0 commit comments

Comments
 (0)