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

Commit af9df18

Browse files
committed
(cherry picked from commit 7874d6b)
1 parent 215c537 commit af9df18

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

src/main/kotlin/io/openapiprocessor/core/model/EndpointResponse.kt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/*
2-
* Copyright 2019-2020 the original authors
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2019 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
154
*/
165

176
package io.openapiprocessor.core.model
@@ -21,8 +10,6 @@ import io.openapiprocessor.core.model.datatypes.ResultDataType
2110

2211
/**
2312
* The responses that can be returned by an endpoint method for one (successful) response.
24-
*
25-
* @author Martin Hauner
2613
*/
2714
class EndpointResponse(
2815

@@ -76,9 +63,9 @@ class EndpointResponse(
7663
/**
7764
* returns a list with all content types.
7865
*/
79-
val contentTypes: List<String>
66+
val contentTypes: Set<String>
8067
get() {
81-
val result = mutableListOf<String>()
68+
val result = mutableSetOf<String>()
8269
if (!main.empty) {
8370
result.add(main.contentType)
8471
}

src/test/groovy/com/github/hauner/openapi/core/model/EndpointMethodResponseSpec.groovy

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,34 @@ class EndpointMethodResponseSpec extends Specification {
6565
result[1].errors.collect {it.contentType} == ['text/plain']
6666
}
6767

68+
void "provides distinct response content type groups" () {
69+
def endpoint = endpoint('/foo', HttpMethod.GET) { eb ->
70+
eb.responses { rs ->
71+
rs.status ('200') {r ->
72+
r.response ('application/json',
73+
new CollectionDataType (new StringDataType ())) {
74+
}
75+
}
76+
rs.status ('400') {r ->
77+
r.response ('application/json',
78+
new CollectionDataType (new StringDataType ())) {
79+
}
80+
}
81+
rs.status ('401') {r ->
82+
r.response ('application/json',
83+
new CollectionDataType (new StringDataType ())) {
84+
}
85+
}
86+
}
87+
}
88+
89+
when:
90+
def result = endpoint.endpointResponses
91+
92+
then:
93+
result.size () == 1
94+
result[0].contentTypes == ['application/json'] as Set
95+
96+
}
97+
6898
}

0 commit comments

Comments
 (0)