Added more types
This commit is contained in:
parent
a080fef47f
commit
0280f02bc0
18 changed files with 443 additions and 0 deletions
11
src/v1/schemas/created_event.rs
Normal file
11
src/v1/schemas/created_event.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct CreatedEvent {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
todo!()
|
||||
}
|
|
@ -39,6 +39,12 @@ fn oversized() {
|
|||
assert!(id.is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forbidden_char() {
|
||||
let id: Result<EventId, _> = "1954a".try_into();
|
||||
assert!(id.is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
let id: Result<EventId, _> = "12345".try_into();
|
||||
|
|
24
src/v1/schemas/event_list.rs
Normal file
24
src/v1/schemas/event_list.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use super::Event;
|
||||
|
||||
default_derive!{
|
||||
pub struct EventList {
|
||||
events: Vec<Event>
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<Event>> for EventList {
|
||||
fn from(value: Vec<Event>) -> Self {
|
||||
EventList { events: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Vec<Event>> for EventList {
|
||||
fn into(self) -> Vec<Event> {
|
||||
self.events
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
todo!()
|
||||
}
|
12
src/v1/schemas/event_rest_search_list.rs
Normal file
12
src/v1/schemas/event_rest_search_list.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct EventRestSearchList {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
todo!()
|
||||
}
|
11
src/v1/schemas/extended_event.rs
Normal file
11
src/v1/schemas/extended_event.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct ExtendedEvent {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
todo!()
|
||||
}
|
24
src/v1/schemas/extended_event_list.rs
Normal file
24
src/v1/schemas/extended_event_list.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use super::{ExtendedEvent};
|
||||
|
||||
default_derive!{
|
||||
pub struct ExtendedEventList {
|
||||
events: Vec<ExtendedEvent>
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<ExtendedEvent>> for ExtendedEventList {
|
||||
fn from(value: Vec<ExtendedEvent>) -> Self {
|
||||
ExtendedEventList { events: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Vec<ExtendedEvent>> for ExtendedEventList {
|
||||
fn into(self) -> Vec<ExtendedEvent> {
|
||||
self.events
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
todo!()
|
||||
}
|
|
@ -14,6 +14,7 @@ expose_submodules!(
|
|||
attribute_type,
|
||||
attribute_value,
|
||||
attribute,
|
||||
created_event,
|
||||
decay_score_list,
|
||||
decay_score,
|
||||
decaying_model_parameters,
|
||||
|
@ -22,15 +23,30 @@ expose_submodules!(
|
|||
event_attribute_count,
|
||||
event_id,
|
||||
event_info,
|
||||
event_list,
|
||||
event_no_id,
|
||||
event_organisation,
|
||||
event_proposal_email_lock,
|
||||
event_report,
|
||||
event_rest_search_list,
|
||||
event_tag_id,
|
||||
event_tag_list,
|
||||
event_tag,
|
||||
event,
|
||||
extended_attribute,
|
||||
extended_event_list,
|
||||
extended_event,
|
||||
full_decaying_model,
|
||||
nullable_object_relation,
|
||||
object_description,
|
||||
object_id,
|
||||
object_meta_category,
|
||||
object_name,
|
||||
object_relation,
|
||||
object_template_version,
|
||||
object,
|
||||
slim_event_list,
|
||||
slim_event,
|
||||
updated_event,
|
||||
uuid
|
||||
);
|
49
src/v1/schemas/nullable_object_relation.rs
Normal file
49
src/v1/schemas/nullable_object_relation.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct NullableObjectRelation {
|
||||
rel: Option<String>
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for NullableObjectRelation {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
if value == "null" { //TODO how is null represented in OpenAPI or actual JSON? len()==0?
|
||||
Ok(NullableObjectRelation { rel: None })
|
||||
}
|
||||
else if value.len() <= 255 {
|
||||
Ok(NullableObjectRelation { rel: Some(value.to_string()) })
|
||||
}
|
||||
else {
|
||||
Err("Failed to parse NullableObjectRelation")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for NullableObjectRelation {
|
||||
fn into(self) -> String {
|
||||
match self.rel {
|
||||
Some(r) => r,
|
||||
None => "null".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oversized() {
|
||||
let rel: Result<NullableObjectRelation, _> = format!("{:>256}", "Test").as_str().try_into();
|
||||
assert!(rel.is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
let rel: Result<NullableObjectRelation, _> = "relation".try_into();
|
||||
assert_eq!(rel, Ok(NullableObjectRelation { rel: Some("relation".to_string()) }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid2() {
|
||||
let rel: Result<NullableObjectRelation, _> = "null".try_into();
|
||||
assert_eq!(rel, Ok(NullableObjectRelation { rel: None }))
|
||||
}
|
11
src/v1/schemas/object.rs
Normal file
11
src/v1/schemas/object.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct Object {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
todo!()
|
||||
}
|
24
src/v1/schemas/object_description.rs
Normal file
24
src/v1/schemas/object_description.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct ObjectDescription {
|
||||
text: String
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for ObjectDescription {
|
||||
fn from(value: &str) -> Self {
|
||||
ObjectDescription { text: value.to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for ObjectDescription {
|
||||
fn into(self) -> String {
|
||||
self.text
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn valid() {
|
||||
assert!(true) // no constraints defined
|
||||
}
|
52
src/v1/schemas/object_id.rs
Normal file
52
src/v1/schemas/object_id.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use regex_macro::regex;
|
||||
|
||||
|
||||
default_derive!{
|
||||
pub struct ObjectId {
|
||||
id: String,
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for ObjectId {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
let re = regex!("^[[:digit:]]+$");
|
||||
if value.len() <= 10 && re.is_match(value) {
|
||||
Ok(ObjectId { id: value.to_string() })
|
||||
}
|
||||
else {
|
||||
Err("Failed to parse ObjectId")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for ObjectId {
|
||||
fn into(self) -> String {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let id: Result<ObjectId, _> = "".try_into();
|
||||
assert!(id.is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oversized() {
|
||||
let id: Result<ObjectId, _> = "12345678910".try_into();
|
||||
assert!(id.is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
let id: Result<ObjectId, _> = "12345".try_into();
|
||||
assert_eq!(id, Ok(ObjectId { id: "12345".to_string() }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid2() {
|
||||
let id: Result<ObjectId, _> = "0123456789".try_into();
|
||||
assert_eq!(id, Ok(ObjectId { id: "0123456789".to_string() }))
|
||||
}
|
24
src/v1/schemas/object_meta_category.rs
Normal file
24
src/v1/schemas/object_meta_category.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct ObjectMetaCategory {
|
||||
cat: String
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for ObjectMetaCategory {
|
||||
fn from(value: &str) -> Self {
|
||||
ObjectMetaCategory { cat: value.to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for ObjectMetaCategory {
|
||||
fn into(self) -> String {
|
||||
self.cat
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn valid() {
|
||||
assert!(true) // no constraints defined
|
||||
}
|
44
src/v1/schemas/object_name.rs
Normal file
44
src/v1/schemas/object_name.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct ObjectName {
|
||||
name: String
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for ObjectName {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
if value.len() <= 131071 {
|
||||
Ok(ObjectName { name: value.to_string() })
|
||||
}
|
||||
else {
|
||||
Err("Failed to parse ObjectName")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for ObjectName {
|
||||
fn into(self) -> String {
|
||||
self.name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn oversized() {
|
||||
let comment: Result<ObjectName, _> = format!("{:>131072}", "Test").as_str().try_into();
|
||||
assert!(comment.is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
let comment: Result<ObjectName, _> = "".try_into();
|
||||
assert_eq!(comment, Ok(ObjectName { name: "".to_string() }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid2() {
|
||||
let comment: Result<ObjectName, _> = "Name".try_into();
|
||||
assert_eq!(comment, Ok(ObjectName{name: String::from("Name")}))
|
||||
}
|
37
src/v1/schemas/object_relation.rs
Normal file
37
src/v1/schemas/object_relation.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct ObjectRelation {
|
||||
rel: String
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for ObjectRelation {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
if value.len() <= 255 {
|
||||
Ok(ObjectRelation { rel: value.to_string() })
|
||||
}
|
||||
else {
|
||||
Err("Failed to parse ObjectRelation")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for ObjectRelation {
|
||||
fn into(self) -> String {
|
||||
self.rel
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oversized() {
|
||||
let rel: Result<ObjectRelation, _> = format!("{:>256}", "Test").as_str().try_into();
|
||||
assert!(rel.is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
let rel: Result<ObjectRelation, _> = "relation".try_into();
|
||||
assert_eq!(rel, Ok(ObjectRelation { rel: "relation".to_string() }))
|
||||
}
|
52
src/v1/schemas/object_template_version.rs
Normal file
52
src/v1/schemas/object_template_version.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use regex_macro::regex;
|
||||
|
||||
|
||||
default_derive!{
|
||||
pub struct ObjectTemplateVersion {
|
||||
version: String,
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for ObjectTemplateVersion {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
let re = regex!("^[[:digit:]]+$");
|
||||
if re.is_match(value) {
|
||||
Ok(ObjectTemplateVersion { version: value.to_string() })
|
||||
}
|
||||
else {
|
||||
Err("Failed to parse ObjectTemplateVersion")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for ObjectTemplateVersion {
|
||||
fn into(self) -> String {
|
||||
self.version
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let id: Result<ObjectTemplateVersion, _> = "".try_into();
|
||||
assert!(id.is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forbidden_char() {
|
||||
let id: Result<ObjectTemplateVersion, _> = "123a".try_into();
|
||||
assert!(id.is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
let id: Result<ObjectTemplateVersion, _> = "12345".try_into();
|
||||
assert_eq!(id, Ok(ObjectTemplateVersion { version: "12345".to_string() }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid2() {
|
||||
let id: Result<ObjectTemplateVersion, _> = "0123456789".try_into();
|
||||
assert_eq!(id, Ok(ObjectTemplateVersion { version: "0123456789".to_string() }))
|
||||
}
|
11
src/v1/schemas/slim_event.rs
Normal file
11
src/v1/schemas/slim_event.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct SlimEvent {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
todo!()
|
||||
}
|
24
src/v1/schemas/slim_event_list.rs
Normal file
24
src/v1/schemas/slim_event_list.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use super::{SlimEvent};
|
||||
|
||||
default_derive!{
|
||||
pub struct SlimEventList {
|
||||
events: Vec<SlimEvent>
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<SlimEvent>> for SlimEventList {
|
||||
fn from(value: Vec<SlimEvent>) -> Self {
|
||||
SlimEventList { events: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Vec<SlimEvent>> for SlimEventList {
|
||||
fn into(self) -> Vec<SlimEvent> {
|
||||
self.events
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
todo!()
|
||||
}
|
11
src/v1/schemas/updated_event.rs
Normal file
11
src/v1/schemas/updated_event.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
default_derive!{
|
||||
pub struct UpdatedEvent {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid1() {
|
||||
todo!()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue