Skip to content

Commit

Permalink
wip: parse basic value schema
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdward162 committed Jan 4, 2024
1 parent b0643bc commit 78eb7a3
Show file tree
Hide file tree
Showing 10 changed files with 566 additions and 211 deletions.
21 changes: 21 additions & 0 deletions core/comlink/src/json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub type JsonValue = serde_json::Value;
pub type JsonMap = serde_json::Map<String, JsonValue>;
pub type JsonSchema = JsonValue;

macro_rules! json_map {
(
{
$($toks: tt)*
}
) => {
{
let o = serde_json::json!({ $($toks)* });
match o {
serde_json::Value::Object(o) => o,
_ => unreachable!()
}
}
};
}
pub(crate) use json_map;
pub(crate) use serde_json::json;
2 changes: 1 addition & 1 deletion core/comlink/src/json_schema_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use jsonschema::JSONSchema;
use thiserror::Error;

use super::{JsonSchema, JsonValue};
use super::json::{JsonSchema, JsonValue};

#[derive(Debug)]
pub enum JsonSchemaValidatorError {
Expand Down
4 changes: 1 addition & 3 deletions core/comlink/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! This crate provides all tools to work with the Comlink tools.

pub mod comlink_parser;
pub mod json;
pub mod json_schema_validator;
pub mod typescript_parser;

pub type JsonValue = serde_json::Value;
pub type JsonSchema = JsonValue;
20 changes: 13 additions & 7 deletions core/comlink/src/typescript_parser/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@ pub struct Diagnostic {
#[repr(u16)]
pub enum DiagnosticCode {
Unknown = 1,
UsecaseNameInvalid = 201,
UsecaseOptionsInvalid = 211,
UsecaseOptionsMemberUnknown,
UsecaseOptionsMemberInvalid,
// 10x
GlobalTypeUnknown = 101,
GlobalTypeInvalid,
// 21x
UsecaseInvalid = 211,
UsecaseNameInvalid,
UsecaseMemberUnknown,
UsecaseMemberInvalid,
}
impl DiagnosticCode {
pub fn description(&self) -> &'static str {
match self {
Self::Unknown => "Unknown",
Self::GlobalTypeUnknown => "Global type is unknown",
Self::GlobalTypeInvalid => "Global type is invalid or missing",
Self::UsecaseInvalid => "Use case options are invalid or missing",
Self::UsecaseNameInvalid => "Use case name is invalid or missing",
Self::UsecaseOptionsInvalid => "Use case options are invalid or missing",
Self::UsecaseOptionsMemberUnknown => "Use case options member is unknown",
Self::UsecaseOptionsMemberInvalid => "Use case options member is invalid or missing",
Self::UsecaseMemberUnknown => "Use case member is unknown",
Self::UsecaseMemberInvalid => "Use case member is invalid or missing",
}
}
}
2 changes: 1 addition & 1 deletion core/comlink/src/typescript_parser/model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Serialize;

use crate::{JsonSchema, JsonValue};
use crate::json::{JsonSchema, JsonValue};

#[derive(Default, Serialize)]
pub struct Documentation {
Expand Down
Loading

0 comments on commit 78eb7a3

Please sign in to comment.