mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Add JsonSchema
This commit is contained in:
parent
d7a30966c1
commit
f78919cd2e
4 changed files with 63 additions and 18 deletions
42
Cargo.lock
generated
42
Cargo.lock
generated
|
@ -1094,6 +1094,12 @@ version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b"
|
checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dyn-clone"
|
||||||
|
version = "1.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.8.1"
|
version = "1.8.1"
|
||||||
|
@ -3212,6 +3218,7 @@ dependencies = [
|
||||||
"roc_module",
|
"roc_module",
|
||||||
"roc_solve_schema",
|
"roc_solve_schema",
|
||||||
"roc_types",
|
"roc_types",
|
||||||
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
@ -4188,6 +4195,30 @@ dependencies = [
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "schemars"
|
||||||
|
version = "0.8.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f"
|
||||||
|
dependencies = [
|
||||||
|
"dyn-clone",
|
||||||
|
"schemars_derive",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "schemars_derive"
|
||||||
|
version = "0.8.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"serde_derive_internals",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scoped-tls"
|
name = "scoped-tls"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
@ -4276,6 +4307,17 @@ dependencies = [
|
||||||
"syn 2.0.16",
|
"syn 2.0.16",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive_internals"
|
||||||
|
version = "0.26.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.96"
|
version = "1.0.96"
|
||||||
|
|
|
@ -141,6 +141,7 @@ reqwest = { version = "0.11.14", default-features = false, features = ["blocking
|
||||||
rlimit = "0.9.1"
|
rlimit = "0.9.1"
|
||||||
rustyline = { git = "https://github.com/roc-lang/rustyline", rev = "e74333c" }
|
rustyline = { git = "https://github.com/roc-lang/rustyline", rev = "e74333c" }
|
||||||
rustyline-derive = { git = "https://github.com/roc-lang/rustyline", rev = "e74333c" }
|
rustyline-derive = { git = "https://github.com/roc-lang/rustyline", rev = "e74333c" }
|
||||||
|
schemars = "0.8.12"
|
||||||
serde = { version = "1.0.153", features = ["derive"] } # update roc_std/Cargo.toml on change
|
serde = { version = "1.0.153", features = ["derive"] } # update roc_std/Cargo.toml on change
|
||||||
serde-xml-rs = "0.6.0"
|
serde-xml-rs = "0.6.0"
|
||||||
serde_json = "1.0.94" # update roc_std/Cargo.toml on change
|
serde_json = "1.0.94" # update roc_std/Cargo.toml on change
|
||||||
|
|
|
@ -14,3 +14,4 @@ roc_types = { path = "../types" }
|
||||||
|
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
schemars.workspace = true
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use schemars::JsonSchema;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub enum Constraint {}
|
pub enum Constraint {}
|
||||||
|
|
||||||
#[derive(Serialize, Debug, PartialEq)]
|
#[derive(Serialize, JsonSchema, Debug, PartialEq)]
|
||||||
pub struct Variable(pub u32);
|
pub struct Variable(pub u32);
|
||||||
|
|
||||||
macro_rules! impl_content {
|
macro_rules! impl_content {
|
||||||
($($name:ident { $($arg:ident: $ty:ty,)* },)*) => {
|
($($name:ident { $($arg:ident: $ty:ty,)* },)*) => {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub enum Content {
|
pub enum Content {
|
||||||
$(
|
$(
|
||||||
$name {
|
$name {
|
||||||
|
@ -101,39 +102,39 @@ impl_content! {
|
||||||
Error {},
|
Error {},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub struct ClosureType {
|
pub struct ClosureType {
|
||||||
pub function: Symbol,
|
pub function: Symbol,
|
||||||
pub environment: Vec<Variable>,
|
pub environment: Vec<Variable>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub struct UnspecializedClosureType {
|
pub struct UnspecializedClosureType {
|
||||||
pub specialization: Variable,
|
pub specialization: Variable,
|
||||||
pub ability_member: Symbol,
|
pub ability_member: Symbol,
|
||||||
pub lambda_set_region: u8,
|
pub lambda_set_region: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub enum AliasKind {
|
pub enum AliasKind {
|
||||||
Structural,
|
Structural,
|
||||||
Opaque,
|
Opaque,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub struct AliasTypeVariables {
|
pub struct AliasTypeVariables {
|
||||||
pub type_variables: Vec<Variable>,
|
pub type_variables: Vec<Variable>,
|
||||||
pub lambda_set_variables: Vec<Variable>,
|
pub lambda_set_variables: Vec<Variable>,
|
||||||
pub infer_ext_in_output_position_variables: Vec<Variable>,
|
pub infer_ext_in_output_position_variables: Vec<Variable>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub struct RecordField {
|
pub struct RecordField {
|
||||||
pub kind: RecordFieldKind,
|
pub kind: RecordFieldKind,
|
||||||
pub field_type: Variable,
|
pub field_type: Variable,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
#[serde(tag = "kind")]
|
#[serde(tag = "kind")]
|
||||||
pub enum RecordFieldKind {
|
pub enum RecordFieldKind {
|
||||||
Demanded,
|
Demanded,
|
||||||
|
@ -141,49 +142,49 @@ pub enum RecordFieldKind {
|
||||||
Optional { rigid: bool },
|
Optional { rigid: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
#[serde(tag = "kind")]
|
#[serde(tag = "kind")]
|
||||||
pub enum TagUnionExtension {
|
pub enum TagUnionExtension {
|
||||||
Openness(Variable),
|
Openness(Variable),
|
||||||
Any(Variable),
|
Any(Variable),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub struct NumericRange {
|
pub struct NumericRange {
|
||||||
pub kind: NumericRangeKind,
|
pub kind: NumericRangeKind,
|
||||||
pub signed: bool,
|
pub signed: bool,
|
||||||
pub min_width: u32,
|
pub min_width: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub enum NumericRangeKind {
|
pub enum NumericRangeKind {
|
||||||
Int,
|
Int,
|
||||||
AnyNum,
|
AnyNum,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub struct Rank(pub u32);
|
pub struct Rank(pub u32);
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub struct Descriptor {
|
pub struct Descriptor {
|
||||||
pub content: Content,
|
pub content: Content,
|
||||||
pub rank: Rank,
|
pub rank: Rank,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub struct Symbol(
|
pub struct Symbol(
|
||||||
// TODO: should this be module ID + symbol?
|
// TODO: should this be module ID + symbol?
|
||||||
pub String,
|
pub String,
|
||||||
);
|
);
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub enum UnificationMode {
|
pub enum UnificationMode {
|
||||||
Eq,
|
Eq,
|
||||||
Present,
|
Present,
|
||||||
LambdaSetSpecialization,
|
LambdaSetSpecialization,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Top(Vec<Event>),
|
Top(Vec<Event>),
|
||||||
VariableEvent(VariableEvent),
|
VariableEvent(VariableEvent),
|
||||||
|
@ -196,7 +197,7 @@ pub enum Event {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, JsonSchema)]
|
||||||
pub enum VariableEvent {
|
pub enum VariableEvent {
|
||||||
Unify {
|
Unify {
|
||||||
from: Variable,
|
from: Variable,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue