Skip to content

Commit d5cf7cc

Browse files
committed
#/component/*/key does not allow '/' or '~1'
1 parent ea76ea9 commit d5cf7cc

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

openapi-parser/src/main/java/io/openapiparser/OpenApiBundler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ private boolean isExternalDocument (URI documentUri) {
169169
if (refName.isEmpty()) {
170170
refName = documentUri.getPath();
171171
}
172+
refName = toComponentKey(refName);
173+
172174
RawValue refValue = getRefValue (documentBucket, refPointer);
173175
Bucket refBucket = getRefBucket (refPointer, refValue);
174176

@@ -339,7 +341,12 @@ private Bucket createBucket(Scope scope, @Nullable Object source, JsonPointer lo
339341
}
340342

341343
private String createRefPointer (String type, String refName) {
342-
return String.format ("#/components/%s/%s", type, JsonPointerSupport.encode(refName));
344+
return String.format ("#/components/%s/%s", type, refName);
345+
}
346+
347+
private String toComponentKey(String refName) {
348+
// /component/*/key pattern does not allow '/'
349+
return refName.replace("/", "--");
343350
}
344351

345352
private void walkSchema (Scope currentScope, Object value, JsonPointer location) {

openapi-parser/src/test/kotlin/io/openapiparser/OpenApiBundlerSpec.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ class OpenApiBundlerSpec : FreeSpec({
299299

300300
val ref = getObject(bundled, "/paths/~1foo")
301301
ref.size shouldBe 1
302-
ref[$$"$ref"].shouldBe("#/components/pathItems/~1bundle-ref-path-item~1foo.api.yaml")
302+
ref[$$"$ref"].shouldBe("#/components/pathItems/--bundle-ref-path-item--foo.api.yaml")
303303

304-
val component = getObject(bundled, "/components/pathItems/~1bundle-ref-path-item~1foo.api.yaml")
304+
val component = getObject(bundled, "/components/pathItems/--bundle-ref-path-item--foo.api.yaml")
305305
component.shouldNotBeNull()
306306
}
307307

@@ -347,12 +347,12 @@ class OpenApiBundlerSpec : FreeSpec({
347347

348348
val ref = getObject(bundled, "/paths/~1foo")
349349
ref.size shouldBe 1
350-
ref[$$"$ref"].shouldBe("#/components/pathItems/~1bundle-ref-nested~1foo.api.yaml")
350+
ref[$$"$ref"].shouldBe("#/components/pathItems/--bundle-ref-nested--foo.api.yaml")
351351

352-
val component = getObject(bundled, "/components/pathItems/~1bundle-ref-nested~1foo.api.yaml")
352+
val component = getObject(bundled, "/components/pathItems/--bundle-ref-nested--foo.api.yaml")
353353
component.shouldNotBeNull()
354354

355-
val barRef = getObject(bundled, "/components/pathItems/~1bundle-ref-nested~1foo.api.yaml/get/responses/200/content/application~1json/schema")
355+
val barRef = getObject(bundled, "/components/pathItems/--bundle-ref-nested--foo.api.yaml/get/responses/200/content/application~1json/schema")
356356
barRef[$$"$ref"].shouldBe("#/components/schemas/Bar")
357357
val barComponent = bundled.getRawValue(from("/components/schemas/Bar"))
358358
barComponent.shouldNotBeNull()
@@ -397,6 +397,5 @@ class OpenApiBundlerSpec : FreeSpec({
397397
getObject(bundled, "/components/mediaTypes/Bar").shouldNotBeNull()
398398
}
399399

400-
// should not modify in-document refs
401-
// conflict if name of bundled component is already used
400+
// conflict if name of bundled component is already used
402401
})

0 commit comments

Comments
 (0)