File tree Expand file tree Collapse file tree
main/java/io/openapiparser/model
resources/v30/ref-response Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ public String getRef () {
3838 return getStringOrThrow (REF );
3939 }
4040
41+ public Response getRefObject () {
42+ return getRefObjectOrThrow (Response .class );
43+ }
44+
4145 @ Required
4246 public String getDescription () {
4347 return getStringOrThrow (DESCRIPTION );
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ public String getRef () {
3838 return getStringOrThrow (REF );
3939 }
4040
41+ public Response getRefObject () {
42+ return getRefObjectOrThrow (Response .class );
43+ }
44+
4145 @ Override
4246 public @ Nullable String getSummary () {
4347 return getStringOrNull (SUMMARY );
Original file line number Diff line number Diff line change 66package io.openapiparser
77
88import io.kotest.core.spec.style.StringSpec
9+ import io.kotest.matchers.booleans.shouldBeTrue
910import io.kotest.matchers.shouldBe
1011import io.openapiparser.support.ApiBuilder
1112import io.openapiparser.support.getParameters
1213import io.openapiparser.support.getResponseSchema
14+ import io.openapiparser.support.getResponses
1315import io.openapiparser.model.v30.Schema as Schema30
1416
1517class RefSpec : StringSpec ({
@@ -124,6 +126,21 @@ class RefSpec: StringSpec({
124126 parameterRef.name shouldBe " bar"
125127 }
126128
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+
127144 " parses ref relative to current file" {
128145 val api = ApiBuilder ()
129146 .buildOpenApi30("/v30/ref-is-relative-to-current-file/openapi.yaml")
Original file line number Diff line number Diff line change 66package io.openapiparser.support
77
88import io.kotest.matchers.nulls.shouldNotBeNull
9+ import io.openapiparser.model.v30.Responses as Responses30
910import io.openapiparser.model.v30.OpenApi as OpenApi30
1011import io.openapiparser.model.v30.Parameter as Parameter30
1112import io.openapiparser.model.v30.Schema as Schema30
@@ -39,3 +40,13 @@ fun OpenApi30.getParameters(path: String): Collection<Parameter30> {
3940 return operation.parameters
4041}
4142
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