Skip to content

Commit a09ade7

Browse files
committed
should not walk primitive types
1 parent 4c8dd79 commit a09ade7

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.openapiprocessor.jsonschema.schema.Keyword;
99
import io.openapiprocessor.jsonschema.schema.Keywords;
1010
import io.openapiprocessor.jsonschema.schema.*;
11+
import io.openapiprocessor.jsonschema.support.Types;
1112
import org.checkerframework.checker.nullness.qual.Nullable;
1213

1314
import java.net.URI;
@@ -360,6 +361,10 @@ private void walkSchemaArray (Scope currentScope, Object value, JsonPointer loca
360361
int index = 0;
361362
for (Object item : items) {
362363
JsonPointer itemLocation = location.append (index);
364+
if (!Types.isObject (item)) {
365+
continue;
366+
}
367+
363368
walkSchema (currentScope, item, itemLocation);
364369
index++;
365370
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
package io.openapiparser
77

8+
import io.kotest.assertions.throwables.shouldNotThrowAny
89
import io.kotest.core.spec.style.FreeSpec
910
import io.kotest.datatest.withData
1011
import io.kotest.matchers.booleans.shouldBeFalse
1112
import io.kotest.matchers.booleans.shouldBeTrue
1213
import io.kotest.matchers.nulls.shouldNotBeNull
1314
import io.kotest.matchers.shouldBe
15+
import io.openapiprocessor.jackson.JacksonConverter
1416
import io.openapiprocessor.jsonschema.support.Types.asObject
1517
import io.openapiprocessor.jsonschema.reader.UriReader
1618
import io.openapiprocessor.jsonschema.schema.JsonPointer.from
@@ -58,6 +60,38 @@ class OpenApiBundlerSpec : FreeSpec({
5860

5961
data class Data(val api: String, val bundle: (result: ResolverResult) -> Bucket)
6062

63+
"do not walk array on simple type" - {
64+
val context = Context(Scope.empty(), ReferenceRegistry())
65+
66+
val converter = JacksonConverter()
67+
val document = converter.convert("""
68+
openapi: 3.0.2
69+
info:
70+
title: do not walk tags
71+
version: 1.0.0
72+
73+
paths:
74+
/foo:
75+
get:
76+
tags:
77+
- a tag
78+
responses:
79+
'204':
80+
description: none
81+
""".trimIndent()
82+
)
83+
84+
val documents = DocumentStore()
85+
val scope = Scope.empty()
86+
documents.addId(scope.documentUri, document)
87+
88+
val bucket = Bucket.createBucket(scope, document)
89+
90+
shouldNotThrowAny {
91+
OpenApiBundler(context, documents, bucket!!).bundle()
92+
}
93+
}
94+
6195
withData(
6296
mapOf(
6397
$$"bundle handles $ref loop, 30" to Data("/bundle-ref-loop/openapi30.yaml", ::bundle30),

0 commit comments

Comments
 (0)