diff --git a/gradle.properties b/gradle.properties index 7748c9b..8501194 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version=1.1.0 +version=1.1.1 jackson.version=2.9.8 \ No newline at end of file diff --git a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/Builder.kt b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/Builder.kt index 916c2db..d17dbef 100644 --- a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/Builder.kt +++ b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/Builder.kt @@ -14,11 +14,11 @@ */ package com.reprezen.jsonoverlay -import com.reprezen.jsonoverlay.JsonOverlay.Companion._jsonObject +import kotlinx.serialization.json.JsonObject class Builder(private val factory: OverlayFactory, private val modelMember: JsonOverlay<*>) { fun build(): JsonOverlay { val refMgr = modelMember.refMgr - return factory.create(_jsonObject(mapOf()), null, refMgr) + return factory.create(JsonObject(mapOf()), null, refMgr) } } diff --git a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/JsonOverlay.kt b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/JsonOverlay.kt index cb2d1db..a9df033 100644 --- a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/JsonOverlay.kt +++ b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/JsonOverlay.kt @@ -189,10 +189,10 @@ abstract class JsonOverlay : IJsonOverlay { } fun findByPath(path: String): JsonOverlay<*>? { - return findByPointer(JsonPointer(path)) + return _findByPointer(JsonPointer(path)) } - open fun findByPointer(path: JsonPointer): JsonOverlay<*>? { + open fun _findByPointer(path: JsonPointer): JsonOverlay<*>? { return null } @@ -241,7 +241,7 @@ abstract class JsonOverlay : IJsonOverlay { fun _toJson(options: SerializationOptions = SerializationOptions()): JsonElement { return if (_isReference()) { if (!options.isFollowRefs || refOverlay!!._getReference().isInvalid) { - _jsonObject(mapOf("\$ref" to JsonPrimitive(refOverlay!!._getReference().refString))) + JsonObject(mapOf("\$ref" to JsonPrimitive(refOverlay!!._getReference().refString))) } else { refOverlay!!.overlay!!._toJson(options) } @@ -284,17 +284,4 @@ abstract class JsonOverlay : IJsonOverlay { return (json != null || other.json != null) && json == other.json } - companion object { - - @JvmStatic - fun _jsonObject(content: Map): JsonObject { - return JsonObject(content) - } - - @JvmStatic - protected fun _jsonArray(content: List): JsonArray { - return JsonArray(content) - } - - } } \ No newline at end of file diff --git a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/KeyValueOverlay.kt b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/KeyValueOverlay.kt index d0370ab..c6c1615 100644 --- a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/KeyValueOverlay.kt +++ b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/KeyValueOverlay.kt @@ -14,6 +14,6 @@ interface KeyValueOverlay { return _getValueOverlayByPath(index.toString()) } - fun findByPointer(path: JsonPointer): JsonOverlay<*>? + fun _findByPointer(path: JsonPointer): JsonOverlay<*>? } \ No newline at end of file diff --git a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/ListOverlay.kt b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/ListOverlay.kt index dc8104f..4a3e821 100644 --- a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/ListOverlay.kt +++ b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/ListOverlay.kt @@ -53,7 +53,7 @@ class ListOverlay private constructor( override fun _toJsonInternal(options: SerializationOptions): JsonElement { if (overlays.isEmpty() && !options.isKeepThisEmpty) return JsonNull - return _jsonArray(overlays.map { it._toJson(options.plus(SerializationOptions.Option.KEEP_ONE_EMPTY)) }) + return JsonArray(overlays.map { it._toJson(options.plus(SerializationOptions.Option.KEEP_ONE_EMPTY)) }) } fun _elaborate() { @@ -95,12 +95,12 @@ class ListOverlay private constructor( return name.toIntOrNull()?.let { overlays[it] } } - override fun findByPointer(path: JsonPointer): JsonOverlay<*>? { + override fun _findByPointer(path: JsonPointer): JsonOverlay<*>? { val index = path.segments.firstOrNull()?.toIntOrNull() if (index != null) { _getValueOverlayByIndex(index)?.let { if (path.segments.size == 1) return it - return it.findByPointer(JsonPointer(path.segments.drop(1))) + return it._findByPointer(JsonPointer(path.segments.drop(1))) } } return null diff --git a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/MapOverlay.kt b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/MapOverlay.kt index 567255c..1e1df9f 100644 --- a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/MapOverlay.kt +++ b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/MapOverlay.kt @@ -46,7 +46,7 @@ class MapOverlay private constructor( return overlays[name] } - override fun findByPointer(path: JsonPointer): JsonOverlay<*>? { + override fun _findByPointer(path: JsonPointer): JsonOverlay<*>? { // val debug = path == JsonPointer("/2.0/users/{username}") // if (debug) println("FINDING $path IN MapOverlay") overlays[path.toString()]?.let { return it } @@ -55,7 +55,7 @@ class MapOverlay private constructor( (overlays[key])?.let { ov -> // if(debug) println("FOUND $key , FINDING ${JsonPointer(path.segments.drop(1))} IN ${ov::class.qualifiedName}") if (path.segments.size == 1) return ov - return ov.findByPointer(JsonPointer(path.segments.drop(1))) + return ov._findByPointer(JsonPointer(path.segments.drop(1))) } // if (debug) println("FINDING F-SLASH") // if (key.getOrNull(0) == '/') { @@ -81,7 +81,7 @@ class MapOverlay private constructor( override fun _toJsonInternal(options: SerializationOptions): JsonElement { if (overlays.isEmpty() && !options.isKeepThisEmpty) return JsonNull - return _jsonObject(overlays.mapValues { it.value._toJson(options.minus(SerializationOptions.Option.KEEP_ONE_EMPTY)) }) + return JsonObject(overlays.mapValues { it.value._toJson(options.minus(SerializationOptions.Option.KEEP_ONE_EMPTY)) }) } fun _elaborate() { diff --git a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/ObjectOverlay.kt b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/ObjectOverlay.kt index 047789c..1a3095b 100644 --- a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/ObjectOverlay.kt +++ b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/ObjectOverlay.kt @@ -97,10 +97,10 @@ class ObjectOverlay : ScalarOverlay, KeyValueOverlay { return null } - override fun findByPointer(path: JsonPointer): JsonOverlay<*>? { + override fun _findByPointer(path: JsonPointer): JsonOverlay<*>? { path.segments.firstOrNull()?.let { valueOfKey(it) }?.let { ov -> if (path.segments.size == 1) return ov - return ov.findByPointer(JsonPointer(path.segments.drop(1))) + return ov._findByPointer(JsonPointer(path.segments.drop(1))) } return null } diff --git a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/PropertiesOverlay.kt b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/PropertiesOverlay.kt index f20e6d9..5be0ddd 100644 --- a/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/PropertiesOverlay.kt +++ b/json-overlay/src/main/kotlin/com/reprezen/jsonoverlay/PropertiesOverlay.kt @@ -146,7 +146,7 @@ abstract class PropertiesOverlay : JsonOverlay, KeyValueOverlay { return elem?.let { createOverlay(it, factoryMap, factory) } } - override fun findByPointer(path: JsonPointer): JsonOverlay<*>? { + override fun _findByPointer(path: JsonPointer): JsonOverlay<*>? { // val debug = path == JsonPointer("/2.0/users/{username}") // if (debug) println("NAVIGATING $path") for (entry in factoryMap) { @@ -160,7 +160,7 @@ abstract class PropertiesOverlay : JsonOverlay, KeyValueOverlay { return it } else if (it is KeyValueOverlay) { // if (debug) println("FINDING $remaining IN ${it::class.qualifiedName}") - it.findByPointer(remaining)?.let { next -> return next } + it._findByPointer(remaining)?.let { next -> return next } // if (debug) println("FINDING /") // if (remaining.segments.firstOrNull()?.startsWith("/") == true) { // println("FINDING WITHOUT F-SLASH $remaining") diff --git a/parser/src/main/kotlin/com/reprezen/kaizen/oasparser/ovl3/OpenApi3Impl.kt b/parser/src/main/kotlin/com/reprezen/kaizen/oasparser/ovl3/OpenApi3Impl.kt index bed85f9..b56dc63 100644 --- a/parser/src/main/kotlin/com/reprezen/kaizen/oasparser/ovl3/OpenApi3Impl.kt +++ b/parser/src/main/kotlin/com/reprezen/kaizen/oasparser/ovl3/OpenApi3Impl.kt @@ -45,7 +45,7 @@ class OpenApi3Impl : PropertiesOverlay ,OpenApi3 { json = JsonObject(mapOf()) } if (json is JsonObject && !json.containsKey("paths")) { - json = JsonObject(json.toMutableMap().apply { put("paths", _jsonObject(mapOf())) }) + json = JsonObject(json.toMutableMap().apply { put("paths", JsonObject(mapOf())) }) } return json } diff --git a/parser/src/main/kotlin/com/reprezen/kaizen/oasparser/ovl3/SchemaImpl.kt b/parser/src/main/kotlin/com/reprezen/kaizen/oasparser/ovl3/SchemaImpl.kt index dac9eb9..224a468 100644 --- a/parser/src/main/kotlin/com/reprezen/kaizen/oasparser/ovl3/SchemaImpl.kt +++ b/parser/src/main/kotlin/com/reprezen/kaizen/oasparser/ovl3/SchemaImpl.kt @@ -3,20 +3,29 @@ package com.reprezen.kaizen.oasparser.ovl3 import com.reprezen.kaizen.oasparser.model3.* import com.reprezen.jsonoverlay.MapOverlay import com.reprezen.jsonoverlay.StringOverlay +import com.reprezen.jsonoverlay.ListOverlay import com.reprezen.jsonoverlay.OverlayFactory import com.reprezen.jsonoverlay.Builder import com.reprezen.jsonoverlay.JsonPointer +import com.reprezen.kaizen.oasparser.ovl3.XmlImpl import com.reprezen.jsonoverlay.ReferenceManager import com.reprezen.jsonoverlay.IntegerOverlay +import com.reprezen.kaizen.oasparser.ovl3.SchemaImpl import kotlin.collections.List import com.reprezen.jsonoverlay.JsonOverlay import com.reprezen.jsonoverlay.Overlay +import com.reprezen.kaizen.oasparser.ovl3.DiscriminatorImpl import com.reprezen.jsonoverlay.parser.Generated +import java.util.Optional +import com.reprezen.jsonoverlay.IJsonOverlay import com.reprezen.jsonoverlay.PropertiesOverlay import com.reprezen.jsonoverlay.NumberOverlay +import kotlin.reflect.KClass import kotlinx.serialization.json.JsonElement import com.reprezen.jsonoverlay.ObjectOverlay +import kotlin.collections.Map import com.reprezen.jsonoverlay.BooleanOverlay +import com.reprezen.kaizen.oasparser.ovl3.ExternalDocsImpl class SchemaImpl : PropertiesOverlay ,Schema { @@ -26,16 +35,16 @@ class SchemaImpl : PropertiesOverlay ,Schema { return if(overlay.parent is MapOverlay<*>) overlay.pathInParent else null } - override fun findByPointer(path: JsonPointer): JsonOverlay<*>? { + override fun _findByPointer(path: JsonPointer): JsonOverlay<*>? { return if(path.segments.firstOrNull() == "additionalProperties"){ val tail = JsonPointer(path.segments.drop(1)) if(json != null && tail.navigate(json!!) != null){ _getOverlay("additionalProperties") as BooleanOverlay } else { - _get("additionalPropertiesSchema")?.findByPointer(tail) + _get("additionalPropertiesSchema")?._findByPointer(tail) } } else { - super.findByPointer(path) + super._findByPointer(path) } } diff --git a/src/main/resources/kotlin/class/openapi3.kate b/src/main/resources/kotlin/class/openapi3.kate index e799e7e..634e5a9 100644 --- a/src/main/resources/kotlin/class/openapi3.kate +++ b/src/main/resources/kotlin/class/openapi3.kate @@ -11,7 +11,7 @@ json = JsonObject(mapOf()) } if (json is JsonObject && !json.containsKey("paths")) { - json = JsonObject(json.toMutableMap().apply { put("paths", _jsonObject(mapOf())) }) + json = JsonObject(json.toMutableMap().apply { put("paths", JsonObject(mapOf())) }) } return json } diff --git a/src/main/resources/kotlin/class/schema.kate b/src/main/resources/kotlin/class/schema.kate index f81f66d..d8014a8 100644 --- a/src/main/resources/kotlin/class/schema.kate +++ b/src/main/resources/kotlin/class/schema.kate @@ -11,16 +11,16 @@ return if(overlay.parent is MapOverlay<*>) overlay.pathInParent else null } - override fun _findByPath(path: JsonPointer): JsonOverlay<*>? { + override fun _findByPointer(path: JsonPointer): JsonOverlay<*>? { return if(path.segments.firstOrNull() == "additionalProperties"){ val tail = JsonPointer(path.segments.drop(1)) if(json != null && tail.navigate(json!!) != null){ _getOverlay("additionalProperties") as BooleanOverlay } else { - _get("additionalPropertiesSchema")?.findByPointer(tail) + _get("additionalPropertiesSchema")?._findByPointer(tail) } } else { - super._findByPath(path) + super._findByPointer(path) } } diff --git a/validator/src/test/kotlin/com/reprezen/swaggerparser/test/BigParseTest.kt b/validator/src/test/kotlin/com/reprezen/swaggerparser/test/BigParseTest.kt index f494f7c..2731c22 100644 --- a/validator/src/test/kotlin/com/reprezen/swaggerparser/test/BigParseTest.kt +++ b/validator/src/test/kotlin/com/reprezen/swaggerparser/test/BigParseTest.kt @@ -42,7 +42,7 @@ class BigParseTest(private val modelUrl: URL) : Assert() { val model = OpenApiParser().parse(modelUrl) as OpenApi3Impl val walker = object : Walker { override fun walk(node: JsonElement, parent: JsonElement?, pointer: com.reprezen.jsonoverlay.JsonPointer) { - val overlay = model.findByPointer(pointer) + val overlay = model._findByPointer(pointer) assertNotNull("No overlay object found for path: $pointer", overlay) val value = Overlay[overlay!!] val fromJson = node.toValue()