Added several new types

This commit is contained in:
Philip (a-0) 2023-07-12 00:21:51 +02:00
parent 0280f02bc0
commit 58c8f8d356
45 changed files with 1496 additions and 1 deletions

View file

@ -1,4 +1,4 @@
use super::{ExtendedEvent}; use super::ExtendedEvent;
default_derive!{ default_derive!{
pub struct ExtendedEventList { pub struct ExtendedEventList {

View file

@ -0,0 +1,14 @@
use super::{Galaxy, GalaxyCluster};
default_derive!{
pub struct ExtendedGalaxy {
galaxy: Galaxy,
galaxy_cluster: GalaxyCluster,
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,11 @@
default_derive!{
pub struct ExtendedGalaxyCluster {
//TODO
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,11 @@
default_derive!{
pub struct ExtendedObject {
//TODO
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,11 @@
default_derive!{
pub struct ExtendedTag {
//TODO
}
}
#[test]
fn valid1() {
todo!()
}

11
src/v1/schemas/galaxy.rs Normal file
View file

@ -0,0 +1,11 @@
default_derive!{
pub struct Galaxy {
//TODO
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,14 @@
use super::{GalaxyClusterId, GalaxyClusterWithoutId};
default_derive!{
pub struct GalaxyCluster {
id: GalaxyClusterId,
attrs: GalaxyClusterWithoutId,
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,18 @@
default_derive!{
pub struct GalaxyClusterAuthors {
authors: String
}
}
impl From<&str> for GalaxyClusterAuthors {
fn from(value: &str) -> Self {
GalaxyClusterAuthors { authors: value.to_string() }
}
}
impl Into<String> for GalaxyClusterAuthors {
fn into(self) -> String {
self.authors
}
}

View file

@ -0,0 +1,43 @@
default_derive!{
pub struct GalaxyClusterDescription {
name: String
}
}
impl TryFrom<&str> for GalaxyClusterDescription {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 65535 {
Ok(GalaxyClusterDescription { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyClusterDescription")
}
}
}
impl Into<String> for GalaxyClusterDescription {
fn into(self) -> String {
self.name
}
}
#[test]
fn oversized() {
let id: Result<GalaxyClusterDescription, _> = format!("{:>65536}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyClusterDescription, _> = "".try_into();
assert_eq!(id, Ok(GalaxyClusterDescription { name: "".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyClusterDescription, _> = "some super long description".try_into();
assert_eq!(id, Ok(GalaxyClusterDescription { name: "some super long description".to_string() }))
}

View file

@ -0,0 +1,58 @@
use regex_macro::regex;
default_derive!{
pub struct GalaxyClusterId {
id: String
}
}
impl TryFrom<&str> for GalaxyClusterId {
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(GalaxyClusterId { id: value.to_string() })
}
else {
Err("Failed to parse GalaxyClusterId")
}
}
}
impl Into<String> for GalaxyClusterId {
fn into(self) -> String {
self.id
}
}
#[test]
fn empty() {
let id: Result<GalaxyClusterId, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyClusterId, _> = "12345678910".try_into();
assert!(id.is_err())
}
#[test]
fn forbidden_char() {
let id: Result<GalaxyClusterId, _> = "1954a".try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyClusterId, _> = "12345".try_into();
assert_eq!(id, Ok(GalaxyClusterId { id: "12345".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyClusterId, _> = "0123456789".try_into();
assert_eq!(id, Ok(GalaxyClusterId { id: "0123456789".to_string() }))
}

View file

@ -0,0 +1,11 @@
default_derive!{
pub struct GalaxyClusterWithoutId {
//TODO
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,25 @@
use super::GalaxyElement;
default_derive!{
pub struct GalaxyClusterRelationList {
elements: Vec<GalaxyElement>
}
}
impl From<Vec<GalaxyElement>> for GalaxyClusterRelationList {
fn from(value: Vec<GalaxyElement>) -> Self {
GalaxyClusterRelationList { elements: value }
}
}
impl Into<Vec<GalaxyElement>> for GalaxyClusterRelationList {
fn into(self) -> Vec<GalaxyElement> {
self.elements
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct GalaxyClusterSource {
name: String
}
}
impl TryFrom<&str> for GalaxyClusterSource {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 255 {
Ok(GalaxyClusterSource { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyClusterSource")
}
}
}
impl Into<String> for GalaxyClusterSource {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<GalaxyClusterSource, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyClusterSource, _> = format!("{:>256}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyClusterSource, _> = "version".try_into();
assert_eq!(id, Ok(GalaxyClusterSource { name: "version".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyClusterSource, _> = "1234".try_into();
assert_eq!(id, Ok(GalaxyClusterSource { name: "1234".to_string() }))
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct GalaxyClusterType {
name: String
}
}
impl TryFrom<&str> for GalaxyClusterType {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 255 {
Ok(GalaxyClusterType { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyClusterType")
}
}
}
impl Into<String> for GalaxyClusterType {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<GalaxyClusterType, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyClusterType, _> = format!("{:>256}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyClusterType, _> = "clustertype".try_into();
assert_eq!(id, Ok(GalaxyClusterType { name: "clustertype".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyClusterType, _> = "1234".try_into();
assert_eq!(id, Ok(GalaxyClusterType { name: "1234".to_string() }))
}

View file

@ -0,0 +1,43 @@
default_derive!{
pub struct GalaxyClusterValue {
name: String
}
}
impl TryFrom<&str> for GalaxyClusterValue {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 65535 {
Ok(GalaxyClusterValue { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyClusterValue")
}
}
}
impl Into<String> for GalaxyClusterValue {
fn into(self) -> String {
self.name
}
}
#[test]
fn oversized() {
let id: Result<GalaxyClusterValue, _> = format!("{:>65536}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyClusterValue, _> = "".try_into();
assert_eq!(id, Ok(GalaxyClusterValue { name: "".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyClusterValue, _> = "some super long value".try_into();
assert_eq!(id, Ok(GalaxyClusterValue { name: "some super long value".to_string() }))
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct GalaxyClusterVersion {
name: String
}
}
impl TryFrom<&str> for GalaxyClusterVersion {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 255 {
Ok(GalaxyClusterVersion { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyClusterVersion")
}
}
}
impl Into<String> for GalaxyClusterVersion {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<GalaxyClusterVersion, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyClusterVersion, _> = format!("{:>256}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyClusterVersion, _> = "version".try_into();
assert_eq!(id, Ok(GalaxyClusterVersion { name: "version".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyClusterVersion, _> = "1234".try_into();
assert_eq!(id, Ok(GalaxyClusterVersion { name: "1234".to_string() }))
}

View file

@ -0,0 +1,43 @@
default_derive!{
pub struct GalaxyDescription {
name: String
}
}
impl TryFrom<&str> for GalaxyDescription {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 65535 {
Ok(GalaxyDescription { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyDescription")
}
}
}
impl Into<String> for GalaxyDescription {
fn into(self) -> String {
self.name
}
}
#[test]
fn oversized() {
let id: Result<GalaxyDescription, _> = format!("{:>65536}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyDescription, _> = "".try_into();
assert_eq!(id, Ok(GalaxyDescription { name: "".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyDescription, _> = "some super long description".try_into();
assert_eq!(id, Ok(GalaxyDescription { name: "some super long description".to_string() }))
}

View file

@ -0,0 +1,16 @@
use super::{GalaxyElementId, GalaxyClusterId, GalaxyElementKey, GalaxyElementValue};
default_derive!{
pub struct GalaxyElement {
id: GalaxyElementId,
galaxy_cluster_id: GalaxyClusterId,
key: GalaxyElementKey,
value: GalaxyElementValue
}
}
#[test]
fn valid1() {
todo!();
}

View file

@ -0,0 +1,58 @@
use regex_macro::regex;
default_derive!{
pub struct GalaxyElementId {
id: String
}
}
impl TryFrom<&str> for GalaxyElementId {
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(GalaxyElementId { id: value.to_string() })
}
else {
Err("Failed to parse GalaxyElementId")
}
}
}
impl Into<String> for GalaxyElementId {
fn into(self) -> String {
self.id
}
}
#[test]
fn empty() {
let id: Result<GalaxyElementId, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyElementId, _> = "12345678910".try_into();
assert!(id.is_err())
}
#[test]
fn forbidden_char() {
let id: Result<GalaxyElementId, _> = "1954a".try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyElementId, _> = "12345".try_into();
assert_eq!(id, Ok(GalaxyElementId { id: "12345".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyElementId, _> = "0123456789".try_into();
assert_eq!(id, Ok(GalaxyElementId { id: "0123456789".to_string() }))
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct GalaxyElementKey {
name: String
}
}
impl TryFrom<&str> for GalaxyElementKey {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 255 {
Ok(GalaxyElementKey { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyElementKey")
}
}
}
impl Into<String> for GalaxyElementKey {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<GalaxyElementKey, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyElementKey, _> = format!("{:>256}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyElementKey, _> = "key".try_into();
assert_eq!(id, Ok(GalaxyElementKey { name: "key".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyElementKey, _> = "best-key:ever&0123456789".try_into();
assert_eq!(id, Ok(GalaxyElementKey { name: "best-key:ever&0123456789".to_string() }))
}

View file

@ -0,0 +1,25 @@
use super::GalaxyElement;
default_derive!{
pub struct GalaxyElementList {
elements: Vec<GalaxyElement>
}
}
impl From<Vec<GalaxyElement>> for GalaxyElementList {
fn from(value: Vec<GalaxyElement>) -> Self {
GalaxyElementList { elements: value }
}
}
impl Into<Vec<GalaxyElement>> for GalaxyElementList {
fn into(self) -> Vec<GalaxyElement> {
self.elements
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,43 @@
default_derive!{
pub struct GalaxyElementValue {
name: String
}
}
impl TryFrom<&str> for GalaxyElementValue {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 65535 {
Ok(GalaxyElementValue { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyElementValue")
}
}
}
impl Into<String> for GalaxyElementValue {
fn into(self) -> String {
self.name
}
}
#[test]
fn oversized() {
let id: Result<GalaxyElementValue, _> = format!("{:>65536}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyElementValue, _> = "".try_into();
assert_eq!(id, Ok(GalaxyElementValue { name: "".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyElementValue, _> = "some super long value".try_into();
assert_eq!(id, Ok(GalaxyElementValue { name: "some super long value".to_string() }))
}

View file

@ -0,0 +1,58 @@
use regex_macro::regex;
default_derive!{
pub struct GalaxyId {
id: String
}
}
impl TryFrom<&str> for GalaxyId {
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(GalaxyId { id: value.to_string() })
}
else {
Err("Failed to parse GalaxyId")
}
}
}
impl Into<String> for GalaxyId {
fn into(self) -> String {
self.id
}
}
#[test]
fn empty() {
let id: Result<GalaxyId, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyId, _> = "12345678910".try_into();
assert!(id.is_err())
}
#[test]
fn forbidden_char() {
let id: Result<GalaxyId, _> = "1954a".try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyId, _> = "12345".try_into();
assert_eq!(id, Ok(GalaxyId { id: "12345".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyId, _> = "0123456789".try_into();
assert_eq!(id, Ok(GalaxyId { id: "0123456789".to_string() }))
}

View file

@ -0,0 +1,11 @@
default_derive!{
pub struct GalaxyMispFormat {
//TODO
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct GalaxyName {
name: String
}
}
impl TryFrom<&str> for GalaxyName {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 255 {
Ok(GalaxyName { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyName")
}
}
}
impl Into<String> for GalaxyName {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<GalaxyName, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyName, _> = format!("{:>256}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyName, _> = "name".try_into();
assert_eq!(id, Ok(GalaxyName { name: "name".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyName, _> = "best-name:ever&0123456789".try_into();
assert_eq!(id, Ok(GalaxyName { name: "best-name:ever&0123456789".to_string() }))
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct GalaxyNamespace {
name: String
}
}
impl TryFrom<&str> for GalaxyNamespace {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 255 {
Ok(GalaxyNamespace { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyNamespace")
}
}
}
impl Into<String> for GalaxyNamespace {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<GalaxyNamespace, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyNamespace, _> = format!("{:>256}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyNamespace, _> = "namespace".try_into();
assert_eq!(id, Ok(GalaxyNamespace { name: "namespace".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyNamespace, _> = "best-namespace:ever&0123456789".try_into();
assert_eq!(id, Ok(GalaxyNamespace { name: "best-namespace:ever&0123456789".to_string() }))
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct GalaxyType {
name: String
}
}
impl TryFrom<&str> for GalaxyType {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 255 {
Ok(GalaxyType { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyType")
}
}
}
impl Into<String> for GalaxyType {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<GalaxyType, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyType, _> = format!("{:>256}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyType, _> = "type".try_into();
assert_eq!(id, Ok(GalaxyType { name: "type".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyType, _> = "best-type:ever&0123456789".try_into();
assert_eq!(id, Ok(GalaxyType { name: "best-type:ever&0123456789".to_string() }))
}

View file

@ -0,0 +1,18 @@
default_derive!{
pub struct GalaxyValueSearchFilter {
authors: String
}
}
impl From<&str> for GalaxyValueSearchFilter {
fn from(value: &str) -> Self {
GalaxyValueSearchFilter { authors: value.to_string() }
}
}
impl Into<String> for GalaxyValueSearchFilter {
fn into(self) -> String {
self.authors
}
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct GalaxyVersion {
name: String
}
}
impl TryFrom<&str> for GalaxyVersion {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 255 {
Ok(GalaxyVersion { name: value.to_string() })
}
else {
Err("Failed to parse GalaxyVersion")
}
}
}
impl Into<String> for GalaxyVersion {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<GalaxyVersion, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<GalaxyVersion, _> = format!("{:>256}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<GalaxyVersion, _> = "version".try_into();
assert_eq!(id, Ok(GalaxyVersion { name: "version".to_string() }))
}
#[test]
fn valid2() {
let id: Result<GalaxyVersion, _> = "1234".try_into();
assert_eq!(id, Ok(GalaxyVersion { name: "1234".to_string() }))
}

View file

@ -0,0 +1,13 @@
default_derive!{
pub struct HideTagFlag {
flag: bool
}
}
#[test]
fn valid1() {
todo!();
}

View file

@ -0,0 +1,14 @@
use super::{GalaxyCluster, Galaxy};
default_derive!{
pub struct ImportGalaxyClusterItem {
galaxy_cluster: GalaxyCluster,
galaxy: Galaxy
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -36,17 +36,59 @@ expose_submodules!(
extended_attribute, extended_attribute,
extended_event_list, extended_event_list,
extended_event, extended_event,
extended_galaxy_cluster,
extended_galaxy,
extended_object,
extended_tag,
full_decaying_model, full_decaying_model,
galaxy_cluster_authors,
galaxy_cluster_description,
galaxy_cluster_id,
galaxy_cluster_no_id,
galaxy_cluster_relation_list,
galaxy_cluster_source,
galaxy_cluster_value,
galaxy_cluster_version,
galaxy_cluster,
galaxy_description,
galaxy_element_id,
galaxy_element_key,
galaxy_element_list,
galaxy_element_value,
galaxy_element,
galaxy_id,
galaxy_misp_format,
galaxy_name,
galaxy_namespace,
galaxy_type,
galaxy_value_search_filter,
galaxy_version,
galaxy,
hide_tag_flag,
import_galaxy_cluster_item,
nullable_object_relation, nullable_object_relation,
object_description, object_description,
object_id, object_id,
object_meta_category, object_meta_category,
object_name, object_name,
object_relation, object_relation,
object_rest_search_filter,
object_rest_search_list,
object_template_id,
object_template_version, object_template_version,
object, object,
sighting_id,
sighting,
slim_event_list, slim_event_list,
slim_event, slim_event,
tag_collection_id,
tag_colour,
tag_id,
tag_list,
tag_name,
tag_no_id,
tag_numerical_value,
tag,
updated_event, updated_event,
uuid uuid
); );

View file

@ -0,0 +1,12 @@
default_derive!{
pub struct ObjectRestSearchFilter {
//TODO
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,25 @@
use super::Object;
default_derive!{
pub struct ObjectRestSearchList {
objects: Vec<Object>
}
}
impl From<Vec<Object>> for ObjectRestSearchList {
fn from(value: Vec<Object>) -> Self {
ObjectRestSearchList { objects: value }
}
}
impl Into<Vec<Object>> for ObjectRestSearchList {
fn into(self) -> Vec<Object> {
self.objects
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,52 @@
use regex_macro::regex;
default_derive!{
pub struct ObjectTemplateId {
id: String
}
}
impl TryFrom<&str> for ObjectTemplateId {
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(ObjectTemplateId { id: value.to_string() })
}
else {
Err("Failed to parse ObjectTemplateId")
}
}
}
#[test]
fn empty() {
let id: Result<ObjectTemplateId, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<ObjectTemplateId, _> = "12345678910".try_into();
assert!(id.is_err())
}
#[test]
fn forbidden_char() {
let id: Result<ObjectTemplateId, _> = "1954a".try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<ObjectTemplateId, _> = "12345".try_into();
assert_eq!(id, Ok(ObjectTemplateId { id: "12345".to_string() }))
}
#[test]
fn valid2() {
let id: Result<ObjectTemplateId, _> = "0123456789".try_into();
assert_eq!(id, Ok(ObjectTemplateId { id: "0123456789".to_string() }))
}

View file

@ -0,0 +1,11 @@
default_derive!{
pub struct ExtendedObject {
//TODO
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,58 @@
use regex_macro::regex;
default_derive!{
pub struct SightingId {
id: String
}
}
impl TryFrom<&str> for SightingId {
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(SightingId { id: value.to_string() })
}
else {
Err("Failed to parse SightingId")
}
}
}
impl Into<String> for SightingId {
fn into(self) -> String {
self.id
}
}
#[test]
fn empty() {
let id: Result<SightingId, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<SightingId, _> = "12345678910".try_into();
assert!(id.is_err())
}
#[test]
fn forbidden_char() {
let id: Result<SightingId, _> = "1954a".try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<SightingId, _> = "12345".try_into();
assert_eq!(id, Ok(SightingId { id: "12345".to_string() }))
}
#[test]
fn valid2() {
let id: Result<SightingId, _> = "0123456789".try_into();
assert_eq!(id, Ok(SightingId { id: "0123456789".to_string() }))
}

16
src/v1/schemas/tag.rs Normal file
View file

@ -0,0 +1,16 @@
use super::{TagWithoutId, TagId};
default_derive!{
pub struct Tag {
id: TagId,
tag: TagWithoutId
}
}
#[test]
fn valid1() {
todo!();
}

View file

@ -0,0 +1,58 @@
use regex_macro::regex;
default_derive!{
pub struct TagCollectionId {
id: String
}
}
impl TryFrom<&str> for TagCollectionId {
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(TagCollectionId { id: value.to_string() })
}
else {
Err("Failed to parse TagCollectionId")
}
}
}
impl Into<String> for TagCollectionId {
fn into(self) -> String {
self.id
}
}
#[test]
fn empty() {
let id: Result<TagCollectionId, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<TagCollectionId, _> = "12345678910".try_into();
assert!(id.is_err())
}
#[test]
fn forbidden_char() {
let id: Result<TagCollectionId, _> = "1954a".try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<TagCollectionId, _> = "12345".try_into();
assert_eq!(id, Ok(TagCollectionId { id: "12345".to_string() }))
}
#[test]
fn valid2() {
let id: Result<TagCollectionId, _> = "0123456789".try_into();
assert_eq!(id, Ok(TagCollectionId { id: "0123456789".to_string() }))
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct TagColour {
name: String
}
}
impl TryFrom<&str> for TagColour {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 7 {
Ok(TagColour { name: value.to_string() })
}
else {
Err("Failed to parse TagColour")
}
}
}
impl Into<String> for TagColour {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<TagColour, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<TagColour, _> = format!("{:>8}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<TagColour, _> = "#ffffff".try_into();
assert_eq!(id, Ok(TagColour { name: "name".to_string() }))
}
#[test]
fn valid2() {
let id: Result<TagColour, _> = "colour".try_into(); // colour is not specced with any regex, only string length
assert_eq!(id, Ok(TagColour { name: "best-name:ever&0123456789".to_string() }))
}

58
src/v1/schemas/tag_id.rs Normal file
View file

@ -0,0 +1,58 @@
use regex_macro::regex;
default_derive!{
pub struct TagId {
id: String,
}
}
impl TryFrom<&str> for TagId {
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(TagId { id: value.to_string() })
}
else {
Err("Failed to parse TagId")
}
}
}
impl Into<String> for TagId {
fn into(self) -> String {
self.id
}
}
#[test]
fn empty() {
let id: Result<TagId, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<TagId, _> = "12345678910".try_into();
assert!(id.is_err())
}
#[test]
fn forbidden_char() {
let id: Result<TagId, _> = "1954a".try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<TagId, _> = "12345".try_into();
assert_eq!(id, Ok(TagId { id: "12345".to_string() }))
}
#[test]
fn valid2() {
let id: Result<TagId, _> = "0123456789".try_into();
assert_eq!(id, Ok(TagId { id: "0123456789".to_string() }))
}

View file

@ -0,0 +1,25 @@
use super::Tag;
default_derive!{
pub struct TagList {
elements: Vec<Tag>
}
}
impl From<Vec<Tag>> for TagList {
fn from(value: Vec<Tag>) -> Self {
TagList { elements: value }
}
}
impl Into<Vec<Tag>> for TagList {
fn into(self) -> Vec<Tag> {
self.elements
}
}
#[test]
fn valid1() {
todo!()
}

View file

@ -0,0 +1,49 @@
default_derive!{
pub struct TagName {
name: String
}
}
impl TryFrom<&str> for TagName {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() > 0 && value.len() <= 255 {
Ok(TagName { name: value.to_string() })
}
else {
Err("Failed to parse TagName")
}
}
}
impl Into<String> for TagName {
fn into(self) -> String {
self.name
}
}
#[test]
fn empty() {
let id: Result<TagName, _> = "".try_into();
assert!(id.is_err())
}
#[test]
fn oversized() {
let id: Result<TagName, _> = format!("{:>256}", "Test").as_str().try_into();
assert!(id.is_err())
}
#[test]
fn valid1() {
let id: Result<TagName, _> = "name".try_into();
assert_eq!(id, Ok(TagName { name: "name".to_string() }))
}
#[test]
fn valid2() {
let id: Result<TagName, _> = "best-name:ever&0123456789".try_into();
assert_eq!(id, Ok(TagName { name: "best-name:ever&0123456789".to_string() }))
}

View file

@ -0,0 +1,13 @@
default_derive!{
pub struct TagWithoutId {
//TODO
}
}
#[test]
fn valid1() {
todo!();
}

View file

@ -0,0 +1,66 @@
use regex_macro::regex;
default_derive!{
pub struct TagNumericalValue {
val: Option<String>
}
}
impl TryFrom<&str> for TagNumericalValue {
type Error = &'static str;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() == 0 || value == "null" {
return Ok(TagNumericalValue{ val: None });
}
else {
let re = regex!("^[[:digit:]]+$");
if re.is_match(value) {
Ok(TagNumericalValue { val: Some(value.to_string()) })
}
else {
Err("Failed to parse TagNumericalValue")
}
}
}
}
impl TryInto<String> for TagNumericalValue {
type Error = &'static str;
fn try_into(self) -> Result<String, Self::Error> {
if let Some(s) = self.val {
Ok(s)
}
else {
Err("Cannot cast TagNumericalValue into string, val is None")
}
}
}
#[test]
fn valid1() {
let val: Result<TagNumericalValue, _> = "12345".try_into();
assert_eq!(val, Ok(TagNumericalValue { val: Some("12345".to_string()) }))
}
#[test]
fn valid2() {
let val: Result<TagNumericalValue, _> = "0123456789".try_into();
assert_eq!(val, Ok(TagNumericalValue { val: Some("0123456789".to_string()) }))
}
#[test]
fn valid3() {
let val: Result<TagNumericalValue, _> = "".try_into();
assert_eq!(val, Ok(TagNumericalValue { val: None }))
}
#[test]
fn valid4() {
let val: Result<TagNumericalValue, _> = "null".try_into();
assert_eq!(val, Ok(TagNumericalValue { val: None }))
}