-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from Kotlin/new-open-api
OpenAPI/Swagger JSON type schema support + many small fixes I came across
- Loading branch information
Showing
119 changed files
with
14,197 additions
and
899 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,7 @@ indent_size=4 | |
max_line_length=120 | ||
|
||
[*.json] | ||
indent_size=2 | ||
indent_size=2 | ||
|
||
[*.yaml] | ||
indent_size=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/JsonPath.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.jetbrains.kotlinx.dataframe.api | ||
|
||
import org.intellij.lang.annotations.Language | ||
import java.io.Serializable | ||
|
||
/** | ||
* Simplistic JSON path implementation. | ||
* Supports just keys (in bracket notation), double quotes, arrays and wildcards. | ||
* | ||
* Examples: | ||
* `$["store"]["book"][*]["author"]` | ||
* | ||
* `$[1]` will match `$[*]` | ||
*/ | ||
@JvmInline | ||
public value class JsonPath(@Language("jsonpath") public val path: String = "$") : Serializable { | ||
|
||
public fun append(name: String): JsonPath = JsonPath("$path[\"$name\"]") | ||
|
||
public fun appendWildcard(): JsonPath = JsonPath("$path[*]") | ||
|
||
public fun appendArrayWithIndex(index: Int): JsonPath = JsonPath("$path[$index]") | ||
|
||
public fun appendArrayWithWildcard(): JsonPath = JsonPath("$path[*]") | ||
|
||
public fun replaceLastWildcardWithIndex(index: Int): JsonPath = JsonPath( | ||
path.toCharArray().let { chars -> | ||
val lastStarIndex = chars.lastIndexOf('*') | ||
chars.flatMapIndexed { i, c -> | ||
if (i == lastStarIndex) index.toString().toCharArray().toList() | ||
else listOf(c) | ||
}.joinToString("") | ||
} | ||
) | ||
|
||
public fun prepend(name: String): JsonPath = JsonPath( | ||
"\$[\"$name\"]" + path.removePrefix("$") | ||
) | ||
|
||
public fun prependWildcard(): JsonPath = JsonPath( | ||
"\$[*]" + path.removePrefix("$") | ||
) | ||
|
||
public fun prependArrayWithIndex(index: Int): JsonPath = JsonPath( | ||
"\$[$index]" + path.removePrefix("$") | ||
) | ||
|
||
public fun prependArrayWithWildcard(): JsonPath = JsonPath( | ||
"\$[*]" + path.removePrefix("$") | ||
) | ||
|
||
public fun erasedIndices(): JsonPath = JsonPath( | ||
path.replace("""\[[0-9]+]""".toRegex(), "[*]") | ||
) | ||
|
||
private fun splitPath() = path.split("[", "]").filter { it.isNotBlank() } | ||
|
||
public fun matches(other: JsonPath): Boolean = | ||
path == other.path || | ||
run { | ||
val path = splitPath() | ||
val otherPath = other.splitPath() | ||
|
||
if (path.size != otherPath.size) false | ||
else path.zip(otherPath).all { (p, o) -> | ||
p == o || p == "*" || o == "*" | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/KeyValueProperty.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.jetbrains.kotlinx.dataframe.api | ||
|
||
import org.jetbrains.kotlinx.dataframe.annotations.ColumnName | ||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema | ||
|
||
/** A [DataSchema] interface / class can implement this if it represents a map-like data schema (so key: value). */ | ||
@DataSchema | ||
public interface KeyValueProperty<T> { | ||
// needs to be explicitly overridden in @DataSchema interface, otherwise extension functions won't generate (TODO) | ||
public val key: String | ||
|
||
// needs to be explicitly overridden in @DataSchema interface, otherwise type will be read as `T` and extensions won't generate (TODO) | ||
@ColumnName("value") | ||
public val `value`: T | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.