use serde::{Deserialize, Serialize};
use super::types::{Common, NodeType, LOC};
#[derive(Serialize, Deserialize, Debug)]
pub struct Comment {
pub kind: NodeType,
pub value: String,
pub loc: LOC,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "Annotation")]
pub struct Annotation {
pub value: Common<String>,
pub loc: LOC,
pub name: Common<String>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "Annotations")]
pub struct Annotations {
pub loc: LOC,
pub members: Vec<Annotation>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "ListType")]
pub struct FieldListType {
pub loc: LOC,
pub value: String,
#[serde(rename = "valueType")]
pub value_type: Box<FieldType>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "SetType")]
pub struct FieldSetType {
pub loc: LOC,
pub value: String,
#[serde(rename = "valueType")]
pub value_type: Box<FieldType>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "MapType")]
pub struct FieldMapType {
pub loc: LOC,
pub value: String,
#[serde(rename = "valueType")]
pub value_type: Box<FieldType>,
#[serde(rename = "keyType")]
pub key_type: Box<FieldType>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "ConstList")]
pub struct ConstList {
pub loc: LOC,
pub elements: Vec<FieldInitialValue>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "PropertyAssignment")]
pub struct MapProperty {
pub loc: LOC,
pub value: FieldInitialValue,
pub name: FieldInitialValue,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "ConstMap")]
pub struct ConstMap {
pub loc: LOC,
pub properties: Vec<MapProperty>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum FieldInitialValue {
ConstMap(ConstMap),
ConstList(ConstList),
ConstValue(Common<String>),
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum FieldType {
MapType(FieldMapType),
ListType(FieldListType),
SetType(FieldSetType),
CommonType(Common<String>),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Initializer {
pub kind: NodeType,
pub value: Common<String>,
pub loc: LOC,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "EnumMember")]
pub struct EnumMember {
pub loc: LOC,
pub name: Common<String>,
pub initializer: Option<Initializer>,
pub comments: Vec<Comment>,
pub annotations: Option<Annotations>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "FieldDefinition")]
pub struct Field {
pub loc: LOC,
pub name: Common<String>,
#[serde(rename = "fieldID")]
pub field_id: Option<Common<String>>,
#[serde(rename = "fieldType")]
pub field_type: FieldType,
#[serde(rename = "requiredType")]
pub required_type: String,
#[serde(rename = "defaultValue")]
pub default_value: Option<FieldInitialValue>,
pub annotations: Option<Annotations>,
pub comments: Vec<Comment>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "FunctionDefinition")]
pub struct Function {
pub loc: LOC,
pub name: Common<String>,
#[serde(rename = "returnType")]
pub return_type: FieldType,
pub params: Vec<Field>,
pub throws: Option<Vec<Field>>,
pub annotations: Option<Annotations>,
pub comments: Vec<Comment>,
pub oneway: bool,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Namespace {
pub loc: LOC,
pub name: Common<String>,
pub scope: Common<String>,
pub comments: Vec<Comment>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Include {
pub loc: LOC,
pub name: Common<String>,
pub comments: Vec<Comment>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Const {
pub loc: LOC,
pub name: Common<String>,
pub value: FieldInitialValue,
#[serde(rename = "fieldType")]
pub field_type: FieldType,
pub comments: Vec<Comment>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Typedef {
pub loc: LOC,
pub name: Common<String>,
#[serde(rename = "fieldType")]
pub field_type: FieldType,
pub comments: Vec<Comment>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Enum {
pub loc: LOC,
pub name: Common<String>,
pub members: Vec<EnumMember>,
pub comments: Vec<Comment>,
pub annotations: Option<Annotations>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Exception {
pub loc: LOC,
pub name: Common<String>,
pub members: Vec<Field>,
pub comments: Vec<Comment>,
pub annotations: Option<Annotations>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Struct {
pub loc: LOC,
pub name: Common<String>,
pub members: Vec<Field>,
pub comments: Vec<Comment>,
pub annotations: Option<Annotations>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Union {
pub loc: LOC,
pub name: Common<String>,
pub members: Vec<Field>,
pub comments: Vec<Comment>,
pub annotations: Option<Annotations>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Service {
pub loc: LOC,
pub name: Common<String>,
pub extends: Option<Common<String>>,
pub members: Vec<Function>,
pub comments: Vec<Comment>,
pub annotations: Option<Annotations>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind", rename = "ThriftDocument")]
pub struct Document {
pub members: Vec<DocumentMembers>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "kind")]
pub enum DocumentMembers {
#[serde(rename = "NamespaceDefinition")]
Namespace(Namespace),
#[serde(rename = "IncludeDefinition")]
Include(Include),
#[serde(rename = "ConstDefinition")]
Const(Const),
#[serde(rename = "TypedefDefinition")]
Typedef(Typedef),
#[serde(rename = "EnumDefinition")]
Enum(Enum),
#[serde(rename = "StructDefinition")]
Struct(Struct),
#[serde(rename = "ServiceDefinition")]
Service(Service),
#[serde(rename = "ExceptionDefinition")]
Exception(Exception),
#[serde(rename = "UnionDefinition")]
Union(Union),
}