Skip to content

Commit 8918398

Browse files
committed
#126, test distinct consumes/produces
1 parent b6cc315 commit 8918398

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/test/groovy/com/github/hauner/openapi/spring/writer/java/MappingAnnotationWriterSpec.groovy

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,48 @@ class MappingAnnotationWriterSpec extends Specification {
127127
target.toString () == """@GetMapping(path = "${endpoint.path}", produces = {"${endpoint.responses.'200'.first ().contentType}", "${endpoint.responses.'default'.first ().contentType}"})"""
128128
}
129129

130+
void "writes unique 'consumes' parameter" () {
131+
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
132+
'204' : [new EmptyResponse ()]
133+
], requestBodies: [
134+
new RequestBody('body', 'foo/in', new StringDataType (),
135+
false, false),
136+
new RequestBody('body', 'foo/in', new StringDataType (),
137+
false, false),
138+
new RequestBody('body', 'foo/in', new StringDataType (),
139+
false, false)
140+
])
141+
142+
when:
143+
writer.write (target, endpoint, endpoint.endpointResponses.first ())
144+
145+
then:
146+
target.toString ().contains ('consumes = {"foo/in"}')
147+
}
148+
149+
void "writes unique 'produces' parameters" () {
150+
def endpoint = createEndpoint (path: '/foo', method: HttpMethod.GET, responses: [
151+
'200' : [
152+
new Response ('foo/out', new StringDataType (), null)
153+
],
154+
'400' : [
155+
new Response ('foo/out', new StringDataType (), null)
156+
],
157+
'401' : [
158+
new Response ('foo/out', new StringDataType (), null)
159+
],
160+
'403': [
161+
new Response ('foo/out', new StringDataType (), null)
162+
]
163+
])
164+
165+
when:
166+
writer.write (target, endpoint, endpoint.endpointResponses.first ())
167+
168+
then:
169+
target.toString ().contains ('produces = {"foo/out"}')
170+
}
171+
130172
@Deprecated
131173
private Endpoint createEndpoint (Map properties) {
132174
def ep = new Endpoint(

0 commit comments

Comments
 (0)