@@ -44,6 +44,14 @@ class OpenApiBundlerSpec : FreeSpec({
4444 return Bucket .createBucket(result.scope, bundle)!!
4545 }
4646
47+ fun bundle32(result: ResolverResult ): Bucket {
48+ val context = Context (result.scope, result.registry)
49+ val bucket = Bucket (result.scope, asObject(result.document))
50+ val api = OpenApiResult32 (context, bucket, result.documents)
51+ val bundle = api.bundle()
52+ return Bucket .createBucket(result.scope, bundle)!!
53+ }
54+
4755 fun getObject(bucket: Bucket , jsonPointer: String ): Map <String , Any ?> {
4856 return asObject(bucket.getRawValue(from(jsonPointer))!!.value)
4957 }
@@ -53,7 +61,8 @@ class OpenApiBundlerSpec : FreeSpec({
5361 withData(
5462 mapOf(
5563 $$"bundle handles $ref loop, 30" to Data ("/bundle-ref-loop/openapi30.yaml", ::bundle30),
56- $$"bundle handles $ref loop, 31" to Data ("/bundle-ref-loop/openapi31.yaml", ::bundle31)
64+ $$"bundle handles $ref loop, 31" to Data ("/bundle-ref-loop/openapi31.yaml", ::bundle31),
65+ $$"bundle handles $ref loop, 32" to Data ("/bundle-ref-loop/openapi32.yaml", ::bundle32)
5766 )
5867 ) { (api, bundle) ->
5968 val result = resolve(api)
@@ -69,7 +78,8 @@ class OpenApiBundlerSpec : FreeSpec({
6978 withData(
7079 mapOf(
7180 $$"bundle schema $ref, 30" to Data ("/bundle-ref-schema/openapi30.yaml", ::bundle30),
72- $$"bundle schema $ref, 31" to Data ("/bundle-ref-schema/openapi31.yaml", ::bundle31)
81+ $$"bundle schema $ref, 31" to Data ("/bundle-ref-schema/openapi31.yaml", ::bundle31),
82+ $$"bundle schema $ref, 32" to Data ("/bundle-ref-schema/openapi32.yaml", ::bundle32)
7383 )
7484 ) { (api, bundle) ->
7585 val result = resolve(api)
@@ -85,7 +95,8 @@ class OpenApiBundlerSpec : FreeSpec({
8595 withData(
8696 mapOf(
8797 $$"bundle response $ref, 30" to Data ("/bundle-ref-response/openapi30.yaml", ::bundle30),
88- $$"bundle response $ref, 31" to Data ("/bundle-ref-response/openapi31.yaml", ::bundle31)
98+ $$"bundle response $ref, 31" to Data ("/bundle-ref-response/openapi31.yaml", ::bundle31),
99+ $$"bundle response $ref, 32" to Data ("/bundle-ref-response/openapi32.yaml", ::bundle32)
89100 )
90101 ) { (api, bundle) ->
91102 val result = resolve(api)
@@ -102,7 +113,8 @@ class OpenApiBundlerSpec : FreeSpec({
102113 withData(
103114 mapOf(
104115 $$"bundle parameter $ref, 30" to Data ("/bundle-ref-parameter/openapi30.yaml", ::bundle30),
105- $$"bundle parameter $ref, 31" to Data ("/bundle-ref-parameter/openapi31.yaml", ::bundle31)
116+ $$"bundle parameter $ref, 31" to Data ("/bundle-ref-parameter/openapi31.yaml", ::bundle31),
117+ $$"bundle parameter $ref, 32" to Data ("/bundle-ref-parameter/openapi32.yaml", ::bundle32)
106118 )
107119 ) { (api, bundle) ->
108120 val result = resolve(api)
@@ -119,7 +131,8 @@ class OpenApiBundlerSpec : FreeSpec({
119131 withData(
120132 mapOf(
121133 $$"bundle example $ref, 30" to Data ("/bundle-ref-example/openapi30.yaml", ::bundle30),
122- $$"bundle example $ref, 31" to Data ("/bundle-ref-example/openapi31.yaml", ::bundle31)
134+ $$"bundle example $ref, 31" to Data ("/bundle-ref-example/openapi31.yaml", ::bundle31),
135+ $$"bundle example $ref, 32" to Data ("/bundle-ref-example/openapi32.yaml", ::bundle32)
123136 )
124137 ) { (api, bundle) ->
125138 val result = resolve(api)
@@ -136,7 +149,8 @@ class OpenApiBundlerSpec : FreeSpec({
136149 withData(
137150 mapOf(
138151 $$"bundle request body $ref, 30" to Data ("/bundle-ref-request-body/openapi30.yaml", ::bundle30),
139- $$"bundle request body $ref, 31" to Data ("/bundle-ref-request-body/openapi31.yaml", ::bundle31)
152+ $$"bundle request body $ref, 31" to Data ("/bundle-ref-request-body/openapi31.yaml", ::bundle31),
153+ $$"bundle request body $ref, 32" to Data ("/bundle-ref-request-body/openapi32.yaml", ::bundle32)
140154 )
141155 ) { (api, bundle) ->
142156 val result = resolve(api)
@@ -153,7 +167,8 @@ class OpenApiBundlerSpec : FreeSpec({
153167 withData(
154168 mapOf(
155169 $$"bundle header $ref, 30" to Data ("/bundle-ref-header/openapi30.yaml", ::bundle30),
156- $$"bundle header $ref, 31" to Data ("/bundle-ref-header/openapi31.yaml", ::bundle31)
170+ $$"bundle header $ref, 31" to Data ("/bundle-ref-header/openapi31.yaml", ::bundle31),
171+ $$"bundle header $ref, 32" to Data ("/bundle-ref-header/openapi32.yaml", ::bundle32)
157172 )
158173 ) { (api, bundle) ->
159174 val result = resolve(api)
@@ -170,7 +185,8 @@ class OpenApiBundlerSpec : FreeSpec({
170185 withData(
171186 mapOf(
172187 $$"bundle security scheme $ref, 30" to Data ("/bundle-ref-security-scheme/openapi30.yaml", ::bundle30),
173- $$"bundle security scheme $ref, 31" to Data ("/bundle-ref-security-scheme/openapi31.yaml", ::bundle31)
188+ $$"bundle security scheme $ref, 31" to Data ("/bundle-ref-security-scheme/openapi31.yaml", ::bundle31),
189+ $$"bundle security scheme $ref, 32" to Data ("/bundle-ref-security-scheme/openapi32.yaml", ::bundle32)
174190 )
175191 ) { (api, bundle) ->
176192 val result = resolve(api)
@@ -184,7 +200,8 @@ class OpenApiBundlerSpec : FreeSpec({
184200 withData(
185201 mapOf(
186202 $$"bundle link $ref, 30" to Data ("/bundle-ref-link/openapi30.yaml", ::bundle30),
187- $$"bundle link $ref, 31" to Data ("/bundle-ref-link/openapi31.yaml", ::bundle31)
203+ $$"bundle link $ref, 31" to Data ("/bundle-ref-link/openapi31.yaml", ::bundle31),
204+ $$"bundle link $ref, 32" to Data ("/bundle-ref-link/openapi32.yaml", ::bundle32)
188205 )
189206 ) { (api, bundle) ->
190207 val result = resolve(api)
@@ -201,13 +218,14 @@ class OpenApiBundlerSpec : FreeSpec({
201218 withData(
202219 mapOf(
203220 $$"bundle callback $ref, 30" to Data ("/bundle-ref-callback/openapi30.yaml", ::bundle30),
204- $$"bundle callback $ref, 31" to Data ("/bundle-ref-callback/openapi31.yaml", ::bundle31)
221+ $$"bundle callback $ref, 31" to Data ("/bundle-ref-callback/openapi31.yaml", ::bundle31),
222+ $$"bundle callback $ref, 32" to Data ("/bundle-ref-callback/openapi32.yaml", ::bundle32)
205223 )
206224 ) { (api, bundle) ->
207225 val result = resolve(api)
208226 val bundled = bundle(result)
209227
210- val ref = getObject(bundled, "/paths/~1foo/get/callbacks/\ $url")
228+ val ref = getObject(bundled, $$ "/paths/~1foo/get/callbacks/$url")
211229 ref.size shouldBe 1
212230 ref[$$" $ref " ].shouldBe("#/components/callbacks/Foo ")
213231
@@ -234,7 +252,8 @@ class OpenApiBundlerSpec : FreeSpec({
234252
235253 withData(
236254 mapOf(
237- $$"bundle path $ref, 31" to Data ("/bundle-ref-path-item/openapi31.yaml", ::bundle31)
255+ $$"bundle path $ref, 31" to Data ("/bundle-ref-path-item/openapi31.yaml", ::bundle31),
256+ $$"bundle path $ref, 32" to Data ("/bundle-ref-path-item/openapi32.yaml", ::bundle32)
238257 )
239258 ) { (api, bundle) ->
240259 val result = resolve(api)
@@ -281,7 +300,8 @@ class OpenApiBundlerSpec : FreeSpec({
281300
282301 withData(
283302 mapOf(
284- $$"bundle nested $ref, 31" to Data ("/bundle-ref-nested/openapi31.yaml", ::bundle31)
303+ $$"bundle nested $ref, 31" to Data ("/bundle-ref-nested/openapi31.yaml", ::bundle31),
304+ $$"bundle nested $ref, 32" to Data ("/bundle-ref-nested/openapi32.yaml", ::bundle32)
285305 )
286306 ) { (api, bundle) ->
287307 val result = resolve(api)
@@ -312,7 +332,8 @@ class OpenApiBundlerSpec : FreeSpec({
312332 withData(
313333 mapOf(
314334 "does not override existing component, 30" to Data ("/bundle-ref-components/openapi30.yaml", ::bundle30),
315- "does not override existing component, 31" to Data ("/bundle-ref-components/openapi31.yaml", ::bundle31)
335+ "does not override existing component, 31" to Data ("/bundle-ref-components/openapi31.yaml", ::bundle31),
336+ "does not override existing component, 32" to Data ("/bundle-ref-components/openapi32.yaml", ::bundle32)
316337 )
317338 ) { (api, bundle) ->
318339 val result = resolve(api)
@@ -325,6 +346,23 @@ class OpenApiBundlerSpec : FreeSpec({
325346 existing.shouldNotBeNull()
326347 }
327348
349+ withData(
350+ mapOf(
351+ $$"bundle media type $ref, 32" to Data ("/bundle-ref-mediatype/openapi32.yaml", ::bundle32)
352+ )
353+ ) { (api, bundle) ->
354+ val result = resolve(api)
355+ val bundled = bundle(result)
356+
357+ val requestBody = getObject(bundled, "/paths/~1foo/get/requestBody/content/application~1json")
358+ requestBody[$$" $ref " ].shouldBe("#/components/mediaTypes/Foo ")
359+ getObject(bundled, "/components/mediaTypes/Foo ").shouldNotBeNull()
360+
361+ val response = getObject(bundled, "/paths/~1foo/get/responses/200/content/application~1json")
362+ response[$$" $ref " ].shouldBe("#/components/mediaTypes/Bar ")
363+ getObject(bundled, "/components/mediaTypes/Bar ").shouldNotBeNull()
364+ }
365+
328366 // should not modify in-document refs
329367 // conflict if name of bundled component is already used
330368})
0 commit comments