Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix int type, add long type, rename double type #184

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,25 @@ class Schema<T>(
fun fromString(value: String?) = type.parse(value)

companion object {
/** Registers a schema for an integer number */
/** Registers a schema for a 32 bit integer number */
fun int(name: String, description: String) =
Schema<Long>(
Schema<Int>(
name = name,
description = description,
format = "int32",
type = FunctionType.INTEGER,
nullable = false,
)

/** Registers a schema for a 64 bit integer number */
fun long(name: String, description: String) =
Schema<Long>(
name = name,
description = description,
type = FunctionType.LONG,
nullable = false,
)

/** Registers a schema for a string */
fun str(name: String, description: String) =
Schema<String>(
Expand All @@ -106,7 +116,7 @@ class Schema<T>(
)

/** Registers a schema for a floating point number */
fun num(name: String, description: String) =
fun double(name: String, description: String) =
Schema<Double>(
name = name,
description = description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import org.json.JSONObject
class FunctionType<T>(val name: String, val parse: (String?) -> T?) {
companion object {
val STRING = FunctionType<String>("STRING") { it }
val INTEGER = FunctionType<Long>("INTEGER") { it?.toLongOrNull() }
val INTEGER = FunctionType<Int>("INTEGER") { it?.toIntOrNull() }
val LONG = FunctionType<Long>("INTEGER") { it?.toLongOrNull() }
val NUMBER = FunctionType<Double>("NUMBER") { it?.toDoubleOrNull() }
val BOOLEAN = FunctionType<Boolean>("BOOLEAN") { it?.toBoolean() }
val ARRAY =
Expand Down
Loading