File tree Expand file tree Collapse file tree 5 files changed +56
-0
lines changed
main/java/io/openapiparser/model
resources/v30/ref-response Expand file tree Collapse file tree 5 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ public String getRef () {
38
38
return getStringOrThrow (REF );
39
39
}
40
40
41
+ public Response getRefObject () {
42
+ return getRefObjectOrThrow (Response .class );
43
+ }
44
+
41
45
@ Required
42
46
public String getDescription () {
43
47
return getStringOrThrow (DESCRIPTION );
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ public String getRef () {
38
38
return getStringOrThrow (REF );
39
39
}
40
40
41
+ public Response getRefObject () {
42
+ return getRefObjectOrThrow (Response .class );
43
+ }
44
+
41
45
@ Override
42
46
public @ Nullable String getSummary () {
43
47
return getStringOrNull (SUMMARY );
Original file line number Diff line number Diff line change 6
6
package io.openapiparser
7
7
8
8
import io.kotest.core.spec.style.StringSpec
9
+ import io.kotest.matchers.booleans.shouldBeTrue
9
10
import io.kotest.matchers.shouldBe
10
11
import io.openapiparser.support.ApiBuilder
11
12
import io.openapiparser.support.getParameters
12
13
import io.openapiparser.support.getResponseSchema
14
+ import io.openapiparser.support.getResponses
13
15
import io.openapiparser.model.v30.Schema as Schema30
14
16
15
17
class RefSpec : StringSpec ({
@@ -124,6 +126,21 @@ class RefSpec: StringSpec({
124
126
parameterRef.name shouldBe " bar"
125
127
}
126
128
129
+ " parses ref in response" {
130
+ val api = ApiBuilder ()
131
+ .buildOpenApi30("/v30/ref-response/openapi.yaml")
132
+
133
+ val responses = api.getResponses("/foo")
134
+ val responseRef = responses.getResponse("200")!!
135
+
136
+ responseRef.isRef.shouldBeTrue()
137
+ val response = responseRef.refObject
138
+
139
+ val content = response.content
140
+ content.size shouldBe 1
141
+ content.containsKey("plain/text") shouldBe true
142
+ }
143
+
127
144
" parses ref relative to current file" {
128
145
val api = ApiBuilder ()
129
146
.buildOpenApi30("/v30/ref-is-relative-to-current-file/openapi.yaml")
Original file line number Diff line number Diff line change 6
6
package io.openapiparser.support
7
7
8
8
import io.kotest.matchers.nulls.shouldNotBeNull
9
+ import io.openapiparser.model.v30.Responses as Responses30
9
10
import io.openapiparser.model.v30.OpenApi as OpenApi30
10
11
import io.openapiparser.model.v30.Parameter as Parameter30
11
12
import io.openapiparser.model.v30.Schema as Schema30
@@ -39,3 +40,13 @@ fun OpenApi30.getParameters(path: String): Collection<Parameter30> {
39
40
return operation.parameters
40
41
}
41
42
43
+ fun OpenApi30.getResponses (path : String ): Responses30 {
44
+ val pathItem = paths.getPathItem(path)
45
+ pathItem.shouldNotBeNull()
46
+
47
+ val operation = pathItem.get
48
+ operation.shouldNotBeNull()
49
+
50
+ return operation.responses
51
+ }
52
+
Original file line number Diff line number Diff line change
1
+ openapi : 3.0.3
2
+ info :
3
+ title : ref responses
4
+ version : 1.0.0
5
+
6
+ paths :
7
+ /foo :
8
+ get :
9
+ responses :
10
+ ' 200 ' :
11
+ $ref : ' #/components/responses/Bar'
12
+
13
+ components :
14
+ responses :
15
+ Bar :
16
+ description : plain text response
17
+ content :
18
+ plain/text :
19
+ schema :
20
+ type : string
You can’t perform that action at this time.
0 commit comments